parser: roughly support inc/dec postfix ops

This commit is contained in:
Ryan Chandler 2022-08-09 11:33:19 +01:00
parent 983c6edbd3
commit e17d66e2d8
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 13 additions and 0 deletions

View File

@ -320,6 +320,12 @@ pub struct Use {
#[derive(Debug, PartialEq, Clone, Serialize)]
pub enum Expression {
Increment {
value: Box<Self>,
},
Decrement {
value: Box<Self>,
},
Int {
i: i64
},

View File

@ -1436,6 +1436,12 @@ impl Parser {
Expression::PropertyFetch { target: Box::new(lhs), property: property.into() }
}
},
TokenKind::Increment => {
Expression::Increment { value: Box::new(lhs) }
},
TokenKind::Decrement => {
Expression::Decrement { value: Box::new(lhs) }
},
_ => todo!("postfix: {:?}", op),
})
}
@ -1499,6 +1505,7 @@ fn infix_binding_power(t: &TokenKind) -> Option<(u8, u8)> {
fn postfix_binding_power(t: &TokenKind) -> Option<u8> {
Some(match t {
TokenKind::Increment | TokenKind::Decrement => 77,
TokenKind::LeftParen | TokenKind::LeftBracket => 19,
TokenKind::Arrow | TokenKind::DoubleColon => 18,
TokenKind::Coalesce => 11,