mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Split parse and expand errors
This commit is contained in:
parent
dffe318701
commit
725805dc79
4 changed files with 76 additions and 74 deletions
|
@ -25,14 +25,17 @@ use ra_syntax::SmolStr;
|
||||||
pub use tt::{Delimiter, Punct};
|
pub use tt::{Delimiter, Punct};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum MacroRulesError {
|
pub enum ParseError {
|
||||||
NoMatchingRule,
|
|
||||||
UnexpectedToken,
|
|
||||||
BindingError(String),
|
|
||||||
ParseError,
|
ParseError,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, MacroRulesError>;
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub enum ExpandError {
|
||||||
|
NoMatchingRule,
|
||||||
|
UnexpectedToken,
|
||||||
|
BindingError(String),
|
||||||
|
}
|
||||||
|
|
||||||
pub use crate::syntax_bridge::{ast_to_token_tree, token_tree_to_ast_item_list};
|
pub use crate::syntax_bridge::{ast_to_token_tree, token_tree_to_ast_item_list};
|
||||||
|
|
||||||
/// This struct contains AST for a single `macro_rules` definition. What might
|
/// This struct contains AST for a single `macro_rules` definition. What might
|
||||||
|
@ -45,10 +48,10 @@ pub struct MacroRules {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroRules {
|
impl MacroRules {
|
||||||
pub fn parse(tt: &tt::Subtree) -> Result<MacroRules> {
|
pub fn parse(tt: &tt::Subtree) -> Result<MacroRules, ParseError> {
|
||||||
mbe_parser::parse(tt)
|
mbe_parser::parse(tt)
|
||||||
}
|
}
|
||||||
pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree> {
|
pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree, ExpandError> {
|
||||||
mbe_expander::expand(self, tt)
|
mbe_expander::expand(self, tt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,22 +5,21 @@ use rustc_hash::FxHashMap;
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
use tt::TokenId;
|
use tt::TokenId;
|
||||||
|
|
||||||
use crate::{MacroRulesError, Result};
|
use crate::ExpandError;
|
||||||
use crate::tt_cursor::TtCursor;
|
use crate::tt_cursor::TtCursor;
|
||||||
|
|
||||||
pub(crate) fn expand(rules: &crate::MacroRules, input: &tt::Subtree) -> Result<tt::Subtree> {
|
pub(crate) fn expand(
|
||||||
rules
|
rules: &crate::MacroRules,
|
||||||
.rules
|
input: &tt::Subtree,
|
||||||
.iter()
|
) -> Result<tt::Subtree, ExpandError> {
|
||||||
.find_map(|it| expand_rule(it, input).ok())
|
rules.rules.iter().find_map(|it| expand_rule(it, input).ok()).ok_or(ExpandError::NoMatchingRule)
|
||||||
.ok_or(MacroRulesError::NoMatchingRule)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_rule(rule: &crate::Rule, input: &tt::Subtree) -> Result<tt::Subtree> {
|
fn expand_rule(rule: &crate::Rule, input: &tt::Subtree) -> Result<tt::Subtree, ExpandError> {
|
||||||
let mut input = TtCursor::new(input);
|
let mut input = TtCursor::new(input);
|
||||||
let bindings = match_lhs(&rule.lhs, &mut input)?;
|
let bindings = match_lhs(&rule.lhs, &mut input)?;
|
||||||
if !input.is_eof() {
|
if !input.is_eof() {
|
||||||
return Err(MacroRulesError::UnexpectedToken);
|
return Err(ExpandError::UnexpectedToken);
|
||||||
}
|
}
|
||||||
expand_subtree(&rule.rhs, &bindings, &mut Vec::new())
|
expand_subtree(&rule.rhs, &bindings, &mut Vec::new())
|
||||||
}
|
}
|
||||||
|
@ -82,29 +81,30 @@ enum Binding {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bindings {
|
impl Bindings {
|
||||||
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree> {
|
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> {
|
||||||
let mut b = self
|
let mut b = self
|
||||||
.inner
|
.inner
|
||||||
.get(name)
|
.get(name)
|
||||||
.ok_or(MacroRulesError::BindingError(format!("could not find binding {}", name)))?;
|
.ok_or(ExpandError::BindingError(format!("could not find binding {}", name)))?;
|
||||||
for &idx in nesting.iter() {
|
for &idx in nesting.iter() {
|
||||||
b = match b {
|
b = match b {
|
||||||
Binding::Simple(_) => break,
|
Binding::Simple(_) => break,
|
||||||
Binding::Nested(bs) => bs.get(idx).ok_or(MacroRulesError::BindingError(
|
Binding::Nested(bs) => bs.get(idx).ok_or(ExpandError::BindingError(format!(
|
||||||
format!("could not find nested binding {}", name),
|
"could not find nested binding {}",
|
||||||
))?,
|
name
|
||||||
|
)))?,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
match b {
|
match b {
|
||||||
Binding::Simple(it) => Ok(it),
|
Binding::Simple(it) => Ok(it),
|
||||||
Binding::Nested(_) => Err(MacroRulesError::BindingError(format!(
|
Binding::Nested(_) => Err(ExpandError::BindingError(format!(
|
||||||
"expected simple binding, found nested binding {}",
|
"expected simple binding, found nested binding {}",
|
||||||
name
|
name
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_nested(&mut self, nested: Bindings) -> Result<()> {
|
fn push_nested(&mut self, nested: Bindings) -> Result<(), ExpandError> {
|
||||||
for (key, value) in nested.inner {
|
for (key, value) in nested.inner {
|
||||||
if !self.inner.contains_key(&key) {
|
if !self.inner.contains_key(&key) {
|
||||||
self.inner.insert(key.clone(), Binding::Nested(Vec::new()));
|
self.inner.insert(key.clone(), Binding::Nested(Vec::new()));
|
||||||
|
@ -112,10 +112,10 @@ impl Bindings {
|
||||||
match self.inner.get_mut(&key) {
|
match self.inner.get_mut(&key) {
|
||||||
Some(Binding::Nested(it)) => it.push(value),
|
Some(Binding::Nested(it)) => it.push(value),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(MacroRulesError::BindingError(format!(
|
return Err(ExpandError::BindingError(format!(
|
||||||
"nested binding for {} not found",
|
"nested binding for {} not found",
|
||||||
key
|
key
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,43 +123,44 @@ impl Bindings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings> {
|
fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, ExpandError> {
|
||||||
let mut res = Bindings::default();
|
let mut res = Bindings::default();
|
||||||
for pat in pattern.token_trees.iter() {
|
for pat in pattern.token_trees.iter() {
|
||||||
match pat {
|
match pat {
|
||||||
crate::TokenTree::Leaf(leaf) => match leaf {
|
crate::TokenTree::Leaf(leaf) => match leaf {
|
||||||
crate::Leaf::Var(crate::Var { text, kind }) => {
|
crate::Leaf::Var(crate::Var { text, kind }) => {
|
||||||
let kind = kind.clone().ok_or(MacroRulesError::ParseError)?;
|
let kind = kind.clone().ok_or(ExpandError::UnexpectedToken)?;
|
||||||
match kind.as_str() {
|
match kind.as_str() {
|
||||||
"ident" => {
|
"ident" => {
|
||||||
let ident = input.eat_ident()?.clone();
|
let ident =
|
||||||
|
input.eat_ident().ok_or(ExpandError::UnexpectedToken)?.clone();
|
||||||
res.inner.insert(
|
res.inner.insert(
|
||||||
text.clone(),
|
text.clone(),
|
||||||
Binding::Simple(tt::Leaf::from(ident).into()),
|
Binding::Simple(tt::Leaf::from(ident).into()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => return Err(MacroRulesError::UnexpectedToken),
|
_ => return Err(ExpandError::UnexpectedToken),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crate::Leaf::Punct(punct) => {
|
crate::Leaf::Punct(punct) => {
|
||||||
if input.eat_punct()? != punct {
|
if input.eat_punct() != Some(punct) {
|
||||||
return Err(MacroRulesError::UnexpectedToken);
|
return Err(ExpandError::UnexpectedToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crate::Leaf::Ident(ident) => {
|
crate::Leaf::Ident(ident) => {
|
||||||
if input.eat_ident()?.text != ident.text {
|
if input.eat_ident().map(|i| &i.text) != Some(&ident.text) {
|
||||||
return Err(MacroRulesError::UnexpectedToken);
|
return Err(ExpandError::UnexpectedToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(MacroRulesError::UnexpectedToken),
|
_ => return Err(ExpandError::UnexpectedToken),
|
||||||
},
|
},
|
||||||
crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => {
|
crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => {
|
||||||
while let Ok(nested) = match_lhs(subtree, input) {
|
while let Ok(nested) = match_lhs(subtree, input) {
|
||||||
res.push_nested(nested)?;
|
res.push_nested(nested)?;
|
||||||
if let Some(separator) = *separator {
|
if let Some(separator) = *separator {
|
||||||
if !input.is_eof() {
|
if !input.is_eof() {
|
||||||
if input.eat_punct()?.char != separator {
|
if input.eat_punct().map(|p| p.char) != Some(separator) {
|
||||||
return Err(MacroRulesError::UnexpectedToken);
|
return Err(ExpandError::UnexpectedToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,12 +176,12 @@ fn expand_subtree(
|
||||||
template: &crate::Subtree,
|
template: &crate::Subtree,
|
||||||
bindings: &Bindings,
|
bindings: &Bindings,
|
||||||
nesting: &mut Vec<usize>,
|
nesting: &mut Vec<usize>,
|
||||||
) -> Result<tt::Subtree> {
|
) -> Result<tt::Subtree, ExpandError> {
|
||||||
let token_trees = template
|
let token_trees = template
|
||||||
.token_trees
|
.token_trees
|
||||||
.iter()
|
.iter()
|
||||||
.map(|it| expand_tt(it, bindings, nesting))
|
.map(|it| expand_tt(it, bindings, nesting))
|
||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>, ExpandError>>()?;
|
||||||
|
|
||||||
Ok(tt::Subtree { token_trees, delimiter: template.delimiter })
|
Ok(tt::Subtree { token_trees, delimiter: template.delimiter })
|
||||||
}
|
}
|
||||||
|
@ -189,7 +190,7 @@ fn expand_tt(
|
||||||
template: &crate::TokenTree,
|
template: &crate::TokenTree,
|
||||||
bindings: &Bindings,
|
bindings: &Bindings,
|
||||||
nesting: &mut Vec<usize>,
|
nesting: &mut Vec<usize>,
|
||||||
) -> Result<tt::TokenTree> {
|
) -> Result<tt::TokenTree, ExpandError> {
|
||||||
let res: tt::TokenTree = match template {
|
let res: tt::TokenTree = match template {
|
||||||
crate::TokenTree::Subtree(subtree) => expand_subtree(subtree, bindings, nesting)?.into(),
|
crate::TokenTree::Subtree(subtree) => expand_subtree(subtree, bindings, nesting)?.into(),
|
||||||
crate::TokenTree::Repeat(repeat) => {
|
crate::TokenTree::Repeat(repeat) => {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/// This module parses a raw `tt::TokenStream` into macro-by-example token
|
/// This module parses a raw `tt::TokenStream` into macro-by-example token
|
||||||
/// stream. This is a *mostly* identify function, expect for handling of
|
/// stream. This is a *mostly* identify function, expect for handling of
|
||||||
/// `$var:tt_kind` and `$(repeat),*` constructs.
|
/// `$var:tt_kind` and `$(repeat),*` constructs.
|
||||||
use crate::{MacroRulesError, Result};
|
use crate::ParseError;
|
||||||
use crate::tt_cursor::TtCursor;
|
use crate::tt_cursor::TtCursor;
|
||||||
|
|
||||||
pub(crate) fn parse(tt: &tt::Subtree) -> Result<crate::MacroRules> {
|
pub(crate) fn parse(tt: &tt::Subtree) -> Result<crate::MacroRules, ParseError> {
|
||||||
let mut parser = TtCursor::new(tt);
|
let mut parser = TtCursor::new(tt);
|
||||||
let mut rules = Vec::new();
|
let mut rules = Vec::new();
|
||||||
while !parser.is_eof() {
|
while !parser.is_eof() {
|
||||||
|
@ -19,7 +19,7 @@ pub(crate) fn parse(tt: &tt::Subtree) -> Result<crate::MacroRules> {
|
||||||
Ok(crate::MacroRules { rules })
|
Ok(crate::MacroRules { rules })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rule(p: &mut TtCursor) -> Result<crate::Rule> {
|
fn parse_rule(p: &mut TtCursor) -> Result<crate::Rule, ParseError> {
|
||||||
let lhs = parse_subtree(p.eat_subtree()?)?;
|
let lhs = parse_subtree(p.eat_subtree()?)?;
|
||||||
p.expect_char('=')?;
|
p.expect_char('=')?;
|
||||||
p.expect_char('>')?;
|
p.expect_char('>')?;
|
||||||
|
@ -28,14 +28,14 @@ fn parse_rule(p: &mut TtCursor) -> Result<crate::Rule> {
|
||||||
Ok(crate::Rule { lhs, rhs })
|
Ok(crate::Rule { lhs, rhs })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_subtree(tt: &tt::Subtree) -> Result<crate::Subtree> {
|
fn parse_subtree(tt: &tt::Subtree) -> Result<crate::Subtree, ParseError> {
|
||||||
let mut token_trees = Vec::new();
|
let mut token_trees = Vec::new();
|
||||||
let mut p = TtCursor::new(tt);
|
let mut p = TtCursor::new(tt);
|
||||||
while let Ok(tt) = p.eat() {
|
while let Some(tt) = p.eat() {
|
||||||
let child: crate::TokenTree = match tt {
|
let child: crate::TokenTree = match tt {
|
||||||
tt::TokenTree::Leaf(leaf) => match leaf {
|
tt::TokenTree::Leaf(leaf) => match leaf {
|
||||||
tt::Leaf::Punct(tt::Punct { char: '$', .. }) => {
|
tt::Leaf::Punct(tt::Punct { char: '$', .. }) => {
|
||||||
if p.at_ident().is_ok() {
|
if p.at_ident().is_some() {
|
||||||
crate::Leaf::from(parse_var(&mut p)?).into()
|
crate::Leaf::from(parse_var(&mut p)?).into()
|
||||||
} else {
|
} else {
|
||||||
parse_repeat(&mut p)?.into()
|
parse_repeat(&mut p)?.into()
|
||||||
|
@ -56,12 +56,12 @@ fn parse_subtree(tt: &tt::Subtree) -> Result<crate::Subtree> {
|
||||||
Ok(crate::Subtree { token_trees, delimiter: tt.delimiter })
|
Ok(crate::Subtree { token_trees, delimiter: tt.delimiter })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_var(p: &mut TtCursor) -> Result<crate::Var> {
|
fn parse_var(p: &mut TtCursor) -> Result<crate::Var, ParseError> {
|
||||||
let ident = p.eat_ident().unwrap();
|
let ident = p.eat_ident().unwrap();
|
||||||
let text = ident.text.clone();
|
let text = ident.text.clone();
|
||||||
let kind = if p.at_char(':') {
|
let kind = if p.at_char(':') {
|
||||||
p.bump();
|
p.bump();
|
||||||
if let Ok(ident) = p.eat_ident() {
|
if let Some(ident) = p.eat_ident() {
|
||||||
Some(ident.text.clone())
|
Some(ident.text.clone())
|
||||||
} else {
|
} else {
|
||||||
p.rev_bump();
|
p.rev_bump();
|
||||||
|
@ -73,21 +73,21 @@ fn parse_var(p: &mut TtCursor) -> Result<crate::Var> {
|
||||||
Ok(crate::Var { text, kind })
|
Ok(crate::Var { text, kind })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_repeat(p: &mut TtCursor) -> Result<crate::Repeat> {
|
fn parse_repeat(p: &mut TtCursor) -> Result<crate::Repeat, ParseError> {
|
||||||
let subtree = p.eat_subtree().unwrap();
|
let subtree = p.eat_subtree().unwrap();
|
||||||
let mut subtree = parse_subtree(subtree)?;
|
let mut subtree = parse_subtree(subtree)?;
|
||||||
subtree.delimiter = crate::Delimiter::None;
|
subtree.delimiter = crate::Delimiter::None;
|
||||||
let sep = p.eat_punct()?;
|
let sep = p.eat_punct().ok_or(ParseError::ParseError)?;
|
||||||
let (separator, rep) = match sep.char {
|
let (separator, rep) = match sep.char {
|
||||||
'*' | '+' | '?' => (None, sep.char),
|
'*' | '+' | '?' => (None, sep.char),
|
||||||
char => (Some(char), p.eat_punct()?.char),
|
char => (Some(char), p.eat_punct().ok_or(ParseError::ParseError)?.char),
|
||||||
};
|
};
|
||||||
|
|
||||||
let kind = match rep {
|
let kind = match rep {
|
||||||
'*' => crate::RepeatKind::ZeroOrMore,
|
'*' => crate::RepeatKind::ZeroOrMore,
|
||||||
'+' => crate::RepeatKind::OneOrMore,
|
'+' => crate::RepeatKind::OneOrMore,
|
||||||
'?' => crate::RepeatKind::ZeroOrOne,
|
'?' => crate::RepeatKind::ZeroOrOne,
|
||||||
_ => return Err(MacroRulesError::ParseError),
|
_ => return Err(ParseError::ParseError),
|
||||||
};
|
};
|
||||||
p.bump();
|
p.bump();
|
||||||
Ok(crate::Repeat { subtree, kind, separator })
|
Ok(crate::Repeat { subtree, kind, separator })
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{MacroRulesError, Result};
|
use crate::ParseError;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct TtCursor<'a> {
|
pub(crate) struct TtCursor<'a> {
|
||||||
|
@ -19,24 +19,24 @@ impl<'a> TtCursor<'a> {
|
||||||
self.subtree.token_trees.get(self.pos)
|
self.subtree.token_trees.get(self.pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn at_punct(&self) -> Result<&'a tt::Punct> {
|
pub(crate) fn at_punct(&self) -> Option<&'a tt::Punct> {
|
||||||
match self.current() {
|
match self.current() {
|
||||||
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(it))) => Ok(it),
|
Some(tt::TokenTree::Leaf(tt::Leaf::Punct(it))) => Some(it),
|
||||||
_ => Err(MacroRulesError::ParseError),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn at_char(&self, char: char) -> bool {
|
pub(crate) fn at_char(&self, char: char) -> bool {
|
||||||
match self.at_punct() {
|
match self.at_punct() {
|
||||||
Ok(tt::Punct { char: c, .. }) if *c == char => true,
|
Some(tt::Punct { char: c, .. }) if *c == char => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn at_ident(&mut self) -> Result<&'a tt::Ident> {
|
pub(crate) fn at_ident(&mut self) -> Option<&'a tt::Ident> {
|
||||||
match self.current() {
|
match self.current() {
|
||||||
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(i))) => Ok(i),
|
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(i))) => Some(i),
|
||||||
_ => Err(MacroRulesError::ParseError),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,45 +47,43 @@ impl<'a> TtCursor<'a> {
|
||||||
self.pos -= 1;
|
self.pos -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat(&mut self) -> Result<&'a tt::TokenTree> {
|
pub(crate) fn eat(&mut self) -> Option<&'a tt::TokenTree> {
|
||||||
match self.current() {
|
self.current().map(|it| {
|
||||||
Some(it) => {
|
|
||||||
self.bump();
|
self.bump();
|
||||||
Ok(it)
|
it
|
||||||
}
|
})
|
||||||
None => Err(MacroRulesError::ParseError),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_subtree(&mut self) -> Result<&'a tt::Subtree> {
|
pub(crate) fn eat_subtree(&mut self) -> Result<&'a tt::Subtree, ParseError> {
|
||||||
match self.current() {
|
match self.current() {
|
||||||
Some(tt::TokenTree::Subtree(sub)) => {
|
Some(tt::TokenTree::Subtree(sub)) => {
|
||||||
self.bump();
|
self.bump();
|
||||||
Ok(sub)
|
Ok(sub)
|
||||||
}
|
}
|
||||||
_ => Err(MacroRulesError::ParseError),
|
_ => Err(ParseError::ParseError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_punct(&mut self) -> Result<&'a tt::Punct> {
|
pub(crate) fn eat_punct(&mut self) -> Option<&'a tt::Punct> {
|
||||||
self.at_punct().map(|it| {
|
self.at_punct().map(|it| {
|
||||||
self.bump();
|
self.bump();
|
||||||
it
|
it
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_ident(&mut self) -> Result<&'a tt::Ident> {
|
pub(crate) fn eat_ident(&mut self) -> Option<&'a tt::Ident> {
|
||||||
self.at_ident().map(|i| {
|
self.at_ident().map(|i| {
|
||||||
self.bump();
|
self.bump();
|
||||||
i
|
i
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn expect_char(&mut self, char: char) -> Result<()> {
|
pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> {
|
||||||
if self.at_char(char) {
|
if self.at_char(char) {
|
||||||
self.bump();
|
self.bump();
|
||||||
return Ok(());
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ParseError::ParseError)
|
||||||
}
|
}
|
||||||
Err(MacroRulesError::ParseError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue