classLemonSymbols
final class LemonSymbols
Remembers which names a Lemon grammar uses as tokens and which as rules.
Lemon does not declare every symbol. It declares its tokens, and everything else is a rule if some rule is written for it, so what a name means is only known once the whole file has been read. A reader therefore says what it has learned as it goes, and the question "is this a terminal" is answered here rather than by whichever reader happens to be looking at the name.
Methods§
public function declareToken(string $name): voidRecords that a name is a token.
Parameters
$name | string | Token name as the grammar spells it |
Test cases 3
Called from 3
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:51
- method-call SqlFaker\Compiler\Lemon\LemonRules::alternatives() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:105
- method-call SqlFaker\Compiler\Lemon\LemonSymbols::declareTokensOn() packages/sql-faker/src/Compiler/Lemon/LemonSymbols.php:66
public function declareRule(string $name): voidRecords that a name is a rule.
Parameters
$name | string | Rule name as the grammar spells it |
Test cases 1
LemonSymbolsTest::testDeclareRuleMakesACapitalisedNameANonTerminalcovers and calls
Called from 3
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:45
- method-call SqlFaker\Compiler\Lemon\LemonRules::readFrom() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:53
- method-call SqlFaker\Compiler\Lemon\LemonRules::alternatives() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:107
public function declareTokensOn(string $line, string $splitPattern): voidRecords every token named on one line of a directive.
A directive lists its tokens separated by whitespace or, for a token class, by an alternation bar, and the line may end in the period Lemon uses to close a declaration. Anything on such a line that is not spelled like a token is not one.
Parameters
$line | string | Everything the directive named |
$splitPattern | string | Pattern separating one name from the next |
Test cases 2
LemonSymbolsTest::testDeclareTokensOnIgnoresWhatIsNotSpelledLikeATokencovers and callsLemonSymbolsTest::testDeclareTokensOnReadsEveryNameADirectiveListscovers and calls
Called from 2
Calls 4
- function-call
preg_splitline 59 - function-call
trimline 59 - static-call LemonSymbols::isTokenName() line 65
- method-call LemonSymbols::declareToken() line 66
public function isTerminal(string $name): boolReports whether a name stands for a token rather than a rule.
What the grammar said outright wins. A name nothing said anything about falls back to Lemon's spelling convention.
Parameters
$name | string | Symbol name to judge |
Returns
bool True when the name stands for a tokenTest cases 11
LemonDirectivesTest::testDeclareIntoReadsAClassAndTheTokensItStandsForcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedAsAFallbackcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedOutrightcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedWhileGivingThemAPrecedencecallsLemonDirectivesTest::testDeclareIntoReadsTheWildcardTokencallsLemonRulesTest::testReadFromTellsTheSymbolTableWhatEachNameTurnedOutToBecallsLemonSymbolsTest::testDeclareRuleMakesACapitalisedNameANonTerminalcovers and callsLemonSymbolsTest::testDeclareTokenMakesALowercaseNameATerminalcovers and callsLemonSymbolsTest::testDeclareTokensOnIgnoresWhatIsNotSpelledLikeATokencovers and callsLemonSymbolsTest::testDeclareTokensOnReadsEveryNameADirectiveListscovers and callsLemonSymbolsTest::testIsTerminalFallsBackToTheSpellingConventionForAnUnknownNamecovers and calls
Called from 1
Calls 1
- static-call LemonSymbols::isTokenName() line 90
public static function isTokenName(string $name): boolReports whether a name is spelled the way Lemon spells a token.
Parameters
$name | string | Symbol name to judge |
Returns
bool True when the name is written in capitalsTest cases 5
LemonSymbolsTest::testDeclareTokensOnIgnoresWhatIsNotSpelledLikeATokencoversLemonSymbolsTest::testDeclareTokensOnReadsEveryNameADirectiveListscoversLemonSymbolsTest::testIsTerminalFallsBackToTheSpellingConventionForAnUnknownNamecoversLemonSymbolsTest::testIsTokenNameAcceptsANameWrittenInCapitalscovers and callsLemonSymbolsTest::testIsTokenNameRejectsANameThatIsNotWrittenInCapitalscovers and calls
Called from 3
- static-call SqlFaker\Compiler\Lemon\LemonRules::alternatives() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:104
- static-call SqlFaker\Compiler\Lemon\LemonSymbols::declareTokensOn() packages/sql-faker/src/Compiler/Lemon/LemonSymbols.php:65
- static-call SqlFaker\Compiler\Lemon\LemonSymbols::isTerminal() packages/sql-faker/src/Compiler/Lemon/LemonSymbols.php:90
Calls 1
- function-call
preg_matchline 102
Private surface 2§
Implementation details, listed for orientation only.
private array<string, true> $tokens = []private array<string, true> $rules = []Test cases 19§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
LemonSymbolsTest::testDeclareRuleMakesACapitalisedNameANonTerminalcovers and callsLemonSymbolsTest::testDeclareTokenMakesALowercaseNameATerminalcovers and callsLemonSymbolsTest::testDeclareTokensOnIgnoresWhatIsNotSpelledLikeATokencovers and callsLemonSymbolsTest::testDeclareTokensOnReadsEveryNameADirectiveListscovers and callsLemonSymbolsTest::testIsTerminalFallsBackToTheSpellingConventionForAnUnknownNamecovers and callsLemonSymbolsTest::testIsTokenNameAcceptsANameWrittenInCapitalscovers and callsLemonSymbolsTest::testIsTokenNameRejectsANameThatIsNotWrittenInCapitalscovers and calls
Other tests reaching this symbol 12
LemonDirectivesTest::testDeclareIntoReadsAClassAndTheTokensItStandsForcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedAsAFallbackcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedOutrightcallsLemonDirectivesTest::testDeclareIntoReadsTheTokensNamedWhileGivingThemAPrecedencecallsLemonDirectivesTest::testDeclareIntoReadsTheWildcardTokencallsLemonParserTestcallsLemonRulesTest::testAlternativesIgnoresAPositionThatConfiguresTheParsercallsLemonRulesTest::testAlternativesMultipliesOutEachAlternationPositioncallsLemonRulesTest::testReadFromDropsTheAliasASymbolCarriescallsLemonRulesTest::testReadFromGathersTheAlternativesOfOneRuleWrittenOnSeveralLinescallsLemonRulesTest::testReadFromReadsARuleThatWritesNothingcallsLemonRulesTest::testReadFromTellsTheSymbolTableWhatEachNameTurnedOutToBecalls
Relations§
Instantiated in 1
Static calls 1
Method calls 8
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:37
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:45
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:46
- method-call SqlFaker\Compiler\Lemon\LemonDirectives::declareInto() packages/sql-faker/src/Compiler/Lemon/LemonDirectives.php:51
- method-call SqlFaker\Compiler\Lemon\LemonParser::parse() packages/sql-faker/src/Compiler/Lemon/LemonParser.php:81
- method-call SqlFaker\Compiler\Lemon\LemonRules::readFrom() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:53
- method-call SqlFaker\Compiler\Lemon\LemonRules::alternatives() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:105
- method-call SqlFaker\Compiler\Lemon\LemonRules::alternatives() packages/sql-faker/src/Compiler/Lemon/LemonRules.php:107