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

Represents a formal grammar for SQL generation.

A formal grammar G = (N, Sigma, P, S) where:

  • N: Set of non-terminal symbols (keys of ruleMap)
  • Sigma: Set of terminal symbols (implicitly defined by Symbol types)
  • P: Set of production rules (ruleMap)
  • S: Start symbol (startSymbol)

Properties§

public string $startSymbol
public array<string, ProductionRule> $ruleMap
public array<string, string> $aliases = []

Methods§

public function __construct(
    public string $startSymbol,
    public array<string, ProductionRule> $ruleMap,
    public array<string, string> $aliases = [],
)

Parameters

$startSymbolstringThe grammar's start symbol
$ruleMaparray<string, ProductionRule>Non-terminal name => ProductionRule
$aliasesarray<string, string>Specialized rule => original grammar rule

Throws

InvalidArgumentException When a rule is filed under a name other than its own left-hand side
Calls 1
  • new InvalidArgumentException line 37
public function __unserialize(array{startSymbol: string, ruleMap: array<string, ProductionRule>, aliases?: array<string, string>} $data): void

Reads both historical grammar resources and newly specialized grammars.

Parameters

$dataarray{startSymbol: string, ruleMap: array<string, ProductionRule>, aliases?: array<string, string>}
public function sourceRule(string $rule): string

Names the source rule behind a specialized subtree.

Parameters

$rulestring

Returns

string
Called from 10
public static function loadFromFile(string $path): self

Load a pre-compiled grammar from a file path.

Parameters

$pathstring

Returns

self

Throws

RuntimeException When the compiled grammar is missing, empty, or is not a grammar
Test cases 4
Called from 3
Calls 4
public function identified(): self

Assigns original ordinals before any dialect adapter filters alternatives.

Returns

self
Test cases 47
Calls 3

Test cases 213§

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

Dedicated tests 9
Other tests reaching this symbol 204

Relations§

Instantiated in 4
Static calls 3
Method calls 13
Type declarations 36