Skip to content

Lex comments between __halt_compiler and its semicolon - #22

Open
danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-halt-compiler-comments
Open

danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-halt-compiler-comments

Conversation

@danslo

@danslo danslo commented Nov 16, 2026

Copy link
Copy Markdown

PHP accepts comments anywhere between the tokens of __halt_compiler();:

<?php __halt_compiler/* a */ ( // b
); data

The scanner's halt states take only whitespace there; at a comment they return to PHP code, so the data after the semicolon is lexed as code and fails to parse.

The halt states now lex block, doc and line comments through a lexer.go helper, which also records their newlines for token positions. scanner.go, regenerated with ragel 6.10 and gofmt, changes only in those actions. Added scanner tests for the comments and for line numbers after a multi-line one.

PHP takes __halt_compiler/* a */ ( // b
) ; as it takes comments anywhere between tokens. The scanner's halt
states took whitespace only and went back to PHP code at a comment, so it
lexed the data after the semicolon as code.
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.

1 participant