aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-31 08:25:27 +0000
committerAleksey Kladov <[email protected]>2019-01-31 20:23:30 +0000
commite28a5e048a9da3091897c86e48bc7d4fb2cf601c (patch)
tree6a6310560bf2d32207969b91c341def5c2e4c3c0 /crates
parent2980508ad2a04364f943af72c2c05337e03f4f6c (diff)
parsing scaffold
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/macros/mbe.rs49
1 files changed, 45 insertions, 4 deletions
diff --git a/crates/ra_hir/src/macros/mbe.rs b/crates/ra_hir/src/macros/mbe.rs
index 7af7066fb..2e7f9cbf4 100644
--- a/crates/ra_hir/src/macros/mbe.rs
+++ b/crates/ra_hir/src/macros/mbe.rs
@@ -9,8 +9,8 @@ pub(crate) struct MacroRules {
9 9
10#[derive(Debug)] 10#[derive(Debug)]
11struct Rule { 11struct Rule {
12 lhs: TokenTree, 12 lhs: Subtree,
13 rhs: TokenTree, 13 rhs: Subtree,
14} 14}
15 15
16#[derive(Debug)] 16#[derive(Debug)]
@@ -75,6 +75,47 @@ struct Var {
75 text: SmolStr, 75 text: SmolStr,
76} 76}
77 77
78pub(crate) fn parse(tt: &tt::Subtree) -> MacroRules { 78pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> {
79 MacroRules { rules: Vec::new() } 79 let mut parser = RulesParser::new(tt);
80 let mut rules = Vec::new();
81 while !parser.is_eof() {
82 rules.push(parse_rule(&mut parser)?)
83 }
84 Some(MacroRules { rules })
85}
86
87fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
88 let lhs = match p.current()? {
89 tt::TokenTree::Subtree(sub) => parse_subtree(sub)?,
90 _ => return None,
91 };
92 let rhs = unimplemented!();
93 Some(Rule { lhs, rhs })
94}
95
96fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
97 unimplemented!()
98}
99
100struct RulesParser<'a> {
101 subtree: &'a tt::Subtree,
102 pos: usize,
103}
104
105impl<'a> RulesParser<'a> {
106 fn new(subtree: &'a tt::Subtree) -> RulesParser<'a> {
107 RulesParser { subtree, pos: 0 }
108 }
109
110 fn is_eof(&self) -> bool {
111 self.pos == self.subtree.token_trees.len()
112 }
113
114 fn current(&self) -> Option<&'a tt::TokenTree> {
115 self.subtree.token_trees.get(self.pos)
116 }
117
118 fn bump(&mut self) {
119 self.pos += 1;
120 }
80} 121}