aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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.rs8
-rw-r--r--src/parser/mod.rs24
-rw-r--r--src/parser/token_set.rs24
-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.rs2
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 @@
24mod attributes; 24mod attributes;
25mod expressions; 25mod expressions;
26mod items; 26mod items;
27mod params;
27mod paths; 28mod paths;
28mod patterns; 29mod patterns;
29mod params;
30mod type_params;
31mod type_args; 30mod type_args;
31mod type_params;
32mod types; 32mod types;
33 33
34use { 34use {
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
87pub(super) fn where_clause(p: &mut Parser) { 86pub(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;
27pub mod algo; 27pub mod algo;
28pub mod ast; 28pub mod ast;
29mod lexer; 29mod lexer;
30mod parser; 30#[macro_use]
31mod parser_api;
32mod grammar;
33mod parser_impl;
34
31mod syntax_kinds; 35mod syntax_kinds;
32/// Utilities for simple uses of the parser. 36/// Utilities for simple uses of the parser.
33pub mod utils; 37pub mod utils;
@@ -43,5 +47,5 @@ pub use {
43 47
44pub fn parse(text: String) -> SyntaxNode { 48pub 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]
2mod token_set;
3mod event;
4mod grammar;
5mod input;
6mod parser;
7
8use {lexer::Token, parser::event::process};
9
10pub(crate) use self::event::Sink;
11
12/// Parse a sequence of tokens into the representative node tree
13pub(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 @@
1use SyntaxKind;
2
3pub(crate) struct TokenSet {
4 pub tokens: &'static [SyntaxKind],
5}
6
7impl TokenSet {
8 pub fn contains(&self, kind: SyntaxKind) -> bool {
9 self.tokens.contains(&kind)
10 }
11}
12
13#[macro_export]
14macro_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 @@
1use SyntaxKind::{self, ERROR}; 1use {
2 parser_impl::ParserImpl,
3 SyntaxKind::{self, ERROR},
4};
2 5
3pub(super) mod imp; 6pub(crate) struct TokenSet {
4use self::imp::ParserImpl; 7 pub tokens: &'static [SyntaxKind],
8}
9
10impl TokenSet {
11 pub fn contains(&self, kind: SyntaxKind) -> bool {
12 self.tokens.contains(&kind)
13 }
14}
15
16#[macro_export]
17macro_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.
10use { 10use {
11 lexer::Token, 11 lexer::Token,
12 parser_impl::Sink,
12 SyntaxKind::{self, TOMBSTONE}, 13 SyntaxKind::{self, TOMBSTONE},
13 TextUnit,
14}; 14};
15 15
16pub(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 @@
1use parser::event::Event; 1mod event;
2use parser::input::{InputPosition, ParserInput}; 2mod input;
3
4use {
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
4use SyntaxKind::{self, EOF, TOMBSTONE}; 15use SyntaxKind::{self, EOF, TOMBSTONE};
5 16
17pub(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
30pub(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 @@
1use { 1use {
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};