final class Symbol
Public API: explicitly declared with @visibility public.

A grammar symbol named where it is written.

Lemon tells terminals from nonterminals by the first letter of the name: an upper-case letter starts a terminal, a lower-case letter a nonterminal.

Telling a terminal from a nonterminaldoctest
$file = (new \LemonParser\Parser())->parse("expr ::= expr PLUS expr.\n");
    $rule = $file->rules()[0];
    [$rule->lhs->isTerminal(), $rule->items[1]->symbols[0]->isTerminal()] // => [false, true]

Properties§

public string $name
public Location $location

Methods§

public function __construct(public string $name, public Location $location)

Parameters

$namestringThe name as written
$locationLocationWhere it is written
public function isTerminal(): bool

Reports whether the name starts with an upper-case letter, which makes it a terminal.

Returns

bool True for a terminal
Test cases 1
Calls 1
public function isNonterminal(): bool

Reports whether the name starts with a lower-case letter, which makes it a nonterminal.

Returns

bool True for a nonterminal
Test cases 1
Calls 1

Test cases 43§

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 41

Relations§

Instantiated in 12
Type declarations 12