aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-11 20:01:12 +0000
committerAleksey Kladov <[email protected]>2018-01-11 20:01:12 +0000
commit9a8e9bc4c6339051ef260f7794603481b6ff0bf2 (patch)
treeb9d23b06feda7249873ca40c88419e1b5c5d9bd6 /src
parent89699c4803a0d12155adf653742f463872667610 (diff)
G: item outer attributes
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/attributes.rs18
-rw-r--r--src/parser/event_parser/grammar/items.rs2
-rw-r--r--src/parser/event_parser/grammar/mod.rs10
-rw-r--r--src/parser/event_parser/parser.rs4
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 @@
1use super::*; 1use super::*;
2 2
3enum AttrKind {
4 Inner, Outer
5}
6
3pub(super) fn inner_attributes(p: &mut Parser) { 7pub(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
7pub(super) fn outer_attributes(_: &mut Parser) { 11pub(super) fn outer_attributes(p: &mut Parser) {
12 many(p, |p| attribute(p, AttrKind::Outer))
8} 13}
9 14
10 15
11fn attribute(p: &mut Parser, inner: bool) -> bool { 16fn 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
13fn item_first(p: &Parser) -> bool { 13fn 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
43fn many<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) { 43fn 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
47fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, end: SyntaxKind, f: F) { 55fn 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);