diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/grammar/attributes.rs (renamed from src/parser/grammar/attributes.rs) | 0 | ||||
-rw-r--r-- | src/grammar/expressions.rs (renamed from src/parser/grammar/expressions.rs) | 0 | ||||
-rw-r--r-- | src/grammar/items/consts.rs (renamed from src/parser/grammar/items/consts.rs) | 0 | ||||
-rw-r--r-- | src/grammar/items/mod.rs (renamed from src/parser/grammar/items/mod.rs) | 0 | ||||
-rw-r--r-- | src/grammar/items/structs.rs (renamed from src/parser/grammar/items/structs.rs) | 0 | ||||
-rw-r--r-- | src/grammar/items/traits.rs (renamed from src/parser/grammar/items/traits.rs) | 0 | ||||
-rw-r--r-- | src/grammar/items/use_item.rs (renamed from src/parser/grammar/items/use_item.rs) | 0 | ||||
-rw-r--r-- | src/grammar/mod.rs (renamed from src/parser/grammar/mod.rs) | 9 | ||||
-rw-r--r-- | src/grammar/params.rs (renamed from src/parser/grammar/params.rs) | 1 | ||||
-rw-r--r-- | src/grammar/paths.rs (renamed from src/parser/grammar/paths.rs) | 0 | ||||
-rw-r--r-- | src/grammar/patterns.rs (renamed from src/parser/grammar/patterns.rs) | 0 | ||||
-rw-r--r-- | src/grammar/type_args.rs (renamed from src/parser/grammar/type_args.rs) | 0 | ||||
-rw-r--r-- | src/grammar/type_params.rs (renamed from src/parser/grammar/type_params.rs) | 1 | ||||
-rw-r--r-- | src/grammar/types.rs (renamed from src/parser/grammar/types.rs) | 0 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | src/parser/mod.rs | 24 | ||||
-rw-r--r-- | src/parser/token_set.rs | 24 | ||||
-rw-r--r-- | src/parser_api.rs (renamed from src/parser/parser/mod.rs) | 29 | ||||
-rw-r--r-- | src/parser_impl/event.rs (renamed from src/parser/event.rs) | 14 | ||||
-rw-r--r-- | src/parser_impl/input.rs (renamed from src/parser/input.rs) | 0 | ||||
-rw-r--r-- | src/parser_impl/mod.rs (renamed from src/parser/parser/imp.rs) | 41 | ||||
-rw-r--r-- | src/yellow/builder.rs | 2 |
22 files changed, 76 insertions, 77 deletions
diff --git a/src/parser/grammar/attributes.rs b/src/grammar/attributes.rs index c411d4d7f..c411d4d7f 100644 --- a/src/parser/grammar/attributes.rs +++ b/src/grammar/attributes.rs | |||
diff --git a/src/parser/grammar/expressions.rs b/src/grammar/expressions.rs index 06f9105c6..06f9105c6 100644 --- a/src/parser/grammar/expressions.rs +++ b/src/grammar/expressions.rs | |||
diff --git a/src/parser/grammar/items/consts.rs b/src/grammar/items/consts.rs index ca26a7814..ca26a7814 100644 --- a/src/parser/grammar/items/consts.rs +++ b/src/grammar/items/consts.rs | |||
diff --git a/src/parser/grammar/items/mod.rs b/src/grammar/items/mod.rs index d5f75f13d..d5f75f13d 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/grammar/items/mod.rs | |||
diff --git a/src/parser/grammar/items/structs.rs b/src/grammar/items/structs.rs index 7ced542a4..7ced542a4 100644 --- a/src/parser/grammar/items/structs.rs +++ b/src/grammar/items/structs.rs | |||
diff --git a/src/parser/grammar/items/traits.rs b/src/grammar/items/traits.rs index bda13e565..bda13e565 100644 --- a/src/parser/grammar/items/traits.rs +++ b/src/grammar/items/traits.rs | |||
diff --git a/src/parser/grammar/items/use_item.rs b/src/grammar/items/use_item.rs index a3f7f0da8..a3f7f0da8 100644 --- a/src/parser/grammar/items/use_item.rs +++ b/src/grammar/items/use_item.rs | |||
diff --git a/src/parser/grammar/mod.rs b/src/grammar/mod.rs index d4f9b80cf..b558da477 100644 --- a/src/parser/grammar/mod.rs +++ b/src/grammar/mod.rs | |||
@@ -24,18 +24,15 @@ | |||
24 | mod attributes; | 24 | mod attributes; |
25 | mod expressions; | 25 | mod expressions; |
26 | mod items; | 26 | mod items; |
27 | mod params; | ||
27 | mod paths; | 28 | mod paths; |
28 | mod patterns; | 29 | mod patterns; |
29 | mod params; | ||
30 | mod type_params; | ||
31 | mod type_args; | 30 | mod type_args; |
31 | mod type_params; | ||
32 | mod types; | 32 | mod types; |
33 | 33 | ||
34 | use { | 34 | use { |
35 | parser::{ | 35 | parser_api::{CompletedMarker, Parser, TokenSet}, |
36 | parser::{CompletedMarker, Parser}, | ||
37 | token_set::TokenSet, | ||
38 | }, | ||
39 | SyntaxKind::{self, *}, | 36 | SyntaxKind::{self, *}, |
40 | }; | 37 | }; |
41 | 38 | ||
diff --git a/src/parser/grammar/params.rs b/src/grammar/params.rs index efa882394..be985c80f 100644 --- a/src/parser/grammar/params.rs +++ b/src/grammar/params.rs | |||
@@ -68,4 +68,3 @@ fn self_param(p: &mut Parser) { | |||
68 | p.expect(COMMA); | 68 | p.expect(COMMA); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | |||
diff --git a/src/parser/grammar/paths.rs b/src/grammar/paths.rs index fe69db096..fe69db096 100644 --- a/src/parser/grammar/paths.rs +++ b/src/grammar/paths.rs | |||
diff --git a/src/parser/grammar/patterns.rs b/src/grammar/patterns.rs index 7216807fd..7216807fd 100644 --- a/src/parser/grammar/patterns.rs +++ b/src/grammar/patterns.rs | |||
diff --git a/src/parser/grammar/type_args.rs b/src/grammar/type_args.rs index 5b960f10b..5b960f10b 100644 --- a/src/parser/grammar/type_args.rs +++ b/src/grammar/type_args.rs | |||
diff --git a/src/parser/grammar/type_params.rs b/src/grammar/type_params.rs index b31bf52b6..1227482ad 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/grammar/type_params.rs | |||
@@ -83,7 +83,6 @@ pub(super) fn bounds_without_colon(p: &mut Parser) { | |||
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | |||
87 | pub(super) fn where_clause(p: &mut Parser) { | 86 | pub(super) fn where_clause(p: &mut Parser) { |
88 | if p.at(WHERE_KW) { | 87 | if p.at(WHERE_KW) { |
89 | let m = p.start(); | 88 | let m = p.start(); |
diff --git a/src/parser/grammar/types.rs b/src/grammar/types.rs index 565037cb0..565037cb0 100644 --- a/src/parser/grammar/types.rs +++ b/src/grammar/types.rs | |||
diff --git a/src/lib.rs b/src/lib.rs index a72d9e3cb..8f25de9a4 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -27,7 +27,11 @@ extern crate unicode_xid; | |||
27 | pub mod algo; | 27 | pub mod algo; |
28 | pub mod ast; | 28 | pub mod ast; |
29 | mod lexer; | 29 | mod lexer; |
30 | mod parser; | 30 | #[macro_use] |
31 | mod parser_api; | ||
32 | mod grammar; | ||
33 | mod parser_impl; | ||
34 | |||
31 | mod syntax_kinds; | 35 | mod syntax_kinds; |
32 | /// Utilities for simple uses of the parser. | 36 | /// Utilities for simple uses of the parser. |
33 | pub mod utils; | 37 | pub mod utils; |
@@ -43,5 +47,5 @@ pub use { | |||
43 | 47 | ||
44 | pub fn parse(text: String) -> SyntaxNode { | 48 | pub fn parse(text: String) -> SyntaxNode { |
45 | let tokens = tokenize(&text); | 49 | let tokens = tokenize(&text); |
46 | parser::parse::<yellow::GreenBuilder>(text, &tokens) | 50 | parser_impl::parse::<yellow::GreenBuilder>(text, &tokens) |
47 | } | 51 | } |
diff --git a/src/parser/mod.rs b/src/parser/mod.rs deleted file mode 100644 index 8631baa2e..000000000 --- a/src/parser/mod.rs +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | #[macro_use] | ||
2 | mod token_set; | ||
3 | mod event; | ||
4 | mod grammar; | ||
5 | mod input; | ||
6 | mod parser; | ||
7 | |||
8 | use {lexer::Token, parser::event::process}; | ||
9 | |||
10 | pub(crate) use self::event::Sink; | ||
11 | |||
12 | /// Parse a sequence of tokens into the representative node tree | ||
13 | pub(crate) fn parse<S: Sink>(text: String, tokens: &[Token]) -> S::Tree { | ||
14 | let events = { | ||
15 | let input = input::ParserInput::new(&text, tokens); | ||
16 | let parser_impl = parser::imp::ParserImpl::new(&input); | ||
17 | let mut parser = parser::Parser(parser_impl); | ||
18 | grammar::file(&mut parser); | ||
19 | parser.0.into_events() | ||
20 | }; | ||
21 | let mut sink = S::new(text); | ||
22 | process(&mut sink, tokens, events); | ||
23 | sink.finish() | ||
24 | } | ||
diff --git a/src/parser/token_set.rs b/src/parser/token_set.rs deleted file mode 100644 index a800f200d..000000000 --- a/src/parser/token_set.rs +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | use SyntaxKind; | ||
2 | |||
3 | pub(crate) struct TokenSet { | ||
4 | pub tokens: &'static [SyntaxKind], | ||
5 | } | ||
6 | |||
7 | impl TokenSet { | ||
8 | pub fn contains(&self, kind: SyntaxKind) -> bool { | ||
9 | self.tokens.contains(&kind) | ||
10 | } | ||
11 | } | ||
12 | |||
13 | #[macro_export] | ||
14 | macro_rules! token_set { | ||
15 | ($($t:ident),*) => { | ||
16 | TokenSet { | ||
17 | tokens: &[$($t),*], | ||
18 | } | ||
19 | }; | ||
20 | |||
21 | ($($t:ident),* ,) => { | ||
22 | token_set!($($t),*) | ||
23 | }; | ||
24 | } | ||
diff --git a/src/parser/parser/mod.rs b/src/parser_api.rs index 0930ff9e4..5a0da32c9 100644 --- a/src/parser/parser/mod.rs +++ b/src/parser_api.rs | |||
@@ -1,7 +1,30 @@ | |||
1 | use SyntaxKind::{self, ERROR}; | 1 | use { |
2 | parser_impl::ParserImpl, | ||
3 | SyntaxKind::{self, ERROR}, | ||
4 | }; | ||
2 | 5 | ||
3 | pub(super) mod imp; | 6 | pub(crate) struct TokenSet { |
4 | use self::imp::ParserImpl; | 7 | pub tokens: &'static [SyntaxKind], |
8 | } | ||
9 | |||
10 | impl TokenSet { | ||
11 | pub fn contains(&self, kind: SyntaxKind) -> bool { | ||
12 | self.tokens.contains(&kind) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | #[macro_export] | ||
17 | macro_rules! token_set { | ||
18 | ($($t:ident),*) => { | ||
19 | TokenSet { | ||
20 | tokens: &[$($t),*], | ||
21 | } | ||
22 | }; | ||
23 | |||
24 | ($($t:ident),* ,) => { | ||
25 | token_set!($($t),*) | ||
26 | }; | ||
27 | } | ||
5 | 28 | ||
6 | /// `Parser` struct provides the low-level API for | 29 | /// `Parser` struct provides the low-level API for |
7 | /// navigating through the stream of tokens and | 30 | /// navigating through the stream of tokens and |
diff --git a/src/parser/event.rs b/src/parser_impl/event.rs index 0086d32ea..eb5d0a4be 100644 --- a/src/parser/event.rs +++ b/src/parser_impl/event.rs | |||
@@ -9,22 +9,10 @@ | |||
9 | //! this stream to a real tree. | 9 | //! this stream to a real tree. |
10 | use { | 10 | use { |
11 | lexer::Token, | 11 | lexer::Token, |
12 | parser_impl::Sink, | ||
12 | SyntaxKind::{self, TOMBSTONE}, | 13 | SyntaxKind::{self, TOMBSTONE}, |
13 | TextUnit, | ||
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub(crate) trait Sink { | ||
17 | type Tree; | ||
18 | |||
19 | fn new(text: String) -> Self; | ||
20 | |||
21 | fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); | ||
22 | fn start_internal(&mut self, kind: SyntaxKind); | ||
23 | fn finish_internal(&mut self); | ||
24 | fn error(&mut self, err: String); | ||
25 | fn finish(self) -> Self::Tree; | ||
26 | } | ||
27 | |||
28 | /// `Parser` produces a flat list of `Event`s. | 16 | /// `Parser` produces a flat list of `Event`s. |
29 | /// They are converted to a tree-structure in | 17 | /// They are converted to a tree-structure in |
30 | /// a separate pass, via `TreeBuilder`. | 18 | /// a separate pass, via `TreeBuilder`. |
diff --git a/src/parser/input.rs b/src/parser_impl/input.rs index db76364b2..db76364b2 100644 --- a/src/parser/input.rs +++ b/src/parser_impl/input.rs | |||
diff --git a/src/parser/parser/imp.rs b/src/parser_impl/mod.rs index c653e3524..b58094be3 100644 --- a/src/parser/parser/imp.rs +++ b/src/parser_impl/mod.rs | |||
@@ -1,8 +1,45 @@ | |||
1 | use parser::event::Event; | 1 | mod event; |
2 | use parser::input::{InputPosition, ParserInput}; | 2 | mod input; |
3 | |||
4 | use { | ||
5 | grammar, | ||
6 | lexer::Token, | ||
7 | parser_api::Parser, | ||
8 | parser_impl::{ | ||
9 | event::{process, Event}, | ||
10 | input::{InputPosition, ParserInput}, | ||
11 | }, | ||
12 | TextUnit, | ||
13 | }; | ||
3 | 14 | ||
4 | use SyntaxKind::{self, EOF, TOMBSTONE}; | 15 | use SyntaxKind::{self, EOF, TOMBSTONE}; |
5 | 16 | ||
17 | pub(crate) trait Sink { | ||
18 | type Tree; | ||
19 | |||
20 | fn new(text: String) -> Self; | ||
21 | |||
22 | fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); | ||
23 | fn start_internal(&mut self, kind: SyntaxKind); | ||
24 | fn finish_internal(&mut self); | ||
25 | fn error(&mut self, err: String); | ||
26 | fn finish(self) -> Self::Tree; | ||
27 | } | ||
28 | |||
29 | /// Parse a sequence of tokens into the representative node tree | ||
30 | pub(crate) fn parse<S: Sink>(text: String, tokens: &[Token]) -> S::Tree { | ||
31 | let events = { | ||
32 | let input = input::ParserInput::new(&text, tokens); | ||
33 | let parser_impl = ParserImpl::new(&input); | ||
34 | let mut parser_api = Parser(parser_impl); | ||
35 | grammar::file(&mut parser_api); | ||
36 | parser_api.0.into_events() | ||
37 | }; | ||
38 | let mut sink = S::new(text); | ||
39 | process(&mut sink, tokens, events); | ||
40 | sink.finish() | ||
41 | } | ||
42 | |||
6 | /// Implementation details of `Parser`, extracted | 43 | /// Implementation details of `Parser`, extracted |
7 | /// to a separate struct in order not to pollute | 44 | /// to a separate struct in order not to pollute |
8 | /// the public API of the `Parser`. | 45 | /// the public API of the `Parser`. |
diff --git a/src/yellow/builder.rs b/src/yellow/builder.rs index 0f7ca45d7..b68ba789e 100644 --- a/src/yellow/builder.rs +++ b/src/yellow/builder.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use { | 1 | use { |
2 | parser::Sink, | 2 | parser_impl::Sink, |
3 | yellow::{GreenNode, GreenNodeBuilder, SyntaxError, SyntaxNode, SyntaxRoot}, | 3 | yellow::{GreenNode, GreenNodeBuilder, SyntaxError, SyntaxNode, SyntaxRoot}, |
4 | SyntaxKind, TextRange, TextUnit, | 4 | SyntaxKind, TextRange, TextUnit, |
5 | }; | 5 | }; |