aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser/src/grammar.rs')
-rw-r--r--crates/ra_parser/src/grammar.rs59
1 files changed, 58 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index f8ed1299a..67eae749d 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -49,6 +49,27 @@ pub(crate) fn root(p: &mut Parser) {
49 m.complete(p, SOURCE_FILE); 49 m.complete(p, SOURCE_FILE);
50} 50}
51 51
52pub(crate) fn macro_items(p: &mut Parser) {
53 let m = p.start();
54 items::mod_contents(p, false);
55 m.complete(p, MACRO_ITEMS);
56}
57
58pub(crate) fn macro_stmts(p: &mut Parser) {
59 let m = p.start();
60
61 while !p.at(EOF) {
62 if p.current() == SEMI {
63 p.bump();
64 continue;
65 }
66
67 expressions::stmt(p, expressions::StmtWithSemi::Optional);
68 }
69
70 m.complete(p, MACRO_STMTS);
71}
72
52pub(crate) fn path(p: &mut Parser) { 73pub(crate) fn path(p: &mut Parser) {
53 paths::type_path(p); 74 paths::type_path(p);
54} 75}
@@ -66,9 +87,45 @@ pub(crate) fn pattern(p: &mut Parser) {
66} 87}
67 88
68pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { 89pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
90 let with_semi = match with_semi {
91 true => expressions::StmtWithSemi::Yes,
92 false => expressions::StmtWithSemi::No,
93 };
94
69 expressions::stmt(p, with_semi) 95 expressions::stmt(p, with_semi)
70} 96}
71 97
98pub(crate) fn block(p: &mut Parser) {
99 expressions::block(p);
100}
101
102// Parse a meta item , which excluded [], e.g : #[ MetaItem ]
103pub(crate) fn meta_item(p: &mut Parser) {
104 fn is_delimiter(p: &mut Parser) -> bool {
105 match p.current() {
106 L_CURLY | L_PAREN | L_BRACK => true,
107 _ => false,
108 }
109 }
110
111 if is_delimiter(p) {
112 items::token_tree(p);
113 return;
114 }
115
116 let m = p.start();
117 while !p.at(EOF) {
118 if is_delimiter(p) {
119 items::token_tree(p);
120 break;
121 } else {
122 p.bump();
123 }
124 }
125
126 m.complete(p, TOKEN_TREE);
127}
128
72pub(crate) fn item(p: &mut Parser) { 129pub(crate) fn item(p: &mut Parser) {
73 items::item_or_macro(p, true, items::ItemFlavor::Mod) 130 items::item_or_macro(p, true, items::ItemFlavor::Mod)
74} 131}
@@ -110,7 +167,7 @@ impl BlockLike {
110 } 167 }
111} 168}
112 169
113fn opt_visibility(p: &mut Parser) -> bool { 170pub(crate) fn opt_visibility(p: &mut Parser) -> bool {
114 match p.current() { 171 match p.current() {
115 PUB_KW => { 172 PUB_KW => {
116 let m = p.start(); 173 let m = p.start();