Граф коммитов

295 Коммитов

Автор SHA1 Сообщение Дата
Rob Lourens 54a84f1250
Merge pull request #260 from TysonAndre/fix-trait-use-notice
Fix a PHP notice generating a scoped property access expression
2018-09-25 22:43:26 -07:00
Tyson Andre c9a8793682 Only allow parsing unset() as a top-level statement
E.g. `unset($x)/2` is a syntax error.
Previously, this parser would not treat that as a syntax error.

This is similar to how `echo` can only be used as a top level statement.

- Tools using this parser may expect `unset` only as a top level statement

See
https://secure.php.net/manual/en/function.unset.php#refsect1-function.unset-notes
2018-09-23 23:16:34 -04:00
Tyson Andre 9463cfc86b Fix a PHP notice generating a scoped property access expression
And add a unit test
2018-09-23 14:55:54 -04:00
Tyson Andre 4155326431 Fix a notice in Parser->parseTernaryExpression()
Fixes #257
2018-09-02 18:09:40 -04:00
Tyson Andre d3e28a76e1 Fix parsing of edge case involving inline HTML
The included test files can be executed.
They will always print the inline HTML,
indicating that PHP is doing the equivalent of inserting semicolons.

Fixes #246

Also, ignore temporary files created by vim
2018-07-28 13:34:16 -07:00
Tyson Andre 80071b4d1e Work on properly parsing the expression lists passed to `<?=`
Before, tolerant-php-parser parsed the tokens after `<?=` and `<?php`
the same way.

Fixes #220 (This commit and subsequent commits in this PR)

This adds `TokenKind::ScriptSectionStartWithEchoTag` and handles the
subsequent tokens differently if that token kind is seen instead of
`ScriptSectionStartTag`.

This reuses `ExpressionStatement` with an `EchoExpression` for simplicity.
The resulting expression will have no `echoKeyword` because
`<?=` was part of the preceding `InlineHTML` Node.

- In all cases that I'm aware of,
  the ExpressionStatement with the EchoExpression will be moved
  into the outer statement list.

NOTE: echo is a statement, not an expression.
It must be followed by `?>` or `;`

- `echo exprList` can't be used as an expression.

- Contrast with `print expr`, (`PrintIntrinsicExpression`),
  which is correctly treated as an expression.

Update documentation

Add a test that the Parser will warn about `<?= 'expr'<EOF>`.

- Fixing that bug got rid of an incorrect EmptyExpression in another test
  (programStructure5.php.tree)
2018-06-08 19:56:53 -07:00
Tyson Andre 60d3fc5d25 Add a missing file 2018-05-12 19:25:35 -07:00
Tyson Andre 59b37a8d25 Fixes #103: Support parsing multiple exception types
Add a new array `otherQualifiedNameList` alongside qualifiedName
to `CatchClause`. (Contains remaining `Token`s and `QualifiedName`s)
(This design breaks backwards compatibility as little as possible)

- A future backwards incompatible release should merge the two
  properties into `qualifiedNameList`,
  or something along those lines.

Add a new helper method to parse the catch list.

- The new helper is required because
  `tests/cases/php-langspec/exception_handling/odds_and_ends.php`
  should not fail because `catch (int $e)` is **syntactically** valid php
  (in 7.x), i.e. `php --syntax-check` doesn't reject it.
2018-05-12 19:25:35 -07:00
Tyson Andre 797f79578d Make remainingTargetNames consistent, avoid php notice
Add a test of parsing an empty `insteadof` clause

Make remainingTargetNames consistently be an empty array instead of null
2018-05-12 12:01:19 -07:00
Tyson Andre f297043862 Fixes #190: `insteadof` should be able to accept a name list
Do this in a way that makes it less likely that applications already
using targetName will throw an exception or error.
This should be revisited in a future backwards incompatible release.
Add remainingTargetNames as a new property.

NOTE: traits16.php is invalid php 7 code,
so traits16.php.diag should be non-empty.
However, tolerant-php-parser emits a slightly different error
message than `php -l` would.
2018-05-12 11:59:13 -07:00
Rob Lourens 694b1538bb
Merge pull request #228 from TysonAndre/fix-unary-lhs-binary
For #19: Fix an edge case parsing `=` and `instanceof`
2018-03-17 21:12:58 -06:00
Tyson Andre 816ec34fb6 Fixes #189 : Fix parsing edge cases in yield statements
Update tests diagnostics and expected generated ASTs

For backwards compatibility, continue to make `yield from expr`
have an ArrayElement as a child node.

To maintain the invariant that all Nodes must have at least one child,
make $yieldExpression->arrayElement be null when parsing `yield;`

Aside: `yield &$a;` is (and should be)
parsed as the binary operator `(yield) & ($a)`.
This is surprising, but makes sense, being the only sane parse tree.

- Add a unit test that `yield & &$a;` is invalid.
  There is no way to parse that.

Verified with the PHP module nikic/php-ast

```php
var_export(ast_dump(
    ast\parse_code('<?php function test() { yield & $x; }', 50)
));
```
2018-02-24 23:20:41 -08:00
Rob Lourens faca5af49c
Merge pull request #235 from TysonAndre/fix-backslashes-unix
Fixes #224: Use DIRECTORY_SEPARATOR instead
2018-02-19 15:50:21 +09:00
Tyson Andre dab357fd83 Fixes #224: Use DIRECTORY_SEPARATOR instead 2018-02-18 22:34:14 -08:00
Tyson Andre 0360257ceb Fixes #188: Fix parsing empty variables
Previously, the fallback case when something beginning
with the token `$` wasn't a simple variable
would be to assume it would be a complex variable
such as `$$x`

Check that the first token would be valid before recursing.
2018-02-15 21:00:58 -08:00
Rob Lourens 59351ce2a6 Add license to FilePositionMapTest.php 2018-02-14 10:39:41 -08:00
Rob Lourens 8bbc9a7f81
Merge pull request #212 from TysonAndre/add-FilePositionMap
Efficiently look up lines/columns of many nodes
2018-02-14 10:38:07 -08:00
Rob Lourens cdac5b2405
Merge pull request #226 from TysonAndre/fix-varname
Improve parsing of `${` template strings
2018-02-14 10:16:52 -08:00
Tyson Andre d996815820 For #19: Fix an edge case parsing `=` and `instanceof`
This does not fix every single edge case.
This only fixes the edge cases for unary operators
on the left hand side of binary operators expecting a variable.

(That probably isn't even every single binary operator or unary operator)
2018-02-11 21:40:47 -08:00
Tyson Andre 2c3e576147 Efficiently look up lines/columns of many nodes
Fixes #179, adds FilePositionMap

This assumes that requested offsets will be close to previous requests,
which should be true if this is used while walking a tree, etc.

Future tasks if the basic design is solid:

- copy license to new files
- Document this in the public API
- Deprecate PositionUtilities or make those APIs use FilePositionMap?
  (E.g. cache FilePositionMap in a static variable,
   and use $text is === as previous request)
2018-02-11 20:47:32 -08:00
Tyson Andre 9d8c500217 Improve parsing of `${` template strings
This is incomplete, but still an improvement.

Related to https://github.com/Microsoft/tolerant-php-parser/issues/214

Note: The function never gets TokenKind::StringVarName for
OpenBraceDollarToken (`{$`), so it always uses parseExpression.
Also, TokenKind::Name is already used for parseExpression.

Add test cases for `"${var['stringIndex']}"`, as well of tests for
things tolerant-php-parser already supported due to parseExpression()

stringLiteral16.php was not used due to already being in skipped.json
(bug for making skipped.json specific was filed)

For issues #219 and #214
2018-02-11 20:38:07 -08:00
Tyson Andre 19debdc1bc Support parsing nested calls (#175)
For https://github.com/Microsoft/tolerant-php-parser/issues/175

Using tolerant-php-parser-to-php-ast,
the following types of statements have been tested,
and the transformed ASTs were identical to nikic/php-ast's AST nodes:

```php
<?php

foo(1234)['index'](true, false);
(new MyClass())();
$result = foo(1234)(5678);
$obj->call('prop')('value');
```

Also, callExpression8.php is valid PHP code.
There shouldn't have been any diagnostics whatsoever.

I'm not very familiar with this repo,
so I might have missed potential bugs.
2018-02-11 18:47:40 -08:00
Gabriel Caruso c435c471f6 Refactoring tests (#217) 2017-12-13 01:47:57 -08:00
Maarten Staa 9382009c22 Fix #194 - oddities around the static keyword.
Previously, all of the following examples would produce parse errors,
while being valid PHP code:

- new static;
- new static::$a;
- if ($a instanceof static) {}

This commit takes care of these edge cases.
2017-11-17 11:43:39 +01:00
Gabriel Caruso c5b4f3504f Update to PHPUnit 6 2017-11-11 11:51:16 -02:00
Stephan Unverwerth 8378884436 Update expected diagnostic results for continue/break statements 2017-09-28 20:55:59 +02:00
Stephan Unverwerth ca875d95ee Add diagnostics test 2017-09-28 20:52:50 +02:00
Stephan Unverwerth 6f9946ede1 Handle parenthesized breakout level 2017-09-26 21:28:37 +02:00
Tyson Andre d58538447d Use slashes 2017-09-20 09:53:09 -07:00
Tyson Andre 5256703431 Stop including non-php files in validation tests.
Noticed test failures for pgsql.phpunit.xml in the drupal project's test
files. (contains the substring ".php")

Also, do the matching on the path name, not on the object to string
conversion.
2017-09-19 20:30:31 -07:00
Rob Lourens b55b9eefcd Fix ${x} variable syntax 2017-08-10 11:42:17 -07:00
Rob Lourens e40b820463 Parse template string variables, and the basic expressions that are allowed 2017-08-10 11:26:27 -07:00
Rob Lourens 5cff92320d Fix tokenizer to tokenize T_NUM_STRING and T_VAR_NAME correctly 2017-08-08 17:23:02 -07:00
Rob Lourens 2cc3701de5 Fix #97 - add questionToken for parsing nullable types, update test baseline 2017-06-12 18:34:14 -07:00
Rob Lourens 55c2a2bfb3 Make LexicalGrammarTest match ParserGrammarTest when a new test file is added 2017-06-12 18:06:10 -07:00
Rob Lourens c993bc6160 Fix #148 - parse `new static` without errors 2017-06-12 17:33:26 -07:00
Rob Lourens 80d0cfe7f2 Fix #146 2017-06-12 17:08:39 -07:00
Rob Lourens 46ede61dd2 Move api tests into tests/api 2017-05-12 09:42:42 -07:00
Rob Lourens df78e029ca Tests for getResolvedName 2017-05-10 17:20:55 -07:00
Rob Lourens e69f149488 Fix data provider 2017-05-05 17:20:51 -07:00
Rob Lourens d08065c13c Merge branch 'lang-server' into lang-server-completions 2017-05-05 14:36:04 -07:00
Rob Lourens f34ac0cfdd Better getNodeAtPosition test setup 2017-05-05 14:30:32 -07:00
Rob Lourens 144756e63b Rewrite getNodeAtPosition and write more tests 2017-05-05 14:29:56 -07:00
Rob Lourens 158e2a7761 Remove var_dump from test 2017-05-05 12:12:28 -07:00
Rob Lourens 42a44597b2 Merge branch 'lang-server-nameresolution' into lang-server-perf 2017-05-05 12:05:10 -07:00
Rob Lourens 95fa8b1150 Merge branch 'master' of github.com:Microsoft/tolerant-php-parser into lang-server-nameresolution 2017-05-05 11:34:23 -07:00
Rob Lourens 4ea4d475e3 Port test fix from 5ea87aec62 2017-05-05 11:02:14 -07:00
Sara Itani 635cf8b16a Fix diagnostics provider issues 2017-05-05 09:54:01 -07:00
Sara Itani ef85002c2f Fix merge issues related to Node structure 2017-05-05 09:54:01 -07:00
Sara Itani e1e4642441 Merge branch 'master' of https://github.com/Microsoft/tolerant-php-parser into lang-server 2017-05-05 09:53:35 -07:00