mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
parsing scaffold
This commit is contained in:
parent
2980508ad2
commit
e28a5e048a
1 changed files with 45 additions and 4 deletions
|
@ -9,8 +9,8 @@ pub(crate) struct MacroRules {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct Rule {
|
||||
lhs: TokenTree,
|
||||
rhs: TokenTree,
|
||||
lhs: Subtree,
|
||||
rhs: Subtree,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -75,6 +75,47 @@ struct Var {
|
|||
text: SmolStr,
|
||||
}
|
||||
|
||||
pub(crate) fn parse(tt: &tt::Subtree) -> MacroRules {
|
||||
MacroRules { rules: Vec::new() }
|
||||
pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> {
|
||||
let mut parser = RulesParser::new(tt);
|
||||
let mut rules = Vec::new();
|
||||
while !parser.is_eof() {
|
||||
rules.push(parse_rule(&mut parser)?)
|
||||
}
|
||||
Some(MacroRules { rules })
|
||||
}
|
||||
|
||||
fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
|
||||
let lhs = match p.current()? {
|
||||
tt::TokenTree::Subtree(sub) => parse_subtree(sub)?,
|
||||
_ => return None,
|
||||
};
|
||||
let rhs = unimplemented!();
|
||||
Some(Rule { lhs, rhs })
|
||||
}
|
||||
|
||||
fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
struct RulesParser<'a> {
|
||||
subtree: &'a tt::Subtree,
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl<'a> RulesParser<'a> {
|
||||
fn new(subtree: &'a tt::Subtree) -> RulesParser<'a> {
|
||||
RulesParser { subtree, pos: 0 }
|
||||
}
|
||||
|
||||
fn is_eof(&self) -> bool {
|
||||
self.pos == self.subtree.token_trees.len()
|
||||
}
|
||||
|
||||
fn current(&self) -> Option<&'a tt::TokenTree> {
|
||||
self.subtree.token_trees.get(self.pos)
|
||||
}
|
||||
|
||||
fn bump(&mut self) {
|
||||
self.pos += 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue