Commit Graph

151 Commits

Author SHA1 Message Date
Laytan Laats
9a4744a28d fix: start and end col not being set for names 2023-04-17 01:14:21 +02:00
Laytan Laats
307175c408 fix: typo using endcol as startcol 2023-04-17 00:06:24 +02:00
Laytan Laats
68ac672368 build: replace VKCOM import with laytan import 2023-03-31 16:50:08 +02:00
Laytan Laats
92d341cbb5 feat: generate ast.Type "enum" 2023-03-30 02:20:12 +02:00
Laytan Laats
ec3527909c refactor: remove unused function 2023-03-26 01:54:21 +01:00
Laytan Laats
7c12f73974 feat: add start column and end column to position struct 2023-03-26 01:54:00 +01:00
Laytan Laats
375ccd136d test: add php8.2 constants in traits test 2023-03-25 16:11:37 +01:00
Laytan Laats
ce8b54eae1 test: add php8.2 true, null and false types test 2023-03-25 15:52:40 +01:00
Laytan Laats
66cc411e7c refactor: change makefile to reflect drop of php5 and run make 2023-03-25 15:29:51 +01:00
Laytan Laats
226f7fb5f1 refactor: remove unused function lastNode 2023-03-25 15:12:21 +01:00
Laytan Laats
74a8771740 refactor: move php7 scanner into php7 package 2023-03-25 15:02:34 +01:00
Laytan Laats
a97686125d refactor!: drop php5 support 2023-03-25 15:00:17 +01:00
Laytan Laats
ffc94c1a63 refactor: move test.php into testdata folder 2023-03-25 14:32:14 +01:00
Makhnev Petr
e16671724e
php8.1: added intersection types support (#29) 2022-06-26 03:31:29 +03:00
Makhnev Petr
7f6cd25376
php8.2: added readonly classes support (#26) 2022-06-26 01:18:40 +03:00
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
Makhnev Petr
50ed139750
php8.1: added first class callable syntax (#18) 2021-07-31 23:50:59 +03:00
Makhnev Petr
13ed0df282
php8.1: grammar improvements (#16)
Renamed 'possible_comma' with 'optional_comma' as in PHP-Parser
Replace all 'identifier' with 'identifier_ex' and all 'T_STRING' with 'identifier' as in PHP-Parser
2021-07-31 23:17:26 +03:00
Makhnev Petr
af394e9eb0
php8.1: added enum (#12) 2021-07-31 19:44:09 +03:00
Makhnev Petr
44bbff6073
php8.1: added new octal numbers syntax (#10)
Also fixed a bug where `0X...` and `0B...` were not recognized as valid numbers.
2021-07-31 18:37:01 +03:00
Makhnev Petr
8df80651e0
php8.1: added never type (#8) 2021-07-31 18:06:46 +03:00
Makhnev Petr
8c35b0aef1
php8.1: added readonly modifier (#6) 2021-07-31 18:00:21 +03:00
Makhnev Petr
72cd222aeb
all: renamed github.com/z7zmey/php-parser with github.com/VKCOM/php-parser 2021-07-30 21:01:34 +03:00
Makhnev Petr
049ce7ddc6
PHP 8 (#1)
PHP 8 Update

- nullsafe operator (?->)
- Remove (real) cast
- Named arguments
- Remove (unset) cast
- Remove {} access
- match expression
- Union types in type hints and static typehint
- Block catch without variable
- Trailing comma in parameter lists
- throw can be used as an expression
- Concatenation precedence
- Declaring properties in the constructor
- Attributes
- Names in the namespace are treated as a single token
- Trailing comma in closure use list
- Check that ::class on object works
- Deferencable changes and arbitrary expressions in new/instanceof
2021-07-30 20:53:27 +03:00
Vadym Slizov
367eff9de6
rename package cfg to conf 2021-02-13 23:54:34 +02:00
Vadym Slizov
29477c9552
[#122] compile php5 parser 2021-02-13 23:50:10 +02:00
Vadym Slizov
c8b7fc0786
[#122] compile php5 parser 2021-02-13 23:48:44 +02:00
Vadym Slizov
e1686cb83c
[#98] fix panic when heredoc is not closed 2021-02-13 23:09:41 +02:00
i582
78492f6456 internal: fixed parsing of anonymous classes
Since now 'ctor_arguments' returns nil, it is
necessary to initialize it to avoid panics.
2021-02-07 07:52:29 +03:00
i582
61523ab396 internal: fixed parsing of expression new
1. Now, for the expression 'new A' the correct
values EndLine, EndPos, and not -1 will be set;
2. Also, for expressions from php5 '$a = &new Foo',
the condition for parsing is fixed when it is necessary
to set the Args values and the initialization of the
NewTkn field is added, in the case when this condition
is false.

## Problem description

The reason why the positions after parsing became
incorrect is that the check that is responsible for
separating expressions like 'new A' and 'new A (args)'
relied on comparison with nil, however, when the parser
was updated, 'ctor_arguments' began to return not nil,
but &ArgumentList{}, so the condition was always true,
and in this case, when calculating the position, the
second argument of the 'NewTokenNodePosition' function
was nil, which is why -1 was returned there.

For the second, the reasons are similar. In addition,
there was a mistake in the number that needs to be
checked. In the expression:

'variable' '=' '&' T_NEW class_name_reference ctor_arguments'

it is necessary to check not 3, but 6 elements for nil.
2021-02-04 07:12:56 +03:00
Vadym Slizov
e3b133f3de
refactoring: update api 2020-12-29 21:23:22 +02:00
Vadym Slizov
cb4b4e69c4
refactoring: fix naming 2020-12-28 23:01:02 +02:00
Vadym Slizov
0701b3552e
refactoring: fix scanning double dollar in template string 2020-12-28 21:43:55 +02:00
Vadym Slizov
07f49a4d21
refactoring: move internal nodes 2020-12-28 21:31:24 +02:00
Vadym Slizov
c0465f9605
refactoring: remove "StmtTraitMethodRef" node 2020-12-28 10:47:09 +02:00
Vadym Slizov
c29e8ec0e0
refactoring: update ast structure of "Class", "Interface" and "Trait" nodes 2020-12-28 10:10:24 +02:00
Vadym Slizov
2990f0cc2d
refactoring: create "ScalarEncapsedStringBrackets" node 2020-12-28 00:53:48 +02:00
Vadym Slizov
38141ce97f
refactoring: create "ScalarEncapsedStringVar" node 2020-12-28 00:38:39 +02:00
Vadym Slizov
e4321b5e90
refactoring: create "ExprBrackets" node 2020-12-28 00:02:14 +02:00
Vadym Slizov
ad884c99df
refactoring: update ast structure of "StaticCall" node 2020-12-27 23:19:49 +02:00
Vadym Slizov
0f2341bfa9
refactoring: update ast structure of "MethodCall" and "PropertyFetch" nodes 2020-12-27 23:04:09 +02:00
Vadym Slizov
2c09138600
refactoring: update ast structure of "Variable" node 2020-12-27 21:55:36 +02:00
Vadym Slizov
115d481a57
refactoring: update ast structure of "IncludeOnce" node 2020-12-26 22:44:14 +02:00
Vadym Slizov
616fd4448e
refactoring: rename DieTkn to ExitTkn 2020-12-26 22:41:25 +02:00
Vadym Slizov
a593760569
refactoring: remove ExprReference node 2020-12-26 22:38:35 +02:00
Vadym Slizov
0f5f5e7dc7
refactoring: update ast structure of "ArrayItem" node 2020-12-26 20:13:50 +02:00
Vadym Slizov
8bf1fa822d
refactoring: update ast structure of "Foreach" node 2020-12-26 19:38:45 +02:00
Vadym Slizov
b85bae2ec1
refactoring: update ast structure of "Closure" and "ClosureUse" nodes 2020-12-26 18:20:10 +02:00
Vadym Slizov
03c7979ccd
refactoring: remove StmtTraitAdaptationList node 2020-12-20 23:04:23 +02:00
Vadym Slizov
eda7ae1c87
refactoring: update scanner tests 2020-12-20 14:39:37 +02:00