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

Decodes the escape sequences of Bison's character and string literals, and writes them back.

Bison decodes octal \NNN, hexadecimal \xHH, the C escapes \a \b \f \n \r \t \v, the quoted \" \' \? \\, and universal characters \uXXXX and \UXXXXXXXX that name a single byte. Anything else after a backslash is an error.

Methods§

public function decode(string $body, Location $location): string

Decodes the body of a literal.

Parameters

$bodystringText between the quotes
$locationLocationWhere the literal begins, for the error

Returns

string The bytes the body stands for

Throws

SyntaxException When an escape is not one Bison accepts
Test cases 3
Called from 2
Calls 3
public function escape(string $rest, Location $location): array{string, int}

Decodes the escape that starts right after a backslash.

Parameters

$reststringText after the backslash
$locationLocationWhere the literal begins, for the error

Returns

array{string, int} The bytes and how many bytes of the text were used

Throws

SyntaxException When the escape is not one Bison accepts
Test cases 7
Called from 1
Calls 8
public function byte(int $code, string $escape, Location $location): string

Turns the number of an octal or hexadecimal escape into its byte, refusing what does not fit one.

Parameters

$codeintThe number
$escapestringThe escape as written, for the message
$locationLocationWhere the literal is, for the message

Returns

string The byte

Throws

SyntaxException When the number is above 255, which Bison rejects
Test cases 2
Called from 3
Calls 2
public function encode(string $bytes, string $quote): string

Writes bytes as the body of a literal, escaping what must be escaped.

Parameters

$bytesstringThe bytes
$quotestringThe quote the literal uses

Returns

string Text to write between the quotes
Test cases 1
Called from 2
Calls 3

Test cases 25§

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 12

Relations§

Instantiated in 2
Method calls 4
Type declarations 2