Capture the offending token in PHP 8 parse errors - #58
Merged
Merged
Conversation
PHP 8 reports unexpected tokens as 'unexpected token ";"', 'unexpected identifier "foo"', 'unexpected variable "$x"', ... with double quotes and a description, but the regex only knew the PHP 7 form "unexpected 'foo'". 'near' was therefore never set and the error was drawn at the first character of the line. Accept both quote styles and the optional description. Add tests with messages from 'php -l' on PHP 8.4. Fixes SublimeLinter#56 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Match the closing quote to the opening quote instead of excluding both quote characters from the captured token. Add a PHP 8 parse error where a double-quoted token contains an apostrophe.
kaste
force-pushed
the
php8-unexpected-token
branch
from
September 29, 2026 18:34
ecbd03a to
d616ef0
Compare
Member
|
I hope I made that regex even stronger in d616ef0 Thanks, released as 1.5.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56.
PHP 8 reports the unexpected token with double quotes and a description (
unexpected token ";",unexpected identifier "bar",unexpected variable "$y",unexpected integer "2",unexpected double-quoted string "def"), butregexonly matched the PHP 7 formunexpected 'foo'. Sonearwas never set and the error was drawn at the first character of the line.The
nearpart of the regex now accepts either quote style and an optional description:r'(?:unexpected (?:[a-z-]+(?: [a-z-]+)* )?["\'](?P<near>[^"\']+)["\'])?.*) 'Messages without a quoted token (
unexpected end of file) still givenear = None, as before, and the existing PHP 7 tests are unchanged.I added
test_issue_56_php8_quoted_tokens, with messages taken fromphp -lon PHP 8.4.25 (token, identifier, variable, integer, double-quoted string, end of file). I ran the test module with UnitTesting in Sublime Text 4215: the new test fails before the change (nearisNone) and all four tests pass after it.Since you mentioned you have no PHP here: the messages in the tests are the real output of
php -l -n -d display_errors=On -d log_errors=Offfor small broken files, and I did not have an older PHP to compare with, so the PHP 7 forms are only covered by the tests that were already there.