chore: format

This commit is contained in:
Ryan Chandler 2022-09-16 15:20:49 +01:00
parent e2065bf029
commit 79bf633fac
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
4 changed files with 94 additions and 38 deletions

View File

@ -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

View File

@ -167,7 +167,7 @@ pub enum TokenKind {
BitwiseNot,
LogicalAnd,
LogicalOr,
LogicalXor
LogicalXor,
}
#[derive(Debug, Clone, PartialEq)]

View File

@ -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]) {

View File

@ -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,