1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!

Produces an abstract syntax tree from a stream of tokens.

*/

mod parser;
mod node;
mod token_parser;

pub use self::node::body;
pub use self::node::expr;
pub use self::node::module::Module;
pub use self::token_parser::{ TokenParser };
pub use self::parser::{ Parser, Parse, ImportedFunction };
pub use self::parser::body as body_parser;
pub use self::parser::expr as expr_parser;
pub use self::parser::module as module_parser;

use environment::ParsingEnvironment;
use tokens::{ TokenRef, TokenIter };
use error::TemplateResult;

#[derive(Debug)]
pub struct Block;

#[derive(Debug)]
pub struct Macro;

#[derive(Debug)]
pub struct Trait;

#[derive(Debug)]
pub struct EmbededTemplate;

pub trait TokenParserExtension
{
    fn get_tag(&self) -> &'static str;
    fn parse<'p, 'c>(&self, parser: &mut Parser<'p, 'c>, token: TokenRef<'c>)
        -> TemplateResult<Option<body::Body<'c>>>;
}

/// Parse given token stream into a node tree.
pub fn parse<'r, 'c>(env: &'r ParsingEnvironment, tokens: &'r mut TokenIter<'r, 'c>) -> TemplateResult<Module<'c>> {
    let mut parser = Parser::new(
        env, tokens
    );
    Module::parse(&mut parser)
}