Skip to main content

Parser

Struct Parser 

Source
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

Source

pub fn new(tokens: VecDeque<TokenInfo>) -> Parser

Source

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.

Source

fn parse_extern( &mut self, last_line: u32, last_col: u32, ) -> Result<ExternalFunctionNode, CompilationError>

Parse info about an external function declaration

Source

fn parse_func_args(&mut self) -> Result<Vec<FuncArg>, CompilationError>

Parse info about the valid args in an external function declaration

Source

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 as implicitly meaning the Super privilege.

Source

fn parse_isr( &mut self, last_line: u32, last_column: u32, ) -> Result<IsrNode, CompilationError>

Parse info about a defined isr

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Parser

Source§

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

Formats the value using the given formatter. 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> 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, 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.