aboutsummaryrefslogtreecommitdiff
path: root/src/parser/mod.rs
blob: ccccd78f9ea628d42a896f47a5fb5875fa2365e8 (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
use {Token, File, FileBuilder, Sink, SyntaxKind};

use syntax_kinds::*;

mod event_parser;
use self::event_parser::Event;


pub fn parse(text: String, tokens: &[Token]) -> File {
    let events = event_parser::parse(&text, tokens);
    from_events_to_file(text, events)
}

fn from_events_to_file(text: String, events: Vec<Event>) -> File {
    let mut builder = FileBuilder::new(text);
    for event in events {
        match event {
            Event::Start { kind } => builder.start_internal(kind),
            Event::Finish => builder.finish_internal(),
            Event::Token { .. } => unimplemented!(),
        }
    }
    builder.finish()
}