mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
parser: support unary plus op
This commit is contained in:
parent
37029e4e41
commit
b6f61bb344
@ -562,6 +562,9 @@ pub enum Expression {
|
||||
Negate {
|
||||
value: Box<Expression>,
|
||||
},
|
||||
UnaryPlus {
|
||||
value: Box<Expression>,
|
||||
},
|
||||
Cast {
|
||||
kind: CastKind,
|
||||
value: Box<Self>,
|
||||
|
@ -2179,6 +2179,7 @@ fn is_prefix(op: &TokenKind) -> bool {
|
||||
op,
|
||||
TokenKind::Bang
|
||||
| TokenKind::Minus
|
||||
| TokenKind::Plus
|
||||
| TokenKind::StringCast
|
||||
| TokenKind::BinaryCast
|
||||
| TokenKind::ObjectCast
|
||||
@ -2203,6 +2204,7 @@ fn prefix(op: &TokenKind, rhs: Expression) -> Expression {
|
||||
TokenKind::Minus => Expression::Negate {
|
||||
value: Box::new(rhs),
|
||||
},
|
||||
TokenKind::Plus => Expression::UnaryPlus { value: Box::new(rhs) },
|
||||
TokenKind::StringCast
|
||||
| TokenKind::BinaryCast
|
||||
| TokenKind::ObjectCast
|
||||
@ -4286,6 +4288,13 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unary_plus() {
|
||||
assert_ast("<?php +1;", &[
|
||||
expr!(Expression::UnaryPlus { value: Box::new(Expression::Int { i: 1 }) })
|
||||
]);
|
||||
}
|
||||
|
||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||
let mut lexer = Lexer::new(None);
|
||||
let tokens = lexer.tokenize(source).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user