Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
60.00% |
3 / 5 |
ShellParser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2.26 | |
60.00% |
3 / 5 |
parse | |
0.00% |
0 / 1 |
2.26 | |
60.00% |
3 / 5 |
<?php | |
namespace Shellbox\ShellParser; | |
use Wikimedia\WikiPEG\SyntaxError; | |
/** | |
* Top-level entry for shell command parsing | |
*/ | |
class ShellParser { | |
/** | |
* Parse a shell command | |
* | |
* @param string $command | |
* @return SyntaxTree | |
*/ | |
public function parse( string $command ) { | |
$peg = new PEGParser; | |
try { | |
$node = $peg->parse( $command ); | |
} catch ( SyntaxError $e ) { | |
throw new ShellSyntaxError( $e->getMessage(), $e->location->start, $command ); | |
} | |
return new SyntaxTree( $node ); | |
} | |
} |