aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-13 10:42:19 +0000
committerAleksey Kladov <[email protected]>2018-01-13 10:42:19 +0000
commit55891be06a1f0a051638cb59f1d15167faf5ab82 (patch)
tree2816530bc237e66b6d7b40f29838d7bbed085f7f /src
parent29b2e0adcc35834dda2884222624bfcc268a3eff (diff)
G: use trees
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/items.rs56
-rw-r--r--src/parser/event_parser/grammar/paths.rs22
-rw-r--r--src/parser/mod.rs2
-rw-r--r--src/syntax_kinds.rs14
4 files changed, 80 insertions, 14 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index f7310c09a..2f64111ab 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -74,9 +74,63 @@ fn mod_item(p: &mut Parser) {
74 p.curly_block(mod_contents); 74 p.curly_block(mod_contents);
75} 75}
76 76
77pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool {
78 kind == STAR || kind == L_CURLY
79}
80
77fn use_item(p: &mut Parser) { 81fn use_item(p: &mut Parser) {
78 paths::use_path(p); 82 use_tree(p);
79 p.expect(SEMI); 83 p.expect(SEMI);
84
85 fn use_tree(p: &mut Parser) -> bool{
86 if node_if(p, STAR, USE_TREE, |_| ()) {
87 return true
88 }
89 if node_if(p, [COLONCOLON, STAR], USE_TREE, |_| ()) {
90 return true
91 }
92 if [COLONCOLON, L_CURLY].is_ahead(p) || L_CURLY.is_ahead(p) {
93 node(p, USE_TREE, |p| {
94 p.eat(COLONCOLON);
95 p.curly_block(|p| {
96 comma_list(p, EOF, use_tree);
97 });
98 });
99 return true;
100 }
101 if paths::is_path_start(p) {
102 node(p, USE_TREE, |p| {
103 paths::use_path(p);
104 match p.current() {
105 AS_KW => {
106 alias(p);
107 }
108 COLONCOLON => {
109 p.bump();
110 match p.current() {
111 STAR => {
112 p.bump();
113 }
114 L_CURLY => {
115 p.curly_block(|p| {
116 comma_list(p, EOF, use_tree);
117 });
118 }
119 _ => {
120 // is this unreachable?
121 p.error()
122 .message("expected `{` or `*`")
123 .emit();
124 }
125 }
126 }
127 _ => (),
128 }
129 });
130 return true;
131 }
132 false
133 }
80} 134}
81 135
82fn struct_field(p: &mut Parser) -> bool { 136fn struct_field(p: &mut Parser) -> bool {
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs
index d6887a9ba..62d1a3bb2 100644
--- a/src/parser/event_parser/grammar/paths.rs
+++ b/src/parser/event_parser/grammar/paths.rs
@@ -1,7 +1,11 @@
1use super::*; 1use super::*;
2 2
3pub (crate) fn is_path_start(p: &Parser) -> bool {
4 AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p)
5}
6
3pub(crate) fn use_path(p: &mut Parser) { 7pub(crate) fn use_path(p: &mut Parser) {
4 if !AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p) { 8 if !is_path_start(p) {
5 return; 9 return;
6 } 10 }
7 let mut prev = p.mark(); 11 let mut prev = p.mark();
@@ -10,11 +14,17 @@ pub(crate) fn use_path(p: &mut Parser) {
10 }); 14 });
11 many(p, |p| { 15 many(p, |p| {
12 let curr = p.mark(); 16 let curr = p.mark();
13 node_if(p, COLONCOLON, PATH, |p| { 17 if p.current() == COLONCOLON && !items::is_use_tree_start(p.raw_lookahead(1)) {
14 path_segment(p, false); 18 node(p, PATH, |p| {
15 p.forward_parent(prev, curr); 19 p.bump();
16 prev = curr; 20 path_segment(p, false);
17 }) 21 p.forward_parent(prev, curr);
22 prev = curr;
23 });
24 true
25 } else {
26 false
27 }
18 }); 28 });
19} 29}
20 30
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index c08d32d08..0c29442f9 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -29,7 +29,7 @@ fn from_events_to_file(
29 } 29 }
30 30
31 match event { 31 match event {
32 &Event::Start { kind, forward_parent } => { 32 &Event::Start { .. } => {
33 forward_parents.clear(); 33 forward_parents.clear();
34 let mut idx = i; 34 let mut idx = i;
35 loop { 35 loop {
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index 48f55fa97..8bc63a210 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -77,13 +77,14 @@ pub const ATTR: SyntaxKind = SyntaxKind(72);
77pub const META_ITEM: SyntaxKind = SyntaxKind(73); 77pub const META_ITEM: SyntaxKind = SyntaxKind(73);
78pub const MOD_ITEM: SyntaxKind = SyntaxKind(74); 78pub const MOD_ITEM: SyntaxKind = SyntaxKind(74);
79pub const USE_ITEM: SyntaxKind = SyntaxKind(75); 79pub const USE_ITEM: SyntaxKind = SyntaxKind(75);
80pub const PATH: SyntaxKind = SyntaxKind(76); 80pub const USE_TREE: SyntaxKind = SyntaxKind(76);
81pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(77); 81pub const PATH: SyntaxKind = SyntaxKind(77);
82pub const LITERAL: SyntaxKind = SyntaxKind(78); 82pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(78);
83pub const ALIAS: SyntaxKind = SyntaxKind(79); 83pub const LITERAL: SyntaxKind = SyntaxKind(79);
84pub const VISIBILITY: SyntaxKind = SyntaxKind(80); 84pub const ALIAS: SyntaxKind = SyntaxKind(80);
85pub const VISIBILITY: SyntaxKind = SyntaxKind(81);
85 86
86static INFOS: [SyntaxInfo; 81] = [ 87static INFOS: [SyntaxInfo; 82] = [
87 SyntaxInfo { name: "USE_KW" }, 88 SyntaxInfo { name: "USE_KW" },
88 SyntaxInfo { name: "FN_KW" }, 89 SyntaxInfo { name: "FN_KW" },
89 SyntaxInfo { name: "STRUCT_KW" }, 90 SyntaxInfo { name: "STRUCT_KW" },
@@ -160,6 +161,7 @@ static INFOS: [SyntaxInfo; 81] = [
160 SyntaxInfo { name: "META_ITEM" }, 161 SyntaxInfo { name: "META_ITEM" },
161 SyntaxInfo { name: "MOD_ITEM" }, 162 SyntaxInfo { name: "MOD_ITEM" },
162 SyntaxInfo { name: "USE_ITEM" }, 163 SyntaxInfo { name: "USE_ITEM" },
164 SyntaxInfo { name: "USE_TREE" },
163 SyntaxInfo { name: "PATH" }, 165 SyntaxInfo { name: "PATH" },
164 SyntaxInfo { name: "PATH_SEGMENT" }, 166 SyntaxInfo { name: "PATH_SEGMENT" },
165 SyntaxInfo { name: "LITERAL" }, 167 SyntaxInfo { name: "LITERAL" },