final class LemonParser
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Reads Lemon source declarations and production rules into a grammar.

Lemon writes one alternative per line — lhs(alias) ::= symbol ... . — so the alternatives of a rule are gathered by name rather than grouped in the file. It declares its tokens in directives, spells them in capitals, and carries the C its parser is built from alongside the rules. Reading the declarations, reading the rules, and remembering what each name turned out to be are three subjects, and this brings their answers together.

Methods§

public function __construct(
    private LemonText $text = new \SqlFaker\Compiler\Lemon\LemonText(),
    private LemonDirectives $directives = new \SqlFaker\Compiler\Lemon\LemonDirectives(),
    private LemonRules $rules = new \SqlFaker\Compiler\Lemon\LemonRules(),
)
public function parse(string $input, list<string> $defines = []): Grammar

Reads a Lemon grammar as a grammar.

The first rule written is the start symbol, which is what Lemon itself assumes when no other is named.

Parameters

$inputstringContents of the grammar file
$defineslist<string>Named parser-build definitions

Returns

Grammar Grammar the file describes

Throws

RuntimeException When source conditionals are malformed
GrammarParseException When the file writes no rules
InvalidArgumentException When a rule is filed under a name other than its own left-hand side
Test cases 10
Called from 1
Calls 17
public function parseFile(string $path): Grammar

Reads a Lemon grammar file as a grammar.

Parameters

$pathstringPath of the grammar file

Returns

Grammar Grammar the file describes

Throws

RuntimeException When the grammar file cannot be read
GrammarParseException When the file writes no rules
InvalidArgumentException When a rule is filed under a name other than its own left-hand side
Test cases 2
Calls 5

Private surface 3§

Implementation details, listed for orientation only.

private LemonText $text = new \SqlFaker\Compiler\Lemon\LemonText()
private LemonDirectives $directives = new \SqlFaker\Compiler\Lemon\LemonDirectives()
private LemonRules $rules = new \SqlFaker\Compiler\Lemon\LemonRules()

Test cases 11§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 11