classLemonParser
final class LemonParser
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(),
)Parameters
$text | LemonText | Removes what is not grammar |
$directives | LemonDirectives | Reads the tokens the grammar declares |
$rules | LemonRules | Reads the rules the grammar writes |
Test cases 11
LemonParserTest::testParseAliasesStrippedcoversLemonParserTest::testParseCommentsStrippedcoversLemonParserTest::testParseEmptyProductioncoversLemonParserTest::testParseExpandsInlineTokenAlternativescoversLemonParserTest::testParseFileReadsAGrammarFromDiskcoversLemonParserTest::testParseFileReportsAFileItCannotReadcoversLemonParserTest::testParseMultipleRulescoversLemonParserTest::testParseSimpleRulecoversLemonParserTest::testParseThrowsOnNoRulescoversLemonParserTest::testParseWithDirectivescoversLemonParserTest::testTerminalDetectioncovers
Calls 3
- new LemonText line 37
- new LemonDirectives line 38
- new LemonRules line 39
public function parse(string $input, list<string> $defines = []): GrammarReads 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
$input | string | Contents of the grammar file |
$defines | list<string> | Named parser-build definitions |
Returns
Grammar Grammar the file describesThrows
RuntimeException When source conditionals are malformedGrammarParseException When the file writes no rulesInvalidArgumentException When a rule is filed under a name other than its own left-hand sideTest cases 10
LemonParserTest::testParseAliasesStrippedcovers and callsLemonParserTest::testParseCommentsStrippedcovers and callsLemonParserTest::testParseEmptyProductioncovers and callsLemonParserTest::testParseExpandsInlineTokenAlternativescovers and callsLemonParserTest::testParseFileReadsAGrammarFromDiskcoversLemonParserTest::testParseMultipleRulescovers and callsLemonParserTest::testParseSimpleRulecovers and callsLemonParserTest::testParseThrowsOnNoRulescovers and callsLemonParserTest::testParseWithDirectivescovers and callsLemonParserTest::testTerminalDetectioncovers and calls
Called from 1
Calls 17
- new LemonSymbols line 60
- method-call LemonPreprocessor::process() line 61
- new LemonPreprocessor line 61
- new LemonCondition line 61
- method-call LemonText::withoutComments() line 61
- method-call LemonDirectives::declareInto() line 62
- method-call LemonRules::readFrom() line 63
- method-call LemonDirectives::tokenClasses() line 64
- static-call GrammarParseException::noRulesParsed() line 66
- function-call
array_key_firstline 70 - method-call LemonSymbols::isTerminal() line 81
- new Terminal line 81
- new NonTerminal line 81
- new Production line 83
- new ProductionRule line 85
- function-call
array_mapline 89 - new Grammar line 94
public function parseFile(string $path): GrammarReads a Lemon grammar file as a grammar.
Parameters
$path | string | Path of the grammar file |
Returns
Grammar Grammar the file describesThrows
RuntimeException When the grammar file cannot be readGrammarParseException When the file writes no rulesInvalidArgumentException When a rule is filed under a name other than its own left-hand sideTest cases 2
LemonParserTest::testParseFileReadsAGrammarFromDiskcovers and callsLemonParserTest::testParseFileReportsAFileItCannotReadcovers and calls
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
LemonParserTest::testParseAliasesStrippedcovers and callsLemonParserTest::testParseCommentsStrippedcovers and callsLemonParserTest::testParseEmptyProductioncovers and callsLemonParserTest::testParseExpandsInlineTokenAlternativescovers and callsLemonParserTest::testParseFileReadsAGrammarFromDiskcovers and callsLemonParserTest::testParseFileReportsAFileItCannotReadcovers and callsLemonParserTest::testParseMultipleRulescovers and callsLemonParserTest::testParseSimpleRulecovers and callsLemonParserTest::testParseThrowsOnNoRulescovers and callsLemonParserTest::testParseWithDirectivescovers and callsLemonParserTest::testTerminalDetectioncovers and calls