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

Renders a reconstructed statement as marked-up SQL.

The statement is rendered from the pattern rather than from the text it displays as, so a gap keeps what is known about it. A gap is a claim about the analysis and not about the statement, and rendering it as an ordinary {$} in the middle of the SQL hides which of the two a reader is looking at. Here it is marked, tinted by where the value came from, and says so when pointed at. The tokens are written in the classes doc-ui highlights.

Constants§

public const TOKENS = '/(?<com>--[^\n]*|\#[^\n]*|\/\*.*?\*\/)|(?<str>\'(?:\'\'|\\\\.|[^\'])*\'|"(?:""…

How the tokens of a resolved run are told apart.

Methods§

public function __construct(?HtmlText $text = null)

Wires the highlighter to the escaping it writes through.

Parameters

$text?HtmlText
Calls 1
public function plain(list<StatementPart> $parts): string
public function inline(list<StatementPart> $parts): string

The whole statement on one line, for a listing.

Parameters

$partslist<StatementPart>

Returns

string
Test cases 1
Calls 3
public function highlight(string $sql): string

One resolved run of SQL, with its tokens marked.

The run is tokenized before it is escaped, not after. Escaping first turns an apostrophe into an entity, and marking a token inside an entity breaks it, so what a reader sees is the escaping rather than the SQL.

Parameters

$sqlstring

Returns

string
Test cases 2
Called from 1
Calls 7
public function captured(array<array-key, array{string, int}> $match): array<string, string>

The named captures of a match, without the offsets they were captured with.

Parameters

$matcharray<array-key, array{string, int}>

Returns

array<string, string>
Test cases 1
Called from 1
Calls 1
public function token(array<string, string> $match): string

One matched token, wrapped in the class its kind is written with.

Parameters

$matcharray<string, string>

Returns

string
Test cases 2
Called from 1
Calls 3
public function isKeyword(string $word): bool

Whether a word is one SQL writes as a keyword.

Parameters

$wordstring

Returns

bool
Test cases 1
Called from 1
Calls 4
public function holeLabel(StatementPart $gap): string
public function holeRole(string $origin): string

The tone a gap of that origin is tinted by.

A value from outside the program is the one thing in a statement worth a warning colour; a call the analysis never reached is not a claim about the statement at all and is written in no colour; every other gap is a caution.

Parameters

$originstring

Returns

string
Test cases 1
Called from 1

Private surface 3§

Implementation details, listed for orientation only.

private const KEYWORDS = 'SELECT|INSERT|UPDATE|DELETE|REPLACE|MERGE|TRUNCATE|CREATE|ALTER|DROP|RENAME|CA…
private const TOKEN_CLASSES = ['com' => 'tok-com', 'str' => 'tok-str', 'qid' => 'tok-id', 'ph' => 'tok-var', …
private HtmlText $text

Test cases 29§

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

Dedicated tests 13
Other tests reaching this symbol 16

Relations§

Instantiated in 3
Method calls 5
Constant reads 1
Type declarations 4