pub struct Parser {
tokens: VecDeque<TokenInfo>,
}Expand description
The Anillo Parser
The parser lives at a slightly higher level than the lexer. At this level,
We can begin to do some additional reasoning about the program as we build
the AST (see AST).
The parse_* methods of this struct are each intended to be called only when its caller has determined that it must succeed (either due to the grammar mandating it, or a peek that indicated an optional token was found). When these functions fail, this thus causes the whole compilation to fail with a diagnostic.
Fields§
§tokens: VecDeque<TokenInfo>Implementations§
Source§impl Parser
impl Parser
pub fn new(tokens: VecDeque<TokenInfo>) -> Parser
Sourcepub fn run(&mut self, verbose: bool) -> Result<Ast, Box<dyn Error>>
pub fn run(&mut self, verbose: bool) -> Result<Ast, Box<dyn Error>>
Generates the AST from a TokenInfo buffer input
Since we have been fed rich token info from the lexer at this point, we can model the grammar closely here (no need to worry about whitespace!). Every token type has a very small set of expected token types that may appear next, which makes a combinator style (as-in what was shown in class) of failure easy to detect.
Sourcefn parse_extern(
&mut self,
last_line: u32,
last_col: u32,
) -> Result<ExternalFunctionNode, CompilationError>
fn parse_extern( &mut self, last_line: u32, last_col: u32, ) -> Result<ExternalFunctionNode, CompilationError>
Parse info about an external function declaration
Sourcefn parse_func_args(&mut self) -> Result<Vec<FuncArg>, CompilationError>
fn parse_func_args(&mut self) -> Result<Vec<FuncArg>, CompilationError>
Parse info about the valid args in an external function declaration
Sourcefn parse_withlevel(
&mut self,
last_line: u32,
last_column: u32,
) -> Result<Ring, CompilationError>
fn parse_withlevel( &mut self, last_line: u32, last_column: u32, ) -> Result<Ring, CompilationError>
Parse a found (optional) RingLevel expression.
ExternalFunctions and ISRs that do not find ‘WithLevel’ won’t call this,
and the AST validator will interpret the None variant of an Option
Sourcefn parse_isr(
&mut self,
last_line: u32,
last_column: u32,
) -> Result<IsrNode, CompilationError>
fn parse_isr( &mut self, last_line: u32, last_column: u32, ) -> Result<IsrNode, CompilationError>
Parse info about a defined isr
Sourcefn parse_isr_body(
&mut self,
last_line: u32,
last_column: u32,
) -> Result<Option<ExternalFunctionCall>, CompilationError>
fn parse_isr_body( &mut self, last_line: u32, last_column: u32, ) -> Result<Option<ExternalFunctionCall>, CompilationError>
Parse the collection of functions called from within the ISR.
An ISR may only call functions (and those functions must be declared with the ‘extern’ keyword as well). It may call 0 or 1 at the moment, but this may be expanded in the future.
Sourcefn parse_function_call(
&mut self,
last_line: u32,
last_col: u32,
) -> Result<ExternalFunctionCall, CompilationError>
fn parse_function_call( &mut self, last_line: u32, last_col: u32, ) -> Result<ExternalFunctionCall, CompilationError>
Parse the known-to-exist function called from within the ISR.
This will be called from parse_isr_body if and only if it has peeked
ahead and determined a call exists (as calls are optional). Thus,
failures here are still universally treated as hard compilation errors.