Struct passerine::compiler::parse::Parser[][src]

pub struct Parser { /* fields omitted */ }

Constructs an AST from a token stream. Note that this struct should not be controlled manually, use the parse function instead.

Implementations

impl Parser[src]

pub fn new(tokens: Vec<Spanned<Token>>) -> Parser[src]

Create a new parser.

pub fn sep(&mut self) -> bool[src]

Consumes all seperator tokens, returning whether there were any.

pub fn draw(&self) -> &Spanned<Token>[src]

Returns the next non-sep tokens, without advancing the parser.

pub fn advance(&mut self) -> &Spanned<Token>[src]

Returns the current token then advances the parser.

pub fn current(&self) -> &Spanned<Token>[src]

Returns the first token.

pub fn skip(&mut self) -> &Spanned<Token>[src]

Returns the first non-Sep token.

pub fn unexpected(&self) -> Syntax[src]

Throws an error if the next token is unexpected. I get one funny error message and this is it. The error message returned by this function will be changed frequently

pub fn consume(&mut self, token: Token) -> Result<&Spanned<Token>, Syntax>[src]

Consumes a specific token then advances the parser. Can be used to consume Sep tokens, which are normally skipped.

pub fn rule_prefix(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Looks at the current token and parses an infix expression

pub fn rule_infix(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Looks at the current token and parses the right side of any infix expressions.

pub fn prec(&mut self) -> Result<Prec, Syntax>[src]

Looks at the current operator token and determines the precedence

pub fn expression(
    &mut self,
    prec: Prec,
    skip_sep: bool
) -> Result<Spanned<AST>, Syntax>
[src]

Uses some pratt parser magic to parse an expression. It’s essentially a fold-left over tokens based on the precedence and content. Cool stuff.

pub fn symbol(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Constructs an AST for a symbol.

pub fn keyword(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parses a keyword. Note that this is wrapped in a CSTPattern node.

pub fn literal(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Constructs the AST for a literal, such as a number or string.

pub fn group(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Constructs the ast for a group, i.e. an expression between parenthesis.

pub fn body(&mut self, end: Token) -> Result<AST, Syntax>[src]

Parses the body of a block. A block is one or more expressions, separated by separators. This is more of a helper function, as it serves as both the parser entrypoint while still being recursively nestable.

pub fn block(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parse a block as an expression, Building the appropriate AST. Just a body between curlies.

pub fn syntax(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parse a macro definition. syntax, followed by a pattern, followed by a block

pub fn print(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parse a print statement. A print statement takes the form print <expression> Where expression is exactly one expression Note that this is just a temporaty workaround; Once the FFI is solidified, printing will be a function like any other.

pub fn magic(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parse an extern statement. used for compiler magic and other glue. takes the form:

magic "FFI String Name" data_to_pass_out

and evaluates to the value returned by the ffi function.

pub fn label(&mut self) -> Result<Spanned<AST>, Syntax>[src]

Parse a label. A label takes the form of <Label> <expression>

pub fn arg_pat(ast: Spanned<AST>) -> Result<Spanned<ArgPattern>, Syntax>[src]

Parses an argument pattern, Which converts an AST into an ArgPattern.

pub fn assign(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses an assignment, associates right.

pub fn lambda(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a lambda definition, associates right.

pub fn pair(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a pair operator, i.e. the comma used to build tuples: a, b, c.

pub fn compose(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a function composition, i.e. a . b

pub fn add(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses an addition, calls out to FFI.

pub fn sub(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a subraction, calls out to FFI.

pub fn mul(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a multiplication, calls out to FFI.

pub fn div(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a division, calls out to FFI.

pub fn equal(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses an equality, calls out to FFI.

pub fn remainder(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses an equality, calls out to FFI.

pub fn call(&mut self, left: Spanned<AST>) -> Result<Spanned<AST>, Syntax>[src]

Parses a function call. Function calls are a bit magical, because they’re just a series of expressions. There’s a bit of magic involved - we interpret anything that isn’t an operator as a function call operator. Then pull a fast one and not parse it like an operator at all.

Trait Implementations

impl Debug for Parser[src]

Auto Trait Implementations

impl !RefUnwindSafe for Parser

impl !Send for Parser

impl !Sync for Parser

impl Unpin for Parser

impl !UnwindSafe for Parser

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.