aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 09:56:39 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 09:56:39 +0100
commitab0a96586fd54858106cb6ac112d61eb657426f6 (patch)
tree86bbf2601069f6b0007dc181c824ef706d08c60d /crates/ra_parser/src/grammar.rs
parentd55f1136d6444b1f50b9092c36a976d0e1c26202 (diff)
parenta6d51e09610989821aaf79871bcab0661c9b0f74 (diff)
Merge #1148
1148: Add token_tree_to_xxx functions r=matklad a=edwin0cheng <del>As discus in PR #1147 , this PR added a `mbe::MacroKind` . Currently only 2 kind of macro are supported, `SourceFile` and `Block`.</del> Added following functions for `tt::TokenTree` and `ast::Node` conversion: * token_tree_to_expr * token_tree_to_pat * token_tree_to_ty * token_tree_to_macro_stmts * token_tree_to_macro_items And added two new syntax kind: * MACRO_ITEMS * MACRO_STMTS Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar.rs')
-rw-r--r--crates/ra_parser/src/grammar.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index f8ed1299a..e1762633e 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,6 +87,11 @@ 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