parser: support nullsafe property fetch

This commit is contained in:
Ryan Chandler 2022-08-09 21:27:07 +01:00
parent 489cb0e884
commit 874e59d270
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 11 additions and 3 deletions

View File

@ -380,6 +380,10 @@ pub enum Expression {
target: Box<Self>,
property: Box<Self>,
},
NullsafePropertyFetch {
target: Box<Self>,
property: Box<Self>,
},
StaticPropertyFetch {
target: Box<Self>,
property: Box<Self>

View File

@ -1493,7 +1493,7 @@ impl Parser {
},
}
},
TokenKind::Arrow => {
TokenKind::Arrow | TokenKind::NullsafeArrow => {
let property = match self.current.kind {
TokenKind::LeftBrace => {
self.lbrace()?;
@ -1536,7 +1536,11 @@ impl Parser {
Expression::MethodCall { target: Box::new(lhs), method: Box::new(property), args }
} else {
Expression::PropertyFetch { target: Box::new(lhs), property: Box::new(property) }
if op == &TokenKind::NullsafeArrow {
Expression::NullsafePropertyFetch { target: Box::new(lhs), property: Box::new(property) }
} else {
Expression::PropertyFetch { target: Box::new(lhs), property: Box::new(property) }
}
}
},
TokenKind::Increment => {
@ -1610,7 +1614,7 @@ 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::Arrow | TokenKind::NullsafeArrow | TokenKind::DoubleColon => 18,
TokenKind::Coalesce => 11,
_ => return None
})