Struct twig::nodes::Parser [] [src]

pub struct Parser<'p, 'c> {
    pub env: &'p ParsingEnvironment,
    pub tokens: Peekable<&'p mut TokenIter<'p, 'c>>,
    pub imported_symbols: Vec<ImportedSymbols<'c>>,
}

Helpers for manipulating and inspecting token iterators when creating AST.

Has methods to inspect state, like "current" token, and advance to next.

Current token is actually implemented as "peekable" next token. However, in all parsing code this "peekable" becomes "current".

Fields

env

Project options for parsing, containing data collected from all added extensions.

tokens

Token stream.

imported_symbols

Imported symbol stack.

Methods

impl<'p, 'c> Parser<'p, 'c>

fn new<'r, 'z>(env: &'r ParsingEnvironment, tokens: &'r mut TokenIter<'r, 'z>) -> Parser<'r, 'z>

fn push_local_scope<'r>(&'r mut self)

fn pop_local_scope<'r>(&'r mut self)

fn add_imported_function<'r>(&'r mut self, alias: &'c str, name: &'c str) -> Uuid

Registers pecified alias as imported function, further parsing might depend on this (use this function).

fn get_imported_function<'r>(&'r self, name: &str) -> Option<ImportedFunction<'c>>

Finds a function that was previosly imported in this or parent scope.

fn current<'r>(&'r mut self) -> TemplateResult<TokenRef<'c>>

Get current token or fail.

Returns current token, does not modify iterator position. Expects current token to exist, and if it is not (the end of file), returns UnexpectedEndOfTemplate error.

fn maybe_current<'r>(&'r mut self) -> TemplateResult<Option<TokenRef<'c>>>

Get current token or the end of stream.

Returns current token, does not modify iterator position. If the end of stream, returns None.

fn next<'r>(&'r mut self) -> TemplateResult<TokenRef<'c>>

Advances to the next token and returns previous.

Expects the next token to exist. If it does not exist (the end of file), returns UnexpectedEndOfTemplate error.

fn skip_to_next_if<'r>(&'r mut self, expected: TokenValueRef<'c>) -> TemplateResult<bool>

Advances to the next token if expected token value is the same as current and returns current.

Expects these tokens to exist. If they do not exist (the end of file), returns UnexpectedEndOfTemplate error.

fn expect<'r>(&'r mut self, expected: TokenValueRef<'c>) -> TemplateResult<TokenRef<'c>>

Expects the current token to match value and advances to next token.

Error condition same as expect_match_or.

fn expect_name<'r>(&'r mut self) -> TemplateResult<&'c str>

Expects the current token to be name type and advances to next token.

Returns found name string.

Error condition same as expect_match_or.

fn expect_or_error<'r>(&'r mut self, expected: TokenValueRef<'c>, error_message: TemplateError) -> TemplateResult<TokenRef<'c>>

Expects the current token to match value and advances to the next token.

Error condition same as expect_match_or.

fn expect_match_or<'r, C, T>(&'r mut self, check: C) -> TemplateResult<T> where C: for<'a> FnOnce(&'a TokenRef<'c>) -> TemplateResult<T>

Expects the current token to pass check and advances to next token.

Expects these tokens (current and next) to exist. If they do not exist (the end of file), returns UnexpectedEndOfTemplate error.

fn test<'r>(&'r mut self, expected: TokenValueRef<'c>) -> TemplateResult<bool>

Test the current token to match value.

Expects these token to exist. If it does not exist (the end of file), returns UnexpectedEndOfTemplate error.

fn get_operator_options<'r>(&'r self, op_str: &'c str) -> OperatorOptions

Returns options structure for specified operator.

Operator must exist in environment, otherwise panics.