mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +01:00
chore: format
This commit is contained in:
parent
e2065bf029
commit
79bf633fac
@ -386,7 +386,7 @@ impl Lexer {
|
||||
[b'^', ..] => {
|
||||
self.next();
|
||||
TokenKind::Caret
|
||||
},
|
||||
}
|
||||
[b'{', ..] => {
|
||||
self.next();
|
||||
TokenKind::LeftBrace
|
||||
@ -461,7 +461,7 @@ impl Lexer {
|
||||
[b'%', ..] => {
|
||||
self.next();
|
||||
TokenKind::Percent
|
||||
},
|
||||
}
|
||||
[b'-', b'-', ..] => {
|
||||
self.skip(2);
|
||||
TokenKind::Decrement
|
||||
@ -499,7 +499,7 @@ impl Lexer {
|
||||
[b'<', b'>', ..] => {
|
||||
self.skip(2);
|
||||
TokenKind::AngledLeftRight
|
||||
},
|
||||
}
|
||||
[b'<', ..] => {
|
||||
self.next();
|
||||
TokenKind::LessThan
|
||||
|
@ -167,7 +167,7 @@ pub enum TokenKind {
|
||||
BitwiseNot,
|
||||
LogicalAnd,
|
||||
LogicalOr,
|
||||
LogicalXor
|
||||
LogicalXor,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -4369,79 +4369,134 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn modulo() {
|
||||
assert_ast("<?php 6 % 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::Mod, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 % 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::Mod,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[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 }) })
|
||||
]);
|
||||
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 }) })
|
||||
]);
|
||||
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 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitwise_and() {
|
||||
assert_ast("<?php 6 & 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::BitwiseAnd, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 & 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::BitwiseAnd,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitwise_or() {
|
||||
assert_ast("<?php 6 | 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::BitwiseOr, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 | 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::BitwiseOr,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitwise_xor() {
|
||||
assert_ast("<?php 6 ^ 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::BitwiseXor, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 ^ 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::BitwiseXor,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[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 }) })
|
||||
]);
|
||||
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 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spaceship() {
|
||||
assert_ast("<?php 6 <=> 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::Spaceship, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 <=> 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::Spaceship,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logical_and() {
|
||||
assert_ast("<?php 6 and 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::LogicalAnd, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 and 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::LogicalAnd,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logical_or() {
|
||||
assert_ast("<?php 6 or 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::LogicalOr, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 or 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::LogicalOr,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logical_xor() {
|
||||
assert_ast("<?php 6 xor 2;", &[
|
||||
expr!(Expression::Infix { lhs: Box::new(Expression::Int { i: 6 }), op: InfixOp::LogicalXor, rhs: Box::new(Expression::Int { i: 2 }) })
|
||||
]);
|
||||
assert_ast(
|
||||
"<?php 6 xor 2;",
|
||||
&[expr!(Expression::Infix {
|
||||
lhs: Box::new(Expression::Int { i: 6 }),
|
||||
op: InfixOp::LogicalXor,
|
||||
rhs: Box::new(Expression::Int { i: 2 })
|
||||
})],
|
||||
);
|
||||
}
|
||||
|
||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||
|
@ -56,7 +56,8 @@ impl Precedence {
|
||||
LeftShift | RightShift => Self::BitShift,
|
||||
Dot => Self::Concat,
|
||||
LessThan | LessThanEquals | GreaterThan | GreaterThanEquals => Self::LtGt,
|
||||
DoubleEquals | BangEquals | TripleEquals | BangDoubleEquals | AngledLeftRight | Spaceship => Self::Equality,
|
||||
DoubleEquals | BangEquals | TripleEquals | BangDoubleEquals | AngledLeftRight
|
||||
| Spaceship => Self::Equality,
|
||||
Ampersand => Self::BitwiseAnd,
|
||||
Caret => Self::BitwiseXor,
|
||||
Pipe => Self::BitwiseOr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user