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: HashMap<String, Rule>,
pub includes: Vec<String>,
}Expand description
Definition of a language
A language consists of:
- a set of tokens, defined with the
tokenkeyword - a set of tokenizer rules, defined with
TokenType "literal"orTokenType /regex/. The syntax of the regex depends on the target language - a set of semantics, defined with the
semanticskeyword - a set of derivations, defined with the
rulekeyword - a context object, defined with the
contextkeyword - 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: StringThe target rule name
tokens: Vec<TokenDef>The token definitions
token_rules: Vec<TokenRule>The token rules
semantics: Vec<String>The semantic definitions
rules: HashMap<String, Rule>The rule definitions
includes: Vec<String>The files to include (relative path from the grammar file)
Implementations§
source§impl Language
impl Language
sourcepub fn dyn_tokenize(&self, src: &str) -> TokenizerOutput<DynTok>
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
impl ASTParser for Language
Generate a dynamic AST from a token stream based on this language
§type A = DynAstNode
type A = DynAstNode
AST root type Read more
source§fn parse_ast(&self, ts: &mut TokenStream<'_, Self::T>) -> Option<Self::A>
fn parse_ast(&self, ts: &mut TokenStream<'_, Self::T>) -> Option<Self::A>
Parse one AST root from the
TokenStream Read moresource§fn parse_ast_all(&self, ts: &mut TokenStream<'_, Self::T>) -> ASTResult<Self::A>
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
Auto Trait Implementations§
impl RefUnwindSafe for Language
impl Send for Language
impl Sync for Language
impl Unpin for Language
impl UnwindSafe for Language
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more