diff --git a/.travis.yml b/.travis.yml index 219a43d5..39903749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,26 +6,21 @@ branches: - trying - master -matrix: +jobs: include: - php: 5.6 - php: 7.0 - php: 7.1 - env: - - ENABLE_DEVTOOLS=true +# 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: + # @todo hoa/test has to be adjusted/raised first concerning PHP 7.4 compatibility + - php: 7.4 - php: nightly - - php: hhvm-3.12 - - php: hhvm fast_finish: true os: @@ -34,8 +29,6 @@ os: notifications: irc: "chat.freenode.net#hoaproject" -sudo: false - env: global: - secure: "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCoAO780/K7xbK3aPnHJmAyw9B3OGRFx2sSnl6umenksq4kmlzmPaUF9g3cHGcXpM5O33P8Tux//iYGASy5W8f5vbxbWSvlwV/aWFW9oSM6G/01gyW9vRFK0MnXpUMyCF9B4K/RJumGxm9BSxkAFFo2gPHIJrd08SOQeiDLygpcEQ==" @@ -53,7 +46,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 - composer global require friendsofphp/php-cs-fixer; + composer global require require friendsofphp/php-cs-fixer:^1.13.0; vendor/bin/hoa devtools:cs --diff --dry-run .; fi 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/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/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, 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'