mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
parser/lexer: support <> op
This commit is contained in:
parent
d99d931107
commit
a7d74e6b2d
@ -492,6 +492,10 @@ impl Lexer {
|
||||
self.skip(2);
|
||||
TokenKind::LessThanEquals
|
||||
}
|
||||
[b'<', b'>', ..] => {
|
||||
self.skip(2);
|
||||
TokenKind::AngledLeftRight
|
||||
},
|
||||
[b'<', ..] => {
|
||||
self.next();
|
||||
TokenKind::LessThan
|
||||
|
@ -30,6 +30,7 @@ pub enum TokenKind {
|
||||
Attribute,
|
||||
Bang,
|
||||
BangEquals,
|
||||
AngledLeftRight,
|
||||
BangDoubleEquals,
|
||||
BoolCast,
|
||||
BooleanCast,
|
||||
|
@ -664,7 +664,7 @@ impl From<TokenKind> for InfixOp {
|
||||
TokenKind::DotEquals => Self::ConcatAssign,
|
||||
TokenKind::DoubleEquals => Self::Equals,
|
||||
TokenKind::TripleEquals => Self::Identical,
|
||||
TokenKind::BangEquals => Self::NotEquals,
|
||||
TokenKind::BangEquals | TokenKind::AngledLeftRight => Self::NotEquals,
|
||||
TokenKind::BangDoubleEquals => Self::NotIdentical,
|
||||
TokenKind::BooleanAnd => Self::And,
|
||||
TokenKind::BooleanOr => Self::Or,
|
||||
|
@ -2277,6 +2277,7 @@ fn is_infix(t: &TokenKind) -> bool {
|
||||
| TokenKind::TripleEquals
|
||||
| TokenKind::BangEquals
|
||||
| TokenKind::BangDoubleEquals
|
||||
| TokenKind::AngledLeftRight
|
||||
| TokenKind::Question
|
||||
| TokenKind::QuestionColon
|
||||
| TokenKind::BooleanAnd
|
||||
@ -4404,6 +4405,13 @@ mod tests {
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn angled_not_equal() {
|
||||
assert_ast("<?php 6 <> 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::NotEquals, 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();
|
||||
|
@ -56,7 +56,7 @@ impl Precedence {
|
||||
LeftShift | RightShift => Self::BitShift,
|
||||
Dot => Self::Concat,
|
||||
LessThan | LessThanEquals | GreaterThan | GreaterThanEquals => Self::LtGt,
|
||||
DoubleEquals | BangEquals | TripleEquals | BangDoubleEquals => Self::Equality,
|
||||
DoubleEquals | BangEquals | TripleEquals | BangDoubleEquals | AngledLeftRight => Self::Equality,
|
||||
Ampersand => Self::BitwiseAnd,
|
||||
Caret => Self::BitwiseXor,
|
||||
Pipe => Self::BitwiseOr,
|
||||
|
Loading…
Reference in New Issue
Block a user