mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
parser: support left and right shift op
This commit is contained in:
parent
fb8ebd2484
commit
274fc7c0d6
@ -641,6 +641,8 @@ pub enum InfixOp {
|
||||
MulAssign,
|
||||
SubAssign,
|
||||
DivAssign,
|
||||
LeftShift,
|
||||
RightShift,
|
||||
}
|
||||
|
||||
impl From<TokenKind> for InfixOp {
|
||||
@ -671,6 +673,8 @@ impl From<TokenKind> for InfixOp {
|
||||
TokenKind::AsteriskEqual => Self::MulAssign,
|
||||
TokenKind::MinusEquals => Self::SubAssign,
|
||||
TokenKind::SlashEquals => Self::DivAssign,
|
||||
TokenKind::LeftShift => Self::LeftShift,
|
||||
TokenKind::RightShift => Self::RightShift,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -2257,6 +2257,8 @@ fn is_infix(t: &TokenKind) -> bool {
|
||||
matches!(
|
||||
t,
|
||||
TokenKind::Pow
|
||||
| TokenKind::LeftShift
|
||||
| TokenKind::RightShift
|
||||
| TokenKind::Percent
|
||||
| TokenKind::Instanceof
|
||||
| TokenKind::Asterisk
|
||||
@ -4364,6 +4366,20 @@ mod tests {
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn left_shift() {
|
||||
assert_ast("<?php 6 << 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::LeftShift, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_shift() {
|
||||
assert_ast("<?php 6 >> 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::RightShift, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
}
|
||||
|
||||
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