diff options
Diffstat (limited to 'crates/libsyntax2/src/grammar/attributes.rs')
-rw-r--r-- | crates/libsyntax2/src/grammar/attributes.rs | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/crates/libsyntax2/src/grammar/attributes.rs b/crates/libsyntax2/src/grammar/attributes.rs index c411d4d7f..cd30e8a45 100644 --- a/crates/libsyntax2/src/grammar/attributes.rs +++ b/crates/libsyntax2/src/grammar/attributes.rs | |||
@@ -22,58 +22,10 @@ fn attribute(p: &mut Parser, inner: bool) { | |||
22 | p.bump(); | 22 | p.bump(); |
23 | } | 23 | } |
24 | 24 | ||
25 | if p.expect(L_BRACK) { | 25 | if p.at(L_BRACK) { |
26 | meta_item(p); | 26 | items::token_tree(p); |
27 | p.expect(R_BRACK); | ||
28 | } | ||
29 | attr.complete(p, ATTR); | ||
30 | } | ||
31 | |||
32 | fn meta_item(p: &mut Parser) { | ||
33 | if p.at(IDENT) { | ||
34 | let meta_item = p.start(); | ||
35 | p.bump(); | ||
36 | match p.current() { | ||
37 | EQ => { | ||
38 | p.bump(); | ||
39 | if expressions::literal(p).is_none() { | ||
40 | p.error("expected literal"); | ||
41 | } | ||
42 | } | ||
43 | L_PAREN => meta_item_arg_list(p), | ||
44 | _ => (), | ||
45 | } | ||
46 | meta_item.complete(p, META_ITEM); | ||
47 | } else { | 27 | } else { |
48 | p.error("expected attribute value"); | 28 | p.error("expected `[`"); |
49 | } | ||
50 | } | ||
51 | |||
52 | fn meta_item_arg_list(p: &mut Parser) { | ||
53 | assert!(p.at(L_PAREN)); | ||
54 | p.bump(); | ||
55 | loop { | ||
56 | match p.current() { | ||
57 | EOF | R_PAREN => break, | ||
58 | IDENT => meta_item(p), | ||
59 | c => if expressions::literal(p).is_none() { | ||
60 | let message = "expected attribute"; | ||
61 | |||
62 | if items::ITEM_FIRST.contains(c) { | ||
63 | p.error(message); | ||
64 | return; | ||
65 | } | ||
66 | |||
67 | let err = p.start(); | ||
68 | p.error(message); | ||
69 | p.bump(); | ||
70 | err.complete(p, ERROR); | ||
71 | continue; | ||
72 | }, | ||
73 | } | ||
74 | if !p.at(R_PAREN) { | ||
75 | p.expect(COMMA); | ||
76 | } | ||
77 | } | 29 | } |
78 | p.expect(R_PAREN); | 30 | attr.complete(p, ATTR); |
79 | } | 31 | } |