Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Adjust testing state, enhance exception context, fix PCRE issue #114

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,8 +29,6 @@ os:
notifications:
irc: "chat.freenode.net#hoaproject"

sudo: false

env:
global:
- secure: "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCoAO780/K7xbK3aPnHJmAyw9B3OGRFx2sSnl6umenksq4kmlzmPaUF9g3cHGcXpM5O33P8Tux//iYGASy5W8f5vbxbWSvlwV/aWFW9oSM6G/01gyW9vRFK0MnXpUMyCF9B4K/RJumGxm9BSxkAFFo2gPHIJrd08SOQeiDLygpcEQ=="
Expand All @@ -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
17 changes: 14 additions & 3 deletions Llk/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Llk/Llk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
3 changes: 2 additions & 1 deletion Llk/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions Test/Unit/Llk/Llk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down