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

Writes a parse table to bytes and reads it back.

The layout is little-endian throughout: a header of counts, the symbol names, the rules, the default of each state, the fallbacks, the byte offset of each row, and then the rows themselves. A row lists its symbols as 16-bit numbers and then its action codes as 32-bit integers, so a row can be unpacked with two calls.

Constants§

public const MAGIC = 'SQLPTBL1'

The bytes every encoded table starts with.

Methods§

public function encode(ParseTable $table): string

Encodes a table.

Parameters

$tableParseTableTable to write

Returns

string The bytes
Test cases 2
Called from 1
Calls 6
public static function integers(string $format, string $bytes): list<int>

Unpacks a run of integers.

Parameters

$formatstringPack format of one repeated integer, such as `v*`
$bytesstringThe bytes

Returns

list<int> The integers, none for empty bytes

Throws

RuntimeException When the bytes are not a whole number of integers
Test cases 2
Called from 4
Calls 4
public function encodeRow(array<int, int> $row): string

Encodes the explicit actions of one state.

Parameters

$rowarray<int, int>Action code by symbol number

Returns

string The bytes
Test cases 2
Called from 1
Calls 4
public function decode(string $bytes): ParseTable

Decodes a table.

Parameters

$bytesstringBytes as encode() wrote them

Returns

ParseTable The table, with its rows decoded on demand

Throws

RuntimeException When the bytes are not an encoded table
Test cases 3
Called from 1
Calls 12

Test cases 12§

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

Dedicated tests 6
Other tests reaching this symbol 6

Relations§

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