mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: support double/float cast
This commit is contained in:
parent
5a44de9650
commit
a83f1b80bb
@ -4,9 +4,11 @@ set -xe
|
||||
|
||||
dir=$(realpath $1)
|
||||
|
||||
cargo build --release
|
||||
|
||||
for file in $(find $dir -name "*.php")
|
||||
do
|
||||
cargo run -q -- $file
|
||||
./target/release/phpast $file
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
|
@ -643,6 +643,10 @@ impl Lexer {
|
||||
self.col += 4;
|
||||
self.skip(5);
|
||||
TokenKind::IntCast
|
||||
} else if self.try_read("float)") {
|
||||
self.col += 6;
|
||||
self.skip(7);
|
||||
TokenKind::DoubleCast
|
||||
} else {
|
||||
TokenKind::LeftParen
|
||||
}
|
||||
|
@ -274,6 +274,7 @@ pub enum CastKind {
|
||||
Object,
|
||||
Bool,
|
||||
Int,
|
||||
Double,
|
||||
}
|
||||
|
||||
impl From<TokenKind> for CastKind {
|
||||
@ -283,6 +284,7 @@ impl From<TokenKind> for CastKind {
|
||||
TokenKind::ObjectCast => Self::Object,
|
||||
TokenKind::BoolCast => Self::Bool,
|
||||
TokenKind::IntCast => Self::Int,
|
||||
TokenKind::DoubleCast => Self::Double,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
@ -1622,12 +1622,12 @@ impl Parser {
|
||||
}
|
||||
|
||||
fn is_prefix(op: &TokenKind) -> bool {
|
||||
matches!(op, TokenKind::Bang | TokenKind::Minus | TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast)
|
||||
matches!(op, TokenKind::Bang | TokenKind::Minus | TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast | TokenKind::DoubleCast)
|
||||
}
|
||||
|
||||
fn prefix_binding_power(op: &TokenKind) -> u8 {
|
||||
match op {
|
||||
TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast => 101,
|
||||
TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast | TokenKind::DoubleCast => 101,
|
||||
TokenKind::Minus => 100,
|
||||
TokenKind::Bang => 99,
|
||||
_ => unreachable!()
|
||||
@ -1638,7 +1638,8 @@ fn prefix(op: &TokenKind, rhs: Expression) -> Expression {
|
||||
match op {
|
||||
TokenKind::Bang => Expression::BooleanNot { value: Box::new(rhs) },
|
||||
TokenKind::Minus => Expression::Negate { value: Box::new(rhs) },
|
||||
TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast => Expression::Cast { kind: op.into(), value: Box::new(rhs) },
|
||||
TokenKind::StringCast | TokenKind::ObjectCast | TokenKind::BoolCast | TokenKind::IntCast |
|
||||
TokenKind::DoubleCast => Expression::Cast { kind: op.into(), value: Box::new(rhs) },
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user