aboutsummaryrefslogtreecommitdiff
path: root/src/parser/mod.rs
blob: e72ab05af025781ab1c192576727f7789a52f788 (plain)
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
#[macro_use]
mod token_set;
mod parser;
mod input;
mod event;
mod grammar;

use {
    lexer::Token,
    parser::event::{process}
};

pub(crate) use self::event::Sink;


/// Parse a sequence of tokens into the representative node tree
pub(crate) fn parse<S: Sink>(text: String, tokens: &[Token]) -> S::Tree {
    let events = {
        let input = input::ParserInput::new(&text, tokens);
        let parser_impl = parser::imp::ParserImpl::new(&input);
        let mut parser = parser::Parser(parser_impl);
        grammar::file(&mut parser);
        parser.0.into_events()
    };
    let mut sink = S::new(text);
    process(&mut sink, tokens, events);
    sink.finish()
}