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

The token substitutions PostgreSQL's parser frontend makes by looking ahead.

A few words mean different things depending on what follows them: NOT before NULL is not the NOT of an expression, WITH before TIME is not the WITH of a CTE. PostgreSQL resolves this between its lexer and its parser by rewriting the first token once the second is known.

Generation and tokenizing both have to apply the same rewriting or they would disagree about what the same text means, and realization has to be able to walk it backwards to find the keyword a substituted token is spelled as.

Type Aliases§

LookaheadRule = array{token: string, followed_by: list<string>}

Methods§

public function __construct(private array<string, LookaheadRule> $rules)

Parameters

$rulesarray<string, LookaheadRule>Substitution by the token that triggers it
Test cases 1
public function normalized(list<string> $terminals): list<string>

Settles each terminal on the spelling its neighbour calls for.

Unlike applied(), this also walks a substitution backwards: a plan that asked for the substituted token where the follower does not call for it gets the base token, because that is what the text would read back as.

Parameters

$terminalslist<string>Terminals a derivation produced

Returns

list<string> The terminals with each substitution settled
Test cases 6
Called from 1
Calls 1
public function baseOf(string $terminal): string|null

Reports the token a substituted one is spelled as.

A substituted token has no keyword of its own; it borrows the spelling of the token it replaced, so realization has to ask which that was.

Parameters

$terminalstringTerminal to look up

Returns

string|null The token it substitutes for, or null when it substitutes for none
Test cases 4

Private surface 1§

Implementation details, listed for orientation only.

private array<string, LookaheadRule> $rules

Test cases 50§

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

Dedicated tests 21
Other tests reaching this symbol 29

Relations§

Instantiated in 1
Static calls 3
Method calls 2
Type declarations 3