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

872 Коммитов

Автор SHA1 Сообщение Дата
Rob Lourens 73e08c06fd
Merge pull request #222 from TysonAndre/suppress-phpunit-risky-warnings
Don't emit "this test did not perform any assertions"
2018-02-11 22:08:56 -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 2ca01a45c1 Use camelCase for properties 2018-02-11 20:47:32 -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
Rob Lourens 93419a2049
Merge pull request #221 from TysonAndre/split-diagnostic-class
Split DiagnosticKind out of Diagnostic.php
2018-02-11 19:21:24 -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
Tyson Andre 59e3993e1d Don't emit "this test did not perform any assertions"
See https://phpunit.de/manual/current/en/risky-tests.html

I'm using php 7.2.2, and phpunit 6.5.6 gets installed.
I believe that the newer phpunit releases were stricter by default about
tests that don't perform any assertions
2018-02-11 18:28:04 -08:00
Tyson Andre b696c25825 Split DiagnosticKind out of Diagnostic.php
E.g. if something using tolerant-php-parser is using DiagnosticKind,
but class diagnostic isn't loaded yet,
then I might fail to load this class.
(If the standard PSR-4 loading rules are used instead of an optimized autoloader)
2018-02-11 17:02:42 -08:00
Rob Lourens 42fe00b6e6
Merge pull request #211 from TysonAndre/optimize-getDiagnostics-v2
Optimize getDiagnostics for speed
2018-01-03 17:11:06 -08:00
Tyson Andre b6fb0236a9 Use callable to be consistent, fix typo in documentation 2017-12-19 21:55:00 -08:00
Tyson Andre c13af9dce1 Initialize tokenKindToText when DiagnosticsProvider is loaded 2017-12-19 21:55:00 -08:00
Tyson Andre f583f4cd2e Optimize getDiagnostics for speed
Add a simple benchmarking script

Extreme optimization, sacrificing code style in some areas.

- This is meant for discussion, since the project is
  in the optimization phase.

This commit reduces the time needed to getDiagnostics
from 0.013 to 0.007 seconds.

Average time to generate diagnostics (before): 0.013...
Average time to generate diagnostics (after):  0.006921
time to parse (Without diagnostics):           0.036374

(E.g. getDiagnostics previously took 36% of the time compared
to generating an AST,
and now it takes 19% of that time.)
2017-12-19 21:55:00 -08:00
Rob Lourens 0e936a121f
Merge pull request #216 from carusogabriel/early-return
Apply Early Return
2017-12-13 09:35:19 -08:00
Rob Lourens d3d1fecc10
Merge pull request #215 from carusogabriel/null-coalesce-operator
Use Null Coalesce Operator
2017-12-13 09:34:02 -08:00
Gabriel Caruso c435c471f6 Refactoring tests (#217) 2017-12-13 01:47:57 -08:00
Gabriel Caruso bee824b040 Use Null Coalesce Operator 2017-12-13 07:30:58 -02:00
Gabriel Caruso 8680f4545f Apply Early Return 2017-12-13 07:29:58 -02:00
Rob Lourens 10e901a608
Merge pull request #210 from MaartenStaa/fix-new-static-and-instanceof-static
Fix #194 - oddities around the static keyword.
2017-11-17 09:06:43 -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
Tomáš Votruba c884bce37a ci(travis): add upcoming PHP 7.2 (#204) 2017-11-15 10:40:05 -08:00
Rob Lourens d3202c84ec
Merge pull request #209 from TysonAndre/perf-micro-opt-eat
Minor performance improvement: Add faster variant of eat()
2017-11-11 18:30:17 -07:00
Rob Lourens 9932c87460
Merge pull request #208 from TysonAndre/phan-remove-unused
Remove unreachable statement and unused variable
2017-11-11 18:28:19 -07:00
Rob Lourens e1258a95b2
Merge pull request #207 from TysonAndre/fix-duplicate-arraykey
nit: Remove duplicate array keys
2017-11-11 18:27:19 -07:00
Rob Lourens b5a67169e8
Merge pull request #206 from gabriel-caruso/phpunit
Update to PHPUnit 6
2017-11-11 18:22:35 -07:00
Tyson Andre 3f08e4282c Minor performance improvement: Add faster variant of eat()
and a faster version of eatOptional().

eat() is called frequently when converting lexed tokens to values,
and often with a single token type. Varargs and array counting would
slow that down.

validatiion/ParserPerformance sped up from 0.581 to 0.574 seconds (1%).
(Added a loop to run on 100 files 10 times, divided by 10, took best times)
2017-11-11 12:33:18 -08:00
Tyson Andre a71ab34029 Remove unreachable statement and unused variable 2017-11-11 12:05:24 -08:00
Tyson Andre 26c64778f7 Remove duplicate array keys from PhpTokenizer.php
Detected via static analysis

When there are duplicate array keys, the last entry takes precedence
(e.g. the removed T_EXIT line had the wrong value)
2017-11-11 12:02:58 -08:00
Gabriel Caruso c5b4f3504f Update to PHPUnit 6 2017-11-11 11:51:16 -02:00
Rob Lourens 77579dfa1e Change GettingStarted to match README change with absolute require 2017-10-30 16:14:48 -07:00
Rob Lourens 2c060ce706
Merge pull request #203 from TomasVotruba/patch-1
README: make require use of __DIR__
2017-10-30 16:13:48 -07:00
Tomáš Votruba 8297d216e1
README: make require use of __DIR__
When we now absolute path, it's be
2017-10-31 00:04:10 +01:00
Rob Lourens 03de0ae0b1 Fix #202 - suppress warnings from token_get_all -
It can produce lots of unnecessary warnings when parsing invalid php syntax
2017-10-30 15:39:40 -07:00
Rob Lourens 69ea4ed415 Merge pull request #200 from TysonAndre/fix-phpdoc
Fix resolution of phpdoc for BreakOrContinueStatement
2017-10-14 23:00:08 -07:00
Tyson Andre 1fc2f28135 Fix resolution of phpdoc for BreakOrContinueStatement
Add phpdoc for parsing expressions.
2017-10-14 13:08:46 -07:00
Rob Lourens 41fd99ffb1 Merge pull request #199 from vinkla/patch-1
Exclude more non-essential files
2017-10-03 14:51:16 -07:00
Vincent Klaiber 77f7f45fd1 Update .gitattributes 2017-10-03 21:18:21 +02:00
Vincent Klaiber 3522a523c4 Exclude more non-essential files
This pull request exclude even more non-essential files when installing this package in production.
2017-10-03 09:07:44 +02:00
Rob Lourens 8aa8c0ab56 Merge pull request #198 from MadHed/diag-validation
Add diagnostics test
2017-09-28 12:57:26 -07: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
Rob Lourens fbac533326 Merge pull request #197 from MadHed/fix-breakout-level-diagnostics
Fix breakout level literal parsing
2017-09-28 11:39:11 -07:00
Stephan Unverwerth 75a901bc50 Fix breakout level literal parsing 2017-09-27 23:05:16 +02:00
Rob Lourens 754db66235 Merge pull request #196 from MadHed/master
Handle parenthesized breakout level
2017-09-26 21:00:14 -07:00
Stephan Unverwerth 870c141736 Fix breakout level number parsing 2017-09-26 22:05:10 +02:00
Stephan Unverwerth 6f9946ede1 Handle parenthesized breakout level 2017-09-26 21:28:37 +02:00
Rob Lourens 099d0b17f2 Merge pull request #187 from TysonAndre/speed-up-token
Speed up token value to name lookup
2017-09-20 12:55:18 -07:00
Tyson Andre b98ede743a Speed up token value to name lookup
Grammar test suite sped up from 1.2 seconds to 1.1 seconds.

This went from O(n) (loop over 183 constants) to O(1) (hash lookup)
2017-09-20 12:43:34 -07:00
Rob Lourens fc9882996c Merge pull request #184 from TysonAndre/fix-misc-framework-errors
Stop including non-php files in validation tests.
2017-09-20 11:52:06 -07:00
Tyson Andre d58538447d Use slashes 2017-09-20 09:53:09 -07:00