[−][src]Struct passerine::compiler::parse::Parser
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 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) -> 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 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 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 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 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
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,