aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar
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
parent1193c5f829dc96683132c12d5395d7805787af2a (diff)
tt-attrs
Diffstat (limited to 'crates/libsyntax2/src/grammar')
-rw-r--r--crates/libsyntax2/src/grammar/attributes.rs56
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs7
2 files changed, 7 insertions, 56 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}
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs
index fc02f0c5c..84cb47748 100644
--- a/crates/libsyntax2/src/grammar/items/mod.rs
+++ b/crates/libsyntax2/src/grammar/items/mod.rs
@@ -55,9 +55,6 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
55 } 55 }
56} 56}
57 57
58pub(super) const ITEM_FIRST: TokenSet =
59 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND];
60
61pub(super) enum MaybeItem { 58pub(super) enum MaybeItem {
62 None, 59 None,
63 Item(SyntaxKind), 60 Item(SyntaxKind),
@@ -322,13 +319,14 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
322 flavor 319 flavor
323} 320}
324 321
325fn token_tree(p: &mut Parser) { 322pub(super) fn token_tree(p: &mut Parser) {
326 let closing_paren_kind = match p.current() { 323 let closing_paren_kind = match p.current() {
327 L_CURLY => R_CURLY, 324 L_CURLY => R_CURLY,
328 L_PAREN => R_PAREN, 325 L_PAREN => R_PAREN,
329 L_BRACK => R_BRACK, 326 L_BRACK => R_BRACK,
330 _ => unreachable!(), 327 _ => unreachable!(),
331 }; 328 };
329 let m = p.start();
332 p.bump(); 330 p.bump();
333 while !p.at(EOF) && !p.at(closing_paren_kind) { 331 while !p.at(EOF) && !p.at(closing_paren_kind) {
334 match p.current() { 332 match p.current() {
@@ -338,4 +336,5 @@ fn token_tree(p: &mut Parser) {
338 } 336 }
339 }; 337 };
340 p.expect(closing_paren_kind); 338 p.expect(closing_paren_kind);
339 m.complete(p, TOKEN_TREE);
341} 340}