php-parser/internal/php8
Makhnev Petr d85f5a4816
php8: fixed a bug with # comments (#22)
Example from issue:
```php
<?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)
};
```
2021-08-02 12:37:08 +03:00
..
builder.go php8.1: added first class callable syntax (#18) 2021-07-31 23:50:59 +03:00
lexer.go all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
newline.go PHP 8 (#1) 2021-07-30 20:53:27 +03:00
node.go php8.1: added first class callable syntax (#18) 2021-07-31 23:50:59 +03:00
parser_php8_1_test.go php8.1: added enum (#12) 2021-07-31 19:44:09 +03:00
parser_php8_test.go php8.1: added readonly modifier (#6) 2021-07-31 18:00:21 +03:00
parser_test.go all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
parser.go all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
php8_bench_test.go all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
php8.go php8.1: added first class callable syntax (#18) 2021-07-31 23:50:59 +03:00
php8.y php8.1: added first class callable syntax (#18) 2021-07-31 23:50:59 +03:00
scanner_php8_1_test.go php8.1: added enum (#12) 2021-07-31 19:44:09 +03:00
scanner_php8_test.go php8: fixed a bug with # comments (#22) 2021-08-02 12:37:08 +03:00
scanner_test.go all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
scanner.go php8: fixed a bug with # comments (#22) 2021-08-02 12:37:08 +03:00
scanner.rl php8: fixed a bug with # comments (#22) 2021-08-02 12:37:08 +03:00
test.php PHP 8 (#1) 2021-07-30 20:53:27 +03:00