WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"email": "[email protected]"
}
],

"require": {
"php": "^7.0"
"php": "^8.0"
},

"autoload": {
"psr-4": { "WouterJ\\Peg\\": "src/" }
},
"autoload-dev": {
"psr-4": { "WouterJ\\Peg\\": "tests/" }
},
"require-dev": {
"phpunit/phpunit": "^9.6"
}
}
4 changes: 2 additions & 2 deletions src/PegGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct()
return $nested[0];
}

return ['choice', array_merge([$nested[0]], array_map('next', $nested[1]))];
return ['choice', array_merge([$nested[0]], array_map(fn($param) => next($param), $nested[1]))];
}),
// Sequence <- Prefix*
new Definition('Sequence', ['repeat', ['identifier', 'Prefix']], function ($nested) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public function __construct()
['identifier', 'Spacing'],
]],
]], function ($nested) {
return ['literal', implode('', array_map('next', $nested[1]))];
return ['literal', implode('', array_map(fn($param) => next($param), $nested[1]))];
}),
// Class <- ’[’ (!’]’ Range)* ’]’ Spacing
new Definition('Class', ['sequence', [
Expand Down
4 changes: 3 additions & 1 deletion tests/GrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace WouterJ\Peg;

use PHPUnit\Framework\TestCase;

/**
* @author Wouter de Jong <[email protected]>
*/
class GrammarTest extends \PHPUnit_Framework_TestCase
class GrammarTest extends TestCase
{
public function testPredicates()
{
Expand Down
17 changes: 8 additions & 9 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
namespace WouterJ\Peg;

use WouterJ\Peg\Exception\DefinitionException;
use PHPUnit\Framework\TestCase;

/**
* @author Wouter de Jong <[email protected]>
*/
class ParserTest extends \PHPUnit_Framework_TestCase
class ParserTest extends TestCase
{
public function testLiteral()
{
Expand Down Expand Up @@ -187,12 +188,11 @@ public function testActions()
$this->assertSame(12, $parser->parse('Int', '12')->value());
}

/**
* @expectedException \WouterJ\Peg\Exception\DefinitionException
* @expectedExceptionMessage did you mean one of these `Everything`?
*/
public function testUnknownDefinition()
{
$this->expectExceptionMessage("did you mean one of these `Everything`?");
$this->expectException(\WouterJ\Peg\Exception\DefinitionException::class);

$parser = new Parser([
new Definition('Everything', ['any']),
new Definition('Digit', ['characterClass', '0-9']),
Expand All @@ -201,12 +201,11 @@ public function testUnknownDefinition()
$parser->parse('Everyting', 'a');
}

/**
* @expectedException \WouterJ\Peg\Exception\DefinitionException
* @expectedExceptionMessageRegExp /^Invalid definition `Foo`: Undefined operator `undefined`\./
*/
public function testInvalidDefinition()
{
$this->expectExceptionMessageMatches("/^Invalid definition `Foo`: Undefined operator `undefined`\./");
$this->expectException(\WouterJ\Peg\Exception\DefinitionException::class);

$parser = new Parser([
new Definition('Mine', ['identifier', 'Custom']),
new Definition('Custom', ['identifier', 'Foo']),
Expand Down
4 changes: 3 additions & 1 deletion tests/PegGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace WouterJ\Peg;

use PHPUnit\Framework\TestCase;

/**
* @author Wouter de Jong <[email protected]>
*/
class PegGrammarTest extends \PHPUnit_Framework_TestCase
class PegGrammarTest extends TestCase
{
/** @dataProvider getGrammars */
public function testGrammar($filePath)
Expand Down