aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/attributes.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-16 10:51:40 +0100
committerAleksey Kladov <[email protected]>2018-08-16 10:51:40 +0100
commit7094291573dc819e3115950ec3b2316bd5e9ea33 (patch)
treebe18ef6c5baab68acac484d00277125484d15820 /crates/libsyntax2/src/grammar/attributes.rs
parent1193c5f829dc96683132c12d5395d7805787af2a (diff)
tt-attrs
Diffstat (limited to 'crates/libsyntax2/src/grammar/attributes.rs')
-rw-r--r--crates/libsyntax2/src/grammar/attributes.rs56
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
32fn 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
52fn 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}