parse 'tag' expressions
This commit is contained in:
parent
35ada4a21d
commit
f0235832c3
|
@ -32,11 +32,6 @@ impl Token<'_> {
|
|||
pub fn is_def_attr(&self) -> bool {
|
||||
matches!(self, Token::Final)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_cobj_attr(&self) -> bool {
|
||||
matches!(self, Token::CtrlFlowEdit)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
|
|
|
@ -50,10 +50,7 @@ pub enum Expression {
|
|||
obj: Box<Expression>,
|
||||
args: BTreeMap<Box<[Atom]>, (Location, Expression)>,
|
||||
},
|
||||
Tag {
|
||||
obj: Box<Expression>,
|
||||
args: BTreeMap<Box<[Atom]>, (Location, Expression)>,
|
||||
},
|
||||
Tag(Path),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -79,6 +76,7 @@ pub enum ErrorKind {
|
|||
UnexpectedTrail,
|
||||
InvalidIdentifier,
|
||||
DuplicateIdentifier,
|
||||
InvalidCombination(&'static str),
|
||||
Unexpected(&'static str),
|
||||
Unknown,
|
||||
}
|
||||
|
@ -183,16 +181,33 @@ impl FullIdentifier {
|
|||
|
||||
impl Expression {
|
||||
fn parse_high(ctx: &mut ParserContext<'_>) -> Result<Self, Error> {
|
||||
let mut cfe = false;
|
||||
for (_, i) in ctx.pklx.peeking_take_while(|(_, t)| t.is_cobj_attr()) {
|
||||
let (mut cfe, mut tag) = (false, false);
|
||||
let preloc = ctx.peek_loc();
|
||||
for (_, i) in ctx
|
||||
.pklx
|
||||
.peeking_take_while(|(_, t)| matches!(Token::CtrlFlowEdit | Token::Tag))
|
||||
{
|
||||
match i {
|
||||
Token::CtrlFlowEdit => cfe = true,
|
||||
Token::Tag => tag = true,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
if cfe && tag {
|
||||
return Err(Error {
|
||||
loc: preloc,
|
||||
kind: ErrorKind::InvalidCombination(
|
||||
"you can't specify both cfe and tag at the same time",
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
let obj = match ctx.pklx.peek() {
|
||||
None => Err(ctx.make_eof()),
|
||||
Some((_, Token::Identifier(ident))) if tag => {
|
||||
Path::parse_high(ctx).map(Expression::Tag)
|
||||
}
|
||||
Some((_, Token::OpenBrace)) => {
|
||||
ctx.pklx.next();
|
||||
let mut codata = Vec::new();
|
||||
|
@ -220,6 +235,10 @@ impl Expression {
|
|||
}
|
||||
})
|
||||
}
|
||||
Some(&(loc, _)) if tag => Err(Error {
|
||||
loc,
|
||||
kind: ErrorKind::Unexpected("identifier"),
|
||||
}),
|
||||
Some(&(loc, _)) if cfe => Err(Error {
|
||||
loc,
|
||||
kind: ErrorKind::Unexpected("braced statement set"),
|
||||
|
|
Loading…
Reference in a new issue