From 5222b8aba3b1c2c68706aacf6869423a8e4fe6d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 15:47:32 +0300 Subject: move all parsing related bits to a separate module --- crates/ra_syntax/src/parsing/grammar/attributes.rs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 crates/ra_syntax/src/parsing/grammar/attributes.rs (limited to 'crates/ra_syntax/src/parsing/grammar/attributes.rs') diff --git a/crates/ra_syntax/src/parsing/grammar/attributes.rs b/crates/ra_syntax/src/parsing/grammar/attributes.rs new file mode 100644 index 000000000..cd30e8a45 --- /dev/null +++ b/crates/ra_syntax/src/parsing/grammar/attributes.rs @@ -0,0 +1,31 @@ +use super::*; + +pub(super) fn inner_attributes(p: &mut Parser) { + while p.current() == POUND && p.nth(1) == EXCL { + attribute(p, true) + } +} + +pub(super) fn outer_attributes(p: &mut Parser) { + while p.at(POUND) { + attribute(p, false) + } +} + +fn attribute(p: &mut Parser, inner: bool) { + let attr = p.start(); + assert!(p.at(POUND)); + p.bump(); + + if inner { + assert!(p.at(EXCL)); + p.bump(); + } + + if p.at(L_BRACK) { + items::token_tree(p); + } else { + p.error("expected `[`"); + } + attr.complete(p, ATTR); +} -- cgit v1.2.3