diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index b2575bf..3205a08 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -641,6 +641,8 @@ pub enum InfixOp { MulAssign, SubAssign, DivAssign, + LeftShift, + RightShift, } impl From for InfixOp { @@ -671,6 +673,8 @@ impl From for InfixOp { TokenKind::AsteriskEqual => Self::MulAssign, TokenKind::MinusEquals => Self::SubAssign, TokenKind::SlashEquals => Self::DivAssign, + TokenKind::LeftShift => Self::LeftShift, + TokenKind::RightShift => Self::RightShift, _ => unreachable!(), } } diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index 8f2f01d..6018241 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -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("> 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();