Repository navigation
v0.25.0
Errors are now machine-readable: every ParseError has a stable code, and every compile-time error names the rule it breaks. Version-targeted parsing follows each PHP version from 7.4 to 8.6 much more closely.
Added
ForbiddenRuleonParseError::Forbidden(rule,forbidden_rule()), so tools can match errors by rule instead of by message. IncludesForbiddenRule::ALL,phase()(Phase::ParseorPhase::Compile, asphp -lreports it),FromStrandDisplay(php-rs-parser).ParseError::code(), a stable identifier for every error, andParseError::leaves_ast_incomplete()(php-rs-parser). Errors returned byparsecarry thecode(php-wasm).LexerErrorKind::UnterminatedCommentandLexerErrorKind::InvalidNumericLiteral, which replacesOtherfor literals such as1_(php-lexer).Name::join_parts_in(src), which borrows a multi-part name from the source when possible (php-ast).
Changed
ParseError::UnclosedDelimiterreadsmissing closing ')'; the opening offset stays inopened_at(php-rs-parser).Name::join_partsandName::to_string_reprborrow single-part names instead of allocating (php-ast).
Removed
- Breaking:
ParseError::ExpectedExpression,ExpectedStatementandExpectedOpenTag; useParseError::Expected, whose message also names the token found (php-rs-parser).
Fixed
- Version gates follow PHP from 7.4 to 8.6: errors that older versions report (trailing commas in parameter lists before 8.0,
?falsebefore 8.2,new readonly classbefore 8.3,exitandcloneargument forms, …), valid PHP 7.4 that was rejected (mixedas a class name,function match(),#[...]as a comment, …), keywords such asreadonly,neverand__PROPERTY__read as names before they were introduced, and PHP 8.6 features (readonly property defaults, partial function application in constant expressions, property writes through constant objects).\staticandnamespace\staticin types are rejected from PHP 8.5 (php-rs-parser). - Lexing: nothing after
__halt_compiler()is lexed, casts need only spaces or tabs around the keyword, a lone\ris a line break, and interpolations are scanned correctly past comments, backticks, heredocs and nested strings (php-lexer,php-rs-parser). - Parsing: bare
yieldbefore?,??,:,=>andas;var,insteadofand hook names match case-insensitively;**stays out of aninstanceofoperand;::works on non-constant array expressions;selfandparentare valid global constant names and stay unresolved in anonymous class types (php-rs-parser). - Compile-time checks no longer reject valid code (
Enumin intersection types, foldable class names, short-circuit folding, set hook parameter types, heredoc indentation inside interpolations) and now catch stray semicolons in class bodies,varwith other modifiers,final privateand pre-8.1finalconstants, reserved enum names, invalid typed enum constants, by-referencegethooks with asethook and<?=without an expression (php-rs-parser). - A parenthesized constant named like a cast keyword, such as
(int), no longer prints as a cast (php-printer).