Skip to content

Capture the offending token in PHP 8 parse errors - #58

Merged
kaste merged 2 commits into
SublimeLinter:masterfrom
dpc00:php8-unexpected-token
Sep 29, 2026
Merged

kaste merged 2 commits into
SublimeLinter:masterfrom
dpc00:php8-unexpected-token

Conversation

@dpc00

@dpc00 dpc00 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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"), but regex only matched the PHP 7 form unexpected 'foo'. So near was never set and the error was drawn at the first character of the line.

The near part 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 give near = None, as before, and the existing PHP 7 tests are unchanged.

I added test_issue_56_php8_quoted_tokens, with messages taken from php -l on 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 (near is None) 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=Off for 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.

dpc00 and others added 2 commits September 29, 2026 20:28
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
kaste force-pushed the php8-unexpected-token branch from ecbd03a to d616ef0 Compare September 29, 2026 18:34
@kaste
kaste merged commit f05938c into SublimeLinter:master Sep 29, 2026
3 checks passed
@kaste

kaste commented Sep 29, 2026

Copy link
Copy Markdown
Member

I hope I made that regex even stronger in d616ef0

Thanks, released as 1.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8 'unexpected token ";"' not matched: error is drawn at the first character of the line

2 participants