rust/src/parser/mod.rs

30 lines
696 B
Rust
Raw Normal View History

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 token_set;
2018-02-04 11:53:47 +01:00
mod parser;
mod input;
2018-02-04 11:53:47 +01:00
mod event;
mod grammar;
2018-01-01 13:10:56 +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 input = input::ParserInput::new(&text, tokens);
let parser_impl = parser::imp::ParserImpl::new(&input);
let mut parser = parser::Parser(parser_impl);
2018-02-04 11:56:51 +01:00
grammar::file(&mut parser);
parser.0.into_events()
2018-02-04 11:56:51 +01:00
};
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
}