lexer: fix nullsafe arrow token skipping too many characters

This commit is contained in:
Ryan Chandler 2022-09-13 00:25:59 +01:00
parent 948c2cf561
commit 1e94b05ba6
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 8 additions and 1 deletions

View File

@ -237,7 +237,7 @@ impl Lexer {
TokenKind::QuestionColon
} else if self.try_read("->") {
self.col += 1;
self.skip(3);
self.skip(2);
TokenKind::NullsafeArrow
} else {
TokenKind::Question

View File

@ -3177,6 +3177,13 @@ mod tests {
);
}
#[test]
fn nullsafe_operator() {
assert_ast("<?php $a?->b;", &[
expr!(Expression::NullsafePropertyFetch { target: Box::new(Expression::Variable { name: "a".into() }), property: Box::new(Expression::Identifier { name: "b".into() }) })
]);
}
fn assert_ast(source: &str, expected: &[Statement]) {
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap();