Language

Struct Language 

Source
pub struct Language {
    pub context: Option<String>,
    pub target: String,
    pub tokens: Vec<TokenDef>,
    pub token_rules: Vec<TokenRule>,
    pub semantics: Vec<String>,
    pub rules: BTreeMap<String, Rule>,
    pub includes: Vec<String>,
}
Expand description

Definition of a language

A language consists of:

  • a set of tokens, defined with the token keyword
  • a set of tokenizer rules, defined with TokenType "literal" or TokenType /regex/. The syntax of the regex depends on the target language
  • a set of semantics, defined with the semantics keyword
  • a set of derivations, defined with the rule keyword
  • a context object, defined with the context keyword
  • a list of include files in the output

Fields§

§context: Option<String>

The context type name.

If this is None, it will be set to the reasonable “None” in the target language. (For example, () in Rust

§target: String

The target rule name

§tokens: Vec<TokenDef>

The token definitions

§token_rules: Vec<TokenRule>

The token rules

§semantics: Vec<String>

The semantic definitions

§rules: BTreeMap<String, Rule>

The rule definitions

§includes: Vec<String>

The files to include (relative path from the grammar file)

Implementations§

Source§

impl Language

Source

pub fn dyn_tokenize(&self, src: &str) -> TokenizerOutput<DynTok>

Dynamically tokenize a source code string based on this language

Trait Implementations§

Source§

impl ASTParser for Language

Generate a dynamic AST from a token stream based on this language

Source§

type T = String

Token type Read more
Source§

type A = DynAstNode

AST root type Read more
Source§

fn parse_ast(&self, ts: &mut TokenStream<'_, Self::T>) -> Option<Self::A>

Parse one AST root from the TokenStream Read more
Source§

fn parse_ast_all(&self, ts: &mut TokenStream<'_, Self::T>) -> ASTResult<Self::A>

Create all ASTs from the source code, until the token stream is exhausted Read more
Source§

impl Clone for Language

Source§

fn clone(&self) -> Language

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Language

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Language

Source§

fn default() -> Language

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.