mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: support add assign operator
This commit is contained in:
parent
67a26ae78f
commit
22d8cc332c
@ -597,7 +597,16 @@ impl Lexer {
|
||||
},
|
||||
'+' => {
|
||||
self.col += 1;
|
||||
TokenKind::Plus
|
||||
|
||||
if let Some('=') = it.peek() {
|
||||
self.col += 1;
|
||||
|
||||
it.next();
|
||||
|
||||
TokenKind::PlusEquals
|
||||
} else {
|
||||
TokenKind::Plus
|
||||
}
|
||||
},
|
||||
'-' => {
|
||||
self.col += 1;
|
||||
|
@ -102,6 +102,7 @@ pub enum TokenKind {
|
||||
Percent,
|
||||
Pipe,
|
||||
Plus,
|
||||
PlusEquals,
|
||||
Pow,
|
||||
Private,
|
||||
Protected,
|
||||
@ -232,6 +233,7 @@ impl Display for TokenKind {
|
||||
Self::Percent => "%",
|
||||
Self::Pipe => "|",
|
||||
Self::Plus => "+",
|
||||
Self::PlusEquals => "+=",
|
||||
Self::Pow => "**",
|
||||
Self::Private => "private",
|
||||
Self::Protected => "protected",
|
||||
|
@ -313,6 +313,7 @@ pub enum InfixOp {
|
||||
NotIdentical,
|
||||
And,
|
||||
Or,
|
||||
AddAssign,
|
||||
}
|
||||
|
||||
impl From<TokenKind> for InfixOp {
|
||||
@ -331,6 +332,7 @@ impl From<TokenKind> for InfixOp {
|
||||
TokenKind::BangDoubleEquals => Self::NotIdentical,
|
||||
TokenKind::BooleanAnd => Self::And,
|
||||
TokenKind::BooleanOr => Self::Or,
|
||||
TokenKind::PlusEquals => Self::AddAssign,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
@ -723,8 +723,6 @@ impl Parser {
|
||||
|
||||
let target = self.expression(0)?;
|
||||
|
||||
dbg!(&self.current.kind);
|
||||
|
||||
Expression::Clone(Box::new(target))
|
||||
},
|
||||
TokenKind::Variable(v) => {
|
||||
@ -1217,7 +1215,7 @@ fn infix_binding_power(t: &TokenKind) -> Option<(u8, u8)> {
|
||||
TokenKind::DoubleEquals | TokenKind::TripleEquals | TokenKind::BangEquals | TokenKind::BangDoubleEquals => (7, 8),
|
||||
TokenKind::BooleanAnd => (5, 6),
|
||||
TokenKind::BooleanOr => (3, 4),
|
||||
TokenKind::Equals => (2, 1),
|
||||
TokenKind::Equals | TokenKind::PlusEquals => (2, 1),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user