From 45b6f6ab361c2494112ae0b3b771bc6216828715 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sun, 8 Mar 2020 11:44:04 +0900 Subject: [PATCH 1/7] Update .travis.yml to include recent PHP versions --- .travis.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 219a43d5..945bb674 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,26 +6,19 @@ branches: - trying - master -matrix: +jobs: include: - php: 5.6 - php: 7.0 - php: 7.1 env: - ENABLE_DEVTOOLS=true + - php: 7.2 + - php: 7.3 + - php: 7.4 - php: nightly - - php: hhvm-3.12 - sudo: required - dist: trusty - group: edge - - php: hhvm - sudo: required - dist: trusty - group: edge allow_failures: - php: nightly - - php: hhvm-3.12 - - php: hhvm fast_finish: true os: @@ -34,8 +27,6 @@ os: notifications: irc: "chat.freenode.net#hoaproject" -sudo: false - env: global: - secure: "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCoAO780/K7xbK3aPnHJmAyw9B3OGRFx2sSnl6umenksq4kmlzmPaUF9g3cHGcXpM5O33P8Tux//iYGASy5W8f5vbxbWSvlwV/aWFW9oSM6G/01gyW9vRFK0MnXpUMyCF9B4K/RJumGxm9BSxkAFFo2gPHIJrd08SOQeiDLygpcEQ==" From a803426c34303080ea34c913a5db34b212f3ed5b Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 13:29:02 +0200 Subject: [PATCH 2/7] [TASK] Adjust TravisCI configuration * exclude PHP 7.4 build (not supported by released hoa/test version) * restrict php-cs-fixer to PHP 7.1 max, requires additional `--allow-risky` for newer 2.x releases see https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/23ec31224005ee0ed09505eca1bc8af90b7ca557/UPGRADE.md --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 945bb674..4f68f38e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,10 @@ jobs: - ENABLE_DEVTOOLS=true - php: 7.2 - php: 7.3 - - php: 7.4 - php: nightly allow_failures: + # @todo hoa/test has to be adjusted/raised first concerning PHP 7.4 compatibility + - php: 7.4 - php: nightly fast_finish: true @@ -45,6 +46,9 @@ script: - composer install - vendor/bin/hoa test:run - if [[ $ENABLE_DEVTOOLS ]]; then - composer global require friendsofphp/php-cs-fixer; + # @todo: + # php-cs-fixer ^2.0 requires additional attribute `--allow-risky`, triggered by hoa/devtools + # php-cs-fixer ^1.13 is supported until PHP 7.1 max (hard-coded internally) + composer global require require friendsofphp/php-cs-fixer:^1.13.0; vendor/bin/hoa devtools:cs --diff --dry-run .; fi From 90c9b8044668f41fa07333fd7464d1ab6b96ae85 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 10:58:51 +0200 Subject: [PATCH 3/7] [TASK] Add more context to exceptions * enhances `UnrecognizedToken` exception, see #111 * enhances `UnexpectedToken` exception, see #112 Fixes: #111, #112 --- Llk/Lexer.php | 17 ++++++++++++++--- Llk/Parser.php | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Llk/Lexer.php b/Llk/Lexer.php index 68513678..5cdc6011 100644 --- a/Llk/Lexer.php +++ b/Llk/Lexer.php @@ -147,14 +147,25 @@ public function lexMe($text, array $tokens) $nextToken = $this->nextToken($offset); if (null === $nextToken) { + $line = 1; + $column = $offset; + $offsetText = substr($text, 0, $offset); + $pointerSpacing = mb_strlen($offsetText); + $previousLineBreak = strrpos($offsetText, "\n"); + if ($previousLineBreak !== false) { + $line = substr_count($offsetText, "\n") + 1; + $column = mb_strlen($offsetText) - $previousLineBreak - 1; + $pointerSpacing = $column; + } throw new Compiler\Exception\UnrecognizedToken( - 'Unrecognized token "%s" at line 1 and column %d:' . + 'Unrecognized token "%s" at line %d and column %d:' . "\n" . '%s' . "\n" . - str_repeat(' ', mb_strlen(substr($text, 0, $offset))) . '↑', + str_repeat(' ', $pointerSpacing) . '↑', 0, [ mb_substr(substr($text, $offset), 0, 1), - $offset + 1, + $line, + $column + 1, $text ], 1, diff --git a/Llk/Parser.php b/Llk/Parser.php index ec35d1d2..88a4c42a 100644 --- a/Llk/Parser.php +++ b/Llk/Parser.php @@ -213,11 +213,12 @@ public function parse($text, $rule = null, $tree = true) } throw new Compiler\Exception\UnexpectedToken( - 'Unexpected token "%s" (%s) at line %d and column %d:' . + 'Unexpected token "%s" (%s:%s) at line %d and column %d:' . "\n" . '%s' . "\n" . str_repeat(' ', $column - 1) . '↑', 0, [ $token['value'], + $token['namespace'], $token['token'], $line, $column, From 224241865758a69350d9c619b316fd5aec3992a3 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 11:00:03 +0200 Subject: [PATCH 4/7] [BUGFIX] Allow colons in PCRE part of default namespace Fixes: #113 --- Llk/Llk.php | 2 +- Test/Unit/Llk/Llk.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Llk/Llk.php b/Llk/Llk.php index c4eb9482..94695158 100644 --- a/Llk/Llk.php +++ b/Llk/Llk.php @@ -314,7 +314,7 @@ public static function parsePP($pp, &$tokens, &$rules, &$pragmas, $streamName) $matches[3] . ')'; } - } elseif (0 !== preg_match('#^%token\h+(?:([^:]+):)?([^\h]+)\h+(.*?)(?:\h+->\h+(.*))?$#u', $line, $matches)) { + } elseif (0 !== preg_match('#^%token\h+(?:([^:\h]+):)?([^\h]+)\h+(.*?)(?:\h+->\h+(.*))?$#u', $line, $matches)) { if (empty($matches[1])) { $matches[1] = 'default'; } diff --git a/Test/Unit/Llk/Llk.php b/Test/Unit/Llk/Llk.php index 79db49d9..318f62f3 100644 --- a/Test/Unit/Llk/Llk.php +++ b/Test/Unit/Llk/Llk.php @@ -214,7 +214,8 @@ public function case_parse_tokens() '%token foobar1 bazqux1' . "\n" . '%token sourceNS1:foobar2 bazqux2' . "\n" . '%token sourceNS2:foobar3 bazqux3 -> destinationNS' . "\n" . - '%token foobar4 barqux4 -> destinationNS' + '%token foobar4 barqux4 -> destinationNS' . "\n" . + '%token foobar5 ns:bar -> destinationNS' ) ->when($result = SUT::parsePP($pp, $tokens, $rules, $pragmas, 'streamFoo')) ->then @@ -224,7 +225,8 @@ public function case_parse_tokens() ->isEqualTo([ 'default' => [ 'foobar1' => 'bazqux1', - 'foobar4:destinationNS' => 'barqux4' + 'foobar4:destinationNS' => 'barqux4', + 'foobar5:destinationNS' => 'ns:bar', ], 'sourceNS1' => [ 'foobar2' => 'bazqux2' From a17b7b1c5a830c05a6d85d2909e6d89148429be0 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 14:08:52 +0200 Subject: [PATCH 5/7] [TASK] Fix position of comments in YAML --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f68f38e..848b8ed5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,10 +45,10 @@ before_script: script: - composer install - vendor/bin/hoa test:run + # @todo: + # php-cs-fixer ^2.0 requires additional attribute `--allow-risky`, triggered by hoa/devtools + # php-cs-fixer ^1.13 is supported until PHP 7.1 max (hard-coded internally) - if [[ $ENABLE_DEVTOOLS ]]; then - # @todo: - # php-cs-fixer ^2.0 requires additional attribute `--allow-risky`, triggered by hoa/devtools - # php-cs-fixer ^1.13 is supported until PHP 7.1 max (hard-coded internally) composer global require require friendsofphp/php-cs-fixer:^1.13.0; vendor/bin/hoa devtools:cs --diff --dry-run .; fi From b4a13ad20be64d9f3d670bd180befb353254f353 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 14:20:27 +0200 Subject: [PATCH 6/7] [TASK] Disable devtools for the time being --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 848b8ed5..a6027501 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ jobs: - php: 5.6 - php: 7.0 - php: 7.1 - env: - - ENABLE_DEVTOOLS=true +# env: +# - ENABLE_DEVTOOLS=true - php: 7.2 - php: 7.3 - php: nightly From 14a4ca7261f02bd87f320170762d771c3de15312 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 6 Oct 2020 14:26:36 +0200 Subject: [PATCH 7/7] [TASK] Add PHP 7.4 to test matrix (expected to fail) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a6027501..39903749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ jobs: # - ENABLE_DEVTOOLS=true - php: 7.2 - php: 7.3 + - php: 7.4 - php: nightly allow_failures: # @todo hoa/test has to be adjusted/raised first concerning PHP 7.4 compatibility