diff options
-rw-r--r-- | src/parser/event_parser/grammar.rs | 7 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 9 | ||||
-rw-r--r-- | tests/data/parser/0001_struct_item.txt | 5 |
3 files changed, 16 insertions, 5 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index 0896506fb..be61483ec 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs | |||
@@ -43,13 +43,18 @@ fn item(p: &mut Parser) -> Result { | |||
43 | if p.current_is(STRUCT_KW) { | 43 | if p.current_is(STRUCT_KW) { |
44 | p.start(STRUCT_ITEM); | 44 | p.start(STRUCT_ITEM); |
45 | p.bump(); | 45 | p.bump(); |
46 | let _ = struct_item(p); | ||
46 | p.finish(); | 47 | p.finish(); |
47 | return OK; | 48 | return OK; |
48 | } | 49 | } |
49 | ERR | 50 | ERR |
50 | } | 51 | } |
51 | 52 | ||
52 | 53 | fn struct_item(p: &mut Parser) -> Result{ | |
54 | p.expect(IDENT)?; | ||
55 | p.expect(L_CURLY)?; | ||
56 | p.expect(R_CURLY) | ||
57 | } | ||
53 | 58 | ||
54 | // Paths, types, attributes, and stuff // | 59 | // Paths, types, attributes, and stuff // |
55 | 60 | ||
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index 2d5418a29..36452ef67 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs | |||
@@ -69,6 +69,15 @@ impl<'t> Parser<'t> { | |||
69 | Some(kind) | 69 | Some(kind) |
70 | } | 70 | } |
71 | 71 | ||
72 | pub(crate) fn expect(&mut self, kind: SyntaxKind) -> Result<(), ()> { | ||
73 | if kind == self.current().ok_or(())? { | ||
74 | self.bump(); | ||
75 | Ok(()) | ||
76 | } else { | ||
77 | Err(()) | ||
78 | } | ||
79 | } | ||
80 | |||
72 | fn event(&mut self, event: Event) { | 81 | fn event(&mut self, event: Event) { |
73 | self.events.push(event) | 82 | self.events.push(event) |
74 | } | 83 | } |
diff --git a/tests/data/parser/0001_struct_item.txt b/tests/data/parser/0001_struct_item.txt index 5ef544282..f599e9d2c 100644 --- a/tests/data/parser/0001_struct_item.txt +++ b/tests/data/parser/0001_struct_item.txt | |||
@@ -1,12 +1,9 @@ | |||
1 | FILE@[0; 13) | 1 | FILE@[0; 13) |
2 | STRUCT_ITEM@[0; 7) | 2 | STRUCT_ITEM@[0; 13) |
3 | STRUCT_KW@[0; 6) | 3 | STRUCT_KW@[0; 6) |
4 | WHITESPACE@[6; 7) | 4 | WHITESPACE@[6; 7) |
5 | ERROR@[7; 9) | ||
6 | IDENT@[7; 8) | 5 | IDENT@[7; 8) |
7 | WHITESPACE@[8; 9) | 6 | WHITESPACE@[8; 9) |
8 | ERROR@[9; 12) | ||
9 | L_CURLY@[9; 10) | 7 | L_CURLY@[9; 10) |
10 | WHITESPACE@[10; 12) | 8 | WHITESPACE@[10; 12) |
11 | ERROR@[12; 13) | ||
12 | R_CURLY@[12; 13) | 9 | R_CURLY@[12; 13) |