diff options
Diffstat (limited to 'src/parser/event_parser/grammar.rs')
-rw-r--r-- | src/parser/event_parser/grammar.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index be61483ec..77596fea6 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | use super::Event; | ||
2 | use super::parser::Parser; | 1 | use super::parser::Parser; |
3 | 2 | ||
4 | use syntax_kinds::*; | 3 | use syntax_kinds::*; |
@@ -50,10 +49,26 @@ fn item(p: &mut Parser) -> Result { | |||
50 | ERR | 49 | ERR |
51 | } | 50 | } |
52 | 51 | ||
53 | fn struct_item(p: &mut Parser) -> Result{ | 52 | fn struct_item(p: &mut Parser) -> Result { |
54 | p.expect(IDENT)?; | 53 | p.expect(IDENT)?; |
55 | p.expect(L_CURLY)?; | 54 | p.curly_block(|p| { |
56 | p.expect(R_CURLY) | 55 | comma_list(p, struct_field) |
56 | }) | ||
57 | } | ||
58 | |||
59 | fn struct_field(p: &mut Parser) -> Result { | ||
60 | if !p.current_is(IDENT) { | ||
61 | return ERR; | ||
62 | } | ||
63 | p.start(STRUCT_FIELD); | ||
64 | p.bump(); | ||
65 | ignore_errors(|| { | ||
66 | p.expect(COLON)?; | ||
67 | p.expect(IDENT)?; | ||
68 | OK | ||
69 | }); | ||
70 | p.finish(); | ||
71 | OK | ||
57 | } | 72 | } |
58 | 73 | ||
59 | // Paths, types, attributes, and stuff // | 74 | // Paths, types, attributes, and stuff // |
@@ -78,4 +93,19 @@ fn skip_one_token(p: &mut Parser) { | |||
78 | p.start(ERROR); | 93 | p.start(ERROR); |
79 | p.bump().unwrap(); | 94 | p.bump().unwrap(); |
80 | p.finish(); | 95 | p.finish(); |
96 | } | ||
97 | |||
98 | fn ignore_errors<F: FnOnce() -> Result>(f: F) { | ||
99 | drop(f()); | ||
100 | } | ||
101 | |||
102 | fn comma_list<F: Fn(&mut Parser) -> Result>(p: &mut Parser, element: F) { | ||
103 | loop { | ||
104 | if element(p).is_err() { | ||
105 | return | ||
106 | } | ||
107 | if p.expect(COMMA).is_err() { | ||
108 | return | ||
109 | } | ||
110 | } | ||
81 | } \ No newline at end of file | 111 | } \ No newline at end of file |