diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/event_parser/grammar/attributes.rs | 18 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 2 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 10 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 4 |
4 files changed, 25 insertions, 9 deletions
diff --git a/src/parser/event_parser/grammar/attributes.rs b/src/parser/event_parser/grammar/attributes.rs index 52210ccad..d774f8827 100644 --- a/src/parser/event_parser/grammar/attributes.rs +++ b/src/parser/event_parser/grammar/attributes.rs | |||
@@ -1,22 +1,26 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | enum AttrKind { | ||
4 | Inner, Outer | ||
5 | } | ||
6 | |||
3 | pub(super) fn inner_attributes(p: &mut Parser) { | 7 | pub(super) fn inner_attributes(p: &mut Parser) { |
4 | many(p, |p| attribute(p, true)) | 8 | many(p, |p| attribute(p, AttrKind::Inner)) |
5 | } | 9 | } |
6 | 10 | ||
7 | pub(super) fn outer_attributes(_: &mut Parser) { | 11 | pub(super) fn outer_attributes(p: &mut Parser) { |
12 | many(p, |p| attribute(p, AttrKind::Outer)) | ||
8 | } | 13 | } |
9 | 14 | ||
10 | 15 | ||
11 | fn attribute(p: &mut Parser, inner: bool) -> bool { | 16 | fn attribute(p: &mut Parser, kind: AttrKind) -> bool { |
12 | fn attr_tail(p: &mut Parser) { | 17 | fn attr_tail(p: &mut Parser) { |
13 | meta_item(p) && p.expect(R_BRACK); | 18 | meta_item(p) && p.expect(R_BRACK); |
14 | } | 19 | } |
15 | 20 | ||
16 | if inner { | 21 | match kind { |
17 | node_if(p, [POUND, EXCL, L_BRACK], ATTR, attr_tail) | 22 | AttrKind::Inner => node_if(p, [POUND, EXCL, L_BRACK], ATTR, attr_tail), |
18 | } else { | 23 | AttrKind::Outer => node_if(p, [POUND, L_BRACK], ATTR, attr_tail), |
19 | node_if(p, [POUND, L_BRACK], ATTR, attr_tail) | ||
20 | } | 24 | } |
21 | } | 25 | } |
22 | 26 | ||
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 950e02a4d..522986ed0 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs | |||
@@ -12,7 +12,7 @@ pub(super) fn mod_contents(p: &mut Parser) { | |||
12 | 12 | ||
13 | fn item_first(p: &Parser) -> bool { | 13 | fn item_first(p: &Parser) -> bool { |
14 | match p.current() { | 14 | match p.current() { |
15 | STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW => true, | 15 | STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW | POUND => true, |
16 | _ => false, | 16 | _ => false, |
17 | } | 17 | } |
18 | } | 18 | } |
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 60458ce70..76f62b714 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs | |||
@@ -41,7 +41,15 @@ fn node<F: FnOnce(&mut Parser)>(p: &mut Parser, node_kind: SyntaxKind, rest: F) | |||
41 | } | 41 | } |
42 | 42 | ||
43 | fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { | 43 | fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { |
44 | while f(p) { } | 44 | loop { |
45 | let pos = p.pos(); | ||
46 | if !f(p) { | ||
47 | return | ||
48 | } | ||
49 | if pos == p.pos() { | ||
50 | panic!("Infinite loop in parser") | ||
51 | } | ||
52 | } | ||
45 | } | 53 | } |
46 | 54 | ||
47 | fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, end: SyntaxKind, f: F) { | 55 | fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, end: SyntaxKind, f: F) { |
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index a1a0ebfea..d7d24fa27 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs | |||
@@ -44,6 +44,10 @@ impl<'t> Parser<'t> { | |||
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | pub(crate) fn pos(&self) -> usize { | ||
48 | self.pos | ||
49 | } | ||
50 | |||
47 | pub(crate) fn into_events(self) -> Vec<Event> { | 51 | pub(crate) fn into_events(self) -> Vec<Event> { |
48 | assert!(self.curly_limit.is_none()); | 52 | assert!(self.curly_limit.is_none()); |
49 | assert!(self.current() == EOF); | 53 | assert!(self.current() == EOF); |