pub trait SyntaxModule<M: Metadata> {
// Required methods
fn new() -> Self;
fn name() -> &'static str;
fn parse(&mut self, meta: &mut M) -> SyntaxResult;
// Provided method
fn parse_debug(&mut self, meta: &mut M) -> SyntaxResult { ... }
}Expand description
Trait for parsing
Trait that should be implemented in order to parse tokens with heraklit
struct MySyntax {
name: String
// ... (you decide what you need to store)
}
impl SyntaxModule<DefaultMetadata> for MySyntax {
syntax_name!("MySyntax");
fn new() -> MySyntax {
MySyntax {
name: format!(""),
// Default initialization
}
}
// Here you can parse the actual code
fn parse(&mut self, meta: &mut DefaultMetadata) -> SyntaxResult {
token(meta, "var")?;
self.name = variable(meta, vec!['_'])?;
Ok(())
}
}Required Methods§
Sourcefn parse(&mut self, meta: &mut M) -> SyntaxResult
fn parse(&mut self, meta: &mut M) -> SyntaxResult
Parse and create AST
This method is fundamental in creating a functional AST node that can determine if tokens provided by metadata can be consumed to create this particular AST node.
Provided Methods§
Sourcefn parse_debug(&mut self, meta: &mut M) -> SyntaxResult
fn parse_debug(&mut self, meta: &mut M) -> SyntaxResult
Do not implement this function as this is a predefined function for debugging
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".