diff options
Diffstat (limited to 'src/parser/mod.rs')
-rw-r--r-- | src/parser/mod.rs | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index c23ed3349..3814837e1 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs | |||
@@ -3,19 +3,20 @@ use {File, SyntaxKind, Token}; | |||
3 | use syntax_kinds::*; | 3 | use syntax_kinds::*; |
4 | 4 | ||
5 | #[macro_use] | 5 | #[macro_use] |
6 | mod token_set; | ||
6 | mod parser; | 7 | mod parser; |
7 | mod input; | 8 | mod input; |
8 | mod event; | 9 | mod event; |
9 | mod grammar; | 10 | mod grammar; |
10 | use self::event::Event; | ||
11 | 11 | ||
12 | /// Parse a sequence of tokens into the representative node tree | 12 | /// Parse a sequence of tokens into the representative node tree |
13 | pub fn parse(text: String, tokens: &[Token]) -> File { | 13 | pub fn parse(text: String, tokens: &[Token]) -> File { |
14 | let events = { | 14 | let events = { |
15 | let input = input::ParserInput::new(&text, tokens); | 15 | let input = input::ParserInput::new(&text, tokens); |
16 | let mut parser = parser::Parser::new(&input); | 16 | let parser_impl = parser::imp::ParserImpl::new(&input); |
17 | let mut parser = parser::Parser(parser_impl); | ||
17 | grammar::file(&mut parser); | 18 | grammar::file(&mut parser); |
18 | parser.into_events() | 19 | parser.0.into_events() |
19 | }; | 20 | }; |
20 | event::to_file(text, tokens, events) | 21 | event::to_file(text, tokens, events) |
21 | } | 22 | } |
@@ -26,33 +27,3 @@ fn is_insignificant(kind: SyntaxKind) -> bool { | |||
26 | _ => false, | 27 | _ => false, |
27 | } | 28 | } |
28 | } | 29 | } |
29 | |||
30 | impl<'p> parser::Parser<'p> { | ||
31 | fn at(&self, kind: SyntaxKind) -> bool { | ||
32 | self.current() == kind | ||
33 | } | ||
34 | |||
35 | fn err_and_bump(&mut self, message: &str) { | ||
36 | let err = self.start(); | ||
37 | self.error(message); | ||
38 | self.bump(); | ||
39 | err.complete(self, ERROR); | ||
40 | } | ||
41 | |||
42 | fn expect(&mut self, kind: SyntaxKind) -> bool { | ||
43 | if self.at(kind) { | ||
44 | self.bump(); | ||
45 | true | ||
46 | } else { | ||
47 | self.error(format!("expected {:?}", kind)); | ||
48 | false | ||
49 | } | ||
50 | } | ||
51 | |||
52 | fn eat(&mut self, kind: SyntaxKind) -> bool { | ||
53 | self.at(kind) && { | ||
54 | self.bump(); | ||
55 | true | ||
56 | } | ||
57 | } | ||
58 | } | ||