aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/event_parser/grammar')
-rw-r--r--src/parser/event_parser/grammar/attributes.rs15
-rw-r--r--src/parser/event_parser/grammar/expressions.rs8
-rw-r--r--src/parser/event_parser/grammar/items.rs38
-rw-r--r--src/parser/event_parser/grammar/mod.rs25
-rw-r--r--src/parser/event_parser/grammar/paths.rs4
-rw-r--r--src/parser/event_parser/grammar/types.rs2
6 files changed, 31 insertions, 61 deletions
diff --git a/src/parser/event_parser/grammar/attributes.rs b/src/parser/event_parser/grammar/attributes.rs
index 045840059..8bf04afce 100644
--- a/src/parser/event_parser/grammar/attributes.rs
+++ b/src/parser/event_parser/grammar/attributes.rs
@@ -12,8 +12,7 @@ pub(super) fn outer_attributes(p: &mut Parser) {
12 } 12 }
13} 13}
14 14
15 15fn attribute(p: &mut Parser, inner: bool) {
16fn attribute(p: &mut Parser, inner: bool){
17 let attr = p.start(); 16 let attr = p.start();
18 assert!(p.at(POUND)); 17 assert!(p.at(POUND));
19 p.bump(); 18 p.bump();
@@ -38,9 +37,7 @@ fn meta_item(p: &mut Parser) {
38 EQ => { 37 EQ => {
39 p.bump(); 38 p.bump();
40 if !expressions::literal(p) { 39 if !expressions::literal(p) {
41 p.error() 40 p.error().message("expected literal").emit();
42 .message("expected literal")
43 .emit();
44 } 41 }
45 } 42 }
46 L_PAREN => meta_item_arg_list(p), 43 L_PAREN => meta_item_arg_list(p),
@@ -48,9 +45,7 @@ fn meta_item(p: &mut Parser) {
48 } 45 }
49 meta_item.complete(p, META_ITEM); 46 meta_item.complete(p, META_ITEM);
50 } else { 47 } else {
51 p.error() 48 p.error().message("expected attribute value").emit()
52 .message("expected attribute value")
53 .emit()
54 } 49 }
55} 50}
56 51
@@ -73,8 +68,8 @@ fn meta_item_arg_list(p: &mut Parser) {
73 p.error().message(message).emit(); 68 p.error().message(message).emit();
74 p.bump(); 69 p.bump();
75 err.complete(p, ERROR); 70 err.complete(p, ERROR);
76 continue 71 continue;
77 } 72 },
78 } 73 }
79 if !p.at(R_PAREN) { 74 if !p.at(R_PAREN) {
80 p.expect(COMMA); 75 p.expect(COMMA);
diff --git a/src/parser/event_parser/grammar/expressions.rs b/src/parser/event_parser/grammar/expressions.rs
index a943b8c81..c81dc6c35 100644
--- a/src/parser/event_parser/grammar/expressions.rs
+++ b/src/parser/event_parser/grammar/expressions.rs
@@ -2,15 +2,13 @@ use super::*;
2 2
3pub(super) fn literal(p: &mut Parser) -> bool { 3pub(super) fn literal(p: &mut Parser) -> bool {
4 match p.current() { 4 match p.current() {
5 TRUE_KW | FALSE_KW | 5 TRUE_KW | FALSE_KW | INT_NUMBER | FLOAT_NUMBER | BYTE | CHAR | STRING | RAW_STRING
6 INT_NUMBER | FLOAT_NUMBER | 6 | BYTE_STRING | RAW_BYTE_STRING => {
7 BYTE | CHAR |
8 STRING | RAW_STRING | BYTE_STRING | RAW_BYTE_STRING => {
9 let lit = p.start(); 7 let lit = p.start();
10 p.bump(); 8 p.bump();
11 lit.complete(p, LITERAL); 9 lit.complete(p, LITERAL);
12 true 10 true
13 } 11 }
14 _ => false 12 _ => false,
15 } 13 }
16} 14}
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index 7706690cc..e569e5047 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -7,15 +7,8 @@ pub(super) fn mod_contents(p: &mut Parser) {
7 } 7 }
8} 8}
9 9
10pub(super) const ITEM_FIRST: TokenSet = token_set![ 10pub(super) const ITEM_FIRST: TokenSet =
11 EXTERN_KW, 11 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,];
12 MOD_KW,
13 USE_KW,
14 STRUCT_KW,
15 FN_KW,
16 PUB_KW,
17 POUND,
18];
19 12
20fn item(p: &mut Parser) { 13fn item(p: &mut Parser) {
21 let item = p.start(); 14 let item = p.start();
@@ -48,7 +41,7 @@ fn item(p: &mut Parser) {
48 let message = if err_token == SEMI { 41 let message = if err_token == SEMI {
49 //TODO: if the item is incomplete, this message is misleading 42 //TODO: if the item is incomplete, this message is misleading
50 "expected item, found `;`\n\ 43 "expected item, found `;`\n\
51 consider removing this semicolon" 44 consider removing this semicolon"
52 } else { 45 } else {
53 "expected item" 46 "expected item"
54 }; 47 };
@@ -76,10 +69,9 @@ fn struct_item(p: &mut Parser) {
76 return; 69 return;
77 } 70 }
78 L_CURLY => named_fields(p), 71 L_CURLY => named_fields(p),
79 _ => { //TODO: special case `(` error message 72 _ => {
80 p.error() 73 //TODO: special case `(` error message
81 .message("expected `;` or `{`") 74 p.error().message("expected `;` or `{`").emit();
82 .emit();
83 return; 75 return;
84 } 76 }
85 } 77 }
@@ -94,9 +86,7 @@ fn struct_item(p: &mut Parser) {
94 p.expect(SEMI); 86 p.expect(SEMI);
95 } 87 }
96 _ => { 88 _ => {
97 p.error() 89 p.error().message("expected `;`, `{`, or `(`").emit();
98 .message("expected `;`, `{`, or `(`")
99 .emit();
100 return; 90 return;
101 } 91 }
102 } 92 }
@@ -177,7 +167,7 @@ fn use_item(p: &mut Parser) {
177 use_tree(p); 167 use_tree(p);
178 p.expect(SEMI); 168 p.expect(SEMI);
179 169
180 fn use_tree(p: &mut Parser){ 170 fn use_tree(p: &mut Parser) {
181 let la = p.raw_lookahead(1); 171 let la = p.raw_lookahead(1);
182 let m = p.start(); 172 let m = p.start();
183 match (p.current(), la) { 173 match (p.current(), la) {
@@ -209,9 +199,7 @@ fn use_item(p: &mut Parser) {
209 L_CURLY => nested_trees(p), 199 L_CURLY => nested_trees(p),
210 _ => { 200 _ => {
211 // is this unreachable? 201 // is this unreachable?
212 p.error() 202 p.error().message("expected `{` or `*`").emit();
213 .message("expected `{` or `*`")
214 .emit();
215 } 203 }
216 } 204 }
217 } 205 }
@@ -222,7 +210,7 @@ fn use_item(p: &mut Parser) {
222 m.abandon(p); 210 m.abandon(p);
223 p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); 211 p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`");
224 return; 212 return;
225 }, 213 }
226 } 214 }
227 m.complete(p, USE_TREE); 215 m.complete(p, USE_TREE);
228 } 216 }
@@ -240,13 +228,9 @@ fn use_item(p: &mut Parser) {
240 } 228 }
241} 229}
242 230
243
244fn fn_item(p: &mut Parser) { 231fn fn_item(p: &mut Parser) {
245 assert!(p.at(FN_KW)); 232 assert!(p.at(FN_KW));
246 p.bump(); 233 p.bump();
247 234
248 p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) 235 p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ());
249 && p.curly_block(|_| ());
250} 236}
251
252
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs
index 6e4f72096..c6ab1fbe2 100644
--- a/src/parser/event_parser/grammar/mod.rs
+++ b/src/parser/event_parser/grammar/mod.rs
@@ -1,5 +1,5 @@
1use super::parser::{Parser, TokenSet}; 1use super::parser::{Parser, TokenSet};
2use {SyntaxKind}; 2use SyntaxKind;
3use tree::EOF; 3use tree::EOF;
4use syntax_kinds::*; 4use syntax_kinds::*;
5 5
@@ -29,7 +29,7 @@ fn visibility(p: &mut Parser) {
29 } 29 }
30 p.expect(R_PAREN); 30 p.expect(R_PAREN);
31 } 31 }
32 _ => () 32 _ => (),
33 } 33 }
34 } 34 }
35 vis.complete(p, VISIBILITY); 35 vis.complete(p, VISIBILITY);
@@ -53,9 +53,7 @@ impl<'p> Parser<'p> {
53 53
54 fn err_and_bump(&mut self, message: &str) { 54 fn err_and_bump(&mut self, message: &str) {
55 let err = self.start(); 55 let err = self.start();
56 self.error() 56 self.error().message(message).emit();
57 .message(message)
58 .emit();
59 self.bump(); 57 self.bump();
60 err.complete(self, ERROR); 58 err.complete(self, ERROR);
61 } 59 }
@@ -65,15 +63,16 @@ impl<'p> Parser<'p> {
65 self.bump(); 63 self.bump();
66 true 64 true
67 } else { 65 } else {
68 self.error() 66 self.error().message(format!("expected {:?}", kind)).emit();
69 .message(format!("expected {:?}", kind))
70 .emit();
71 false 67 false
72 } 68 }
73 } 69 }
74 70
75 fn eat(&mut self, kind: SyntaxKind) -> bool { 71 fn eat(&mut self, kind: SyntaxKind) -> bool {
76 self.current() == kind && { self.bump(); true } 72 self.current() == kind && {
73 self.bump();
74 true
75 }
77 } 76 }
78} 77}
79 78
@@ -94,8 +93,7 @@ impl Lookahead for SyntaxKind {
94 93
95impl Lookahead for [SyntaxKind; 2] { 94impl Lookahead for [SyntaxKind; 2] {
96 fn is_ahead(self, p: &Parser) -> bool { 95 fn is_ahead(self, p: &Parser) -> bool {
97 p.current() == self[0] 96 p.current() == self[0] && p.raw_lookahead(1) == self[1]
98 && p.raw_lookahead(1) == self[1]
99 } 97 }
100 98
101 fn consume(p: &mut Parser) { 99 fn consume(p: &mut Parser) {
@@ -106,9 +104,7 @@ impl Lookahead for [SyntaxKind; 2] {
106 104
107impl Lookahead for [SyntaxKind; 3] { 105impl Lookahead for [SyntaxKind; 3] {
108 fn is_ahead(self, p: &Parser) -> bool { 106 fn is_ahead(self, p: &Parser) -> bool {
109 p.current() == self[0] 107 p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2]
110 && p.raw_lookahead(1) == self[1]
111 && p.raw_lookahead(2) == self[2]
112 } 108 }
113 109
114 fn consume(p: &mut Parser) { 110 fn consume(p: &mut Parser) {
@@ -130,5 +126,4 @@ impl<'a> Lookahead for AnyOf<'a> {
130 fn consume(p: &mut Parser) { 126 fn consume(p: &mut Parser) {
131 p.bump(); 127 p.bump();
132 } 128 }
133
134} 129}
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs
index b58c59aef..4e028073a 100644
--- a/src/parser/event_parser/grammar/paths.rs
+++ b/src/parser/event_parser/grammar/paths.rs
@@ -34,9 +34,7 @@ fn path_segment(p: &mut Parser, first: bool) {
34 p.bump(); 34 p.bump();
35 } 35 }
36 _ => { 36 _ => {
37 p.error() 37 p.error().message("expected identifier").emit();
38 .message("expected identifier")
39 .emit();
40 } 38 }
41 }; 39 };
42 segment.complete(p, PATH_SEGMENT); 40 segment.complete(p, PATH_SEGMENT);
diff --git a/src/parser/event_parser/grammar/types.rs b/src/parser/event_parser/grammar/types.rs
index c431643d7..1a3d44a0a 100644
--- a/src/parser/event_parser/grammar/types.rs
+++ b/src/parser/event_parser/grammar/types.rs
@@ -2,4 +2,4 @@ use super::*;
2 2
3pub(super) fn type_ref(p: &mut Parser) { 3pub(super) fn type_ref(p: &mut Parser) {
4 p.expect(IDENT); 4 p.expect(IDENT);
5} \ No newline at end of file 5}