Debian Codegraph @

vendor/wikimedia/shellbox/src/ShellParser/ShellParser.php

raw
1 <?php
2
3 namespace Shellbox\ShellParser;
4
5 use Wikimedia\WikiPEG\SyntaxError;
6
7 /**
8 * Top-level entry for shell command parsing
9 */
10 class ShellParser {
11 /**
12 * Parse a shell command
13 *
14 * @param string $command
15 * @return SyntaxTree
16 */
17 public function parse( string $command ) {
18 $peg = new PEGParser;
19 try {
20 $node = $peg->parse( $command );
21 } catch ( SyntaxError $e ) {
22 throw new ShellSyntaxError( $e->getMessage(), $e->location->start, $command );
23 }
24 return new SyntaxTree( $node );
25 }
26 }