aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-27 21:05:31 +0000
committerAleksey Kladov <[email protected]>2018-01-27 21:05:31 +0000
commitcaba13a2dd1f3514ced3fbc2d4966def644f5ad8 (patch)
tree569d8a69fc7feb6ea36af3d1dbcf684c5f06c327 /src/parser
parentd280c72338313ed7d900a9dad05923d344b5fa86 (diff)
Simplify
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event_parser/grammar/items.rs24
-rw-r--r--src/parser/event_parser/grammar/mod.rs9
2 files changed, 22 insertions, 11 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index 2e0aa3043..38a4657aa 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -45,7 +45,6 @@ fn item(p: &mut Parser) {
45 } 45 }
46 err_token => { 46 err_token => {
47 item.abandon(p); 47 item.abandon(p);
48 let err = p.start();
49 let message = if err_token == SEMI { 48 let message = if err_token == SEMI {
50 //TODO: if the item is incomplete, this message is misleading 49 //TODO: if the item is incomplete, this message is misleading
51 "expected item, found `;`\n\ 50 "expected item, found `;`\n\
@@ -53,11 +52,7 @@ fn item(p: &mut Parser) {
53 } else { 52 } else {
54 "expected item" 53 "expected item"
55 }; 54 };
56 p.error() 55 p.err_and_bump(message);
57 .message(message)
58 .emit();
59 p.bump();
60 err.complete(p, ERROR);
61 return; 56 return;
62 } 57 }
63 }; 58 };
@@ -127,7 +122,7 @@ fn pos_fields(p: &mut Parser) {
127 if !p.expect(L_PAREN) { 122 if !p.expect(L_PAREN) {
128 return; 123 return;
129 } 124 }
130 while !(p.at(R_PAREN) || p.at(EOF)) { 125 while !p.at(R_PAREN) && !p.at(EOF) {
131 let pos_field = p.start(); 126 let pos_field = p.start();
132 visibility(p); 127 visibility(p);
133 types::type_ref(p); 128 types::type_ref(p);
@@ -173,7 +168,7 @@ fn use_item(p: &mut Parser) {
173 use_tree(p); 168 use_tree(p);
174 p.expect(SEMI); 169 p.expect(SEMI);
175 170
176 fn use_tree(p: &mut Parser) -> bool { 171 fn use_tree(p: &mut Parser){
177 let la = p.raw_lookahead(1); 172 let la = p.raw_lookahead(1);
178 let m = p.start(); 173 let m = p.start();
179 match (p.current(), la) { 174 match (p.current(), la) {
@@ -216,16 +211,23 @@ fn use_item(p: &mut Parser) {
216 } 211 }
217 _ => { 212 _ => {
218 m.abandon(p); 213 m.abandon(p);
219 return false 214 p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`");
215 return;
220 }, 216 },
221 } 217 }
222 m.complete(p, USE_TREE); 218 m.complete(p, USE_TREE);
223 return true;
224 } 219 }
225 220
226 fn nested_trees(p: &mut Parser) { 221 fn nested_trees(p: &mut Parser) {
227 assert!(p.at(L_CURLY)); 222 assert!(p.at(L_CURLY));
228 p.curly_block(|p| comma_list(p, EOF, use_tree)); 223 p.bump();
224 while !p.at(EOF) && !p.at(R_CURLY) {
225 use_tree(p);
226 if !p.at(R_CURLY) {
227 p.expect(COMMA);
228 }
229 }
230 p.expect(R_CURLY);
229 } 231 }
230} 232}
231 233
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs
index 32e4db698..67773453b 100644
--- a/src/parser/event_parser/grammar/mod.rs
+++ b/src/parser/event_parser/grammar/mod.rs
@@ -84,6 +84,15 @@ impl<'p> Parser<'p> {
84 l.is_ahead(self) 84 l.is_ahead(self)
85 } 85 }
86 86
87 fn err_and_bump(&mut self, message: &str) {
88 let err = self.start();
89 self.error()
90 .message(message)
91 .emit();
92 self.bump();
93 err.complete(self, ERROR);
94 }
95
87 pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { 96 pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool {
88 if self.at(kind) { 97 if self.at(kind) {
89 self.bump(); 98 self.bump();