2018-02-04 11:53:47 +01:00
|
|
|
use {File, SyntaxKind, Token};
|
2017-12-31 15:54:33 +01:00
|
|
|
|
2017-12-31 21:34:29 +01:00
|
|
|
use syntax_kinds::*;
|
|
|
|
|
2018-02-04 11:53:47 +01:00
|
|
|
#[macro_use]
|
|
|
|
mod parser;
|
|
|
|
mod event;
|
|
|
|
mod grammar;
|
|
|
|
use self::event::Event;
|
2018-01-01 13:10:56 +01:00
|
|
|
|
2018-01-28 02:29:14 +01:00
|
|
|
/// Parse a sequence of tokens into the representative node tree
|
2017-12-31 21:34:29 +01:00
|
|
|
pub fn parse(text: String, tokens: &[Token]) -> File {
|
2018-02-04 11:56:51 +01:00
|
|
|
let events = {
|
|
|
|
let mut parser = parser::Parser::new(&text, tokens);
|
|
|
|
grammar::file(&mut parser);
|
|
|
|
parser.into_events()
|
|
|
|
};
|
2018-02-04 11:53:47 +01:00
|
|
|
event::to_file(text, tokens, events)
|
2018-01-01 13:10:56 +01:00
|
|
|
}
|
|
|
|
|
2018-01-01 20:13:04 +01:00
|
|
|
fn is_insignificant(kind: SyntaxKind) -> bool {
|
|
|
|
match kind {
|
|
|
|
WHITESPACE | COMMENT => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
2018-01-08 20:40:14 +01:00
|
|
|
}
|