Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php8: fixed a bug with # comments #22

Merged
merged 1 commit into from
Aug 2, 2021

Conversation

i582
Copy link
Contributor

@i582 i582 commented Aug 2, 2021

Example from issue:

<?php
#
# Comment
#

$a = 100;

The problem with the example from the issue is that # is immediately followed by a line break.
And since the rule in the lexer for such comments was changed, this case was handled incorrectly.

(('#' ^'[') | '//') any_line* when is_not_comment_end => {
   lex.ungetStr("?>")
   lex.addFreeFloatingToken(tkn, token.T_COMMENT, lex.ts, lex.te)
};

This rule has one problem, it checks two characters at once, first for the match #, and
then for the mismatch [, which leads to the fact that in the case of an empty comment, the first
matcher will capture #, and the second line break (\n), which will lead to the fact that any_line
matcher will not work and will not increase the line number.

The next rule added is specifically for this case.

'#' newline when is_not_comment_end => {
    lex.ungetStr("?>")
    lex.addFreeFloatingToken(tkn, token.T_COMMENT, lex.ts, lex.te)
};

Fixes #21

… the line number, which caused all positions to become incorrect

An example of such a comment is

#

An empty comment with a line break immediately after the #.
@i582 i582 added the bug Something isn't working label Aug 2, 2021
@i582 i582 merged commit d85f5a4 into master Aug 2, 2021
@i582 i582 deleted the pmakhnev/fix_bug_with_sharp_comments_position branch August 2, 2021 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug with positions with # comments
1 participant