classRhsItem
final class RhsItem
Public API: explicitly declared with
@visibility public.One position on the right-hand side of a rule.
Usually one symbol, but Lemon lets several terminals share a position, written A|B|C; the position then matches any of them. An alias in parentheses names the value of the position in the rule's code.
$file = (new \LemonParser\Parser())->parse("cmd ::= BEGIN|START trans_opt(X).\n");
$items = $file->rules()[0]->items;
[$items[0]->isMultiTerminal(), array_map(static fn ($symbol) => $symbol->name, $items[0]->symbols), $items[1]->alias] // => [true, ['BEGIN', 'START'], 'X']Properties§
public non-empty-list<Symbol> $symbolspublic string|null $aliasMethods§
public function __construct(public non-empty-list<Symbol> $symbols, public string|null $alias)Parameters
$symbols | non-empty-list<Symbol> | The symbol, or the terminals that share the position |
$alias | string|null | The name given to the position's value, or null |
public function isMultiTerminal(): boolReports whether several terminals share the position.
Returns
bool True for `A|B` style positionsTest cases 1
Calls 1
- function-call
countline 40
Test cases 16§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 14
RuleTest::testSymbolscallsLemonGrammarCompilerTestcallsLemonGrammarReaderTestcallsParserTestcallsPrinterTest::testPrintcallsRulePrinterTest::testItemcallsRulePrinterTest::testPrintcallsGrammarReaderTestcallsRuleReaderTest::testAliascallsRuleReaderTest::testAliasRejectsABadNamecallsRuleReaderTest::testAliasRejectsAMissingClosercallsRuleReaderTest::testCompoundcallsRuleReaderTest::testCompoundRejectsANonterminalcallsRuleReaderTest::testReadcalls