diff --git a/meta/run_on_files.sh b/meta/run_on_files.sh index 71ac5e4..4f6b97f 100755 --- a/meta/run_on_files.sh +++ b/meta/run_on_files.sh @@ -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 diff --git a/trunk_lexer/src/lexer.rs b/trunk_lexer/src/lexer.rs index 2819aea..8a4e887 100644 --- a/trunk_lexer/src/lexer.rs +++ b/trunk_lexer/src/lexer.rs @@ -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 } diff --git a/trunk_parser/src/ast.rs b/trunk_parser/src/ast.rs index e99b9c3..adbdf06 100644 --- a/trunk_parser/src/ast.rs +++ b/trunk_parser/src/ast.rs @@ -274,6 +274,7 @@ pub enum CastKind { Object, Bool, Int, + Double, } impl From for CastKind { @@ -283,6 +284,7 @@ impl From for CastKind { TokenKind::ObjectCast => Self::Object, TokenKind::BoolCast => Self::Bool, TokenKind::IntCast => Self::Int, + TokenKind::DoubleCast => Self::Double, _ => unreachable!() } } diff --git a/trunk_parser/src/parser/mod.rs b/trunk_parser/src/parser/mod.rs index b47b707..415f6be 100644 --- a/trunk_parser/src/parser/mod.rs +++ b/trunk_parser/src/parser/mod.rs @@ -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!() } }