classEscapes
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): stringDecodes the body of a literal.
Parameters
$body | string | Text between the quotes |
$location | Location | Where the literal begins, for the error |
Returns
string The bytes the body stands forThrows
SyntaxException When an escape is not one Bison acceptsTest cases 3
Called from 2
Calls 3
- function-call
strlenline 35 - function-call
substrline 42 - method-call Escapes::escape() line 43
public function escape(string $rest, Location $location): array{string, int}Decodes the escape that starts right after a backslash.
Parameters
$rest | string | Text after the backslash |
$location | Location | Where the literal begins, for the error |
Returns
array{string, int} The bytes and how many bytes of the text were usedThrows
SyntaxException When the escape is not one Bison acceptsTest cases 7
EscapesTest::testEscapecallsEscapesTest::testEscapeRejectsANullHexadecimalEscapecallsEscapesTest::testEscapeRejectsANullOctalEscapecallsEscapesTest::testEscapeRejectsANullUniversalCharactercallsEscapesTest::testEscapeRejectsANullWideUniversalCharactercallsEscapesTest::testEscapeRejectsANumberAboveOneBytecallsEscapesTest::testEscapeRejectsAWideUniversalCharactercalls
Called from 1
Calls 8
- function-call
preg_matchline 63 - method-call Escapes::byte() line 64
- function-call
octdecline 64 - function-call
strlenline 64 - function-call
hexdecline 67 - function-call
ltrimline 67 - function-call
substrline 67 - static-call SyntaxException::invalid() line 78
public function byte(int $code, string $escape, Location $location): stringTurns the number of an octal or hexadecimal escape into its byte, refusing what does not fit one.
Parameters
$code | int | The number |
$escape | string | The escape as written, for the message |
$location | Location | Where the literal is, for the message |
Returns
string The byteThrows
SyntaxException When the number is above 255, which Bison rejectsTest cases 2
Called from 3
Calls 2
- static-call SyntaxException::invalid() line 95
- function-call
chrline 98
public function encode(string $bytes, string $quote): stringWrites bytes as the body of a literal, escaping what must be escaped.
Parameters
$bytes | string | The bytes |
$quote | string | The quote the literal uses |
Returns
string Text to write between the quotesTest cases 1
EscapesTest::testEncodecalls
Called from 2
Test cases 25§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
EscapesTest::testBytecallsEscapesTest::testByteRejectsZerocallsEscapesTest::testDecodecallsEscapesTest::testDecodeRejectsAnUnknownEscapecallsEscapesTest::testDecodeRejectsATrailingBackslashcallsEscapesTest::testEncodecallsEscapesTest::testEscapecallsEscapesTest::testEscapeRejectsANullHexadecimalEscapecallsEscapesTest::testEscapeRejectsANullOctalEscapecallsEscapesTest::testEscapeRejectsANullUniversalCharactercallsEscapesTest::testEscapeRejectsANullWideUniversalCharactercallsEscapesTest::testEscapeRejectsANumberAboveOneBytecallsEscapesTest::testEscapeRejectsAWideUniversalCharactercalls
Other tests reaching this symbol 12
BisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsDeclarationPrinterTestcallsPrinterTestcallsRhsPrinterTestcallsSymbolPrinterTestcallsScannerTestcallsDeclarationParserTestcallsGrammarParserTestcallsRuleParserTestcallsSymbolListParserTestcalls
Relations§
Instantiated in 2
Method calls 4
- method-call BisonParser\Printer\SymbolPrinter::symbol() packages/bison-parser/src/Printer/SymbolPrinter.php:41
- method-call BisonParser\Printer\SymbolPrinter::string() packages/bison-parser/src/Printer/SymbolPrinter.php:55
- method-call BisonParser\Scanner\Scanner::literal() packages/bison-parser/src/Scanner/Scanner.php:270
- method-call BisonParser\Scanner\Scanner::literal() packages/bison-parser/src/Scanner/Scanner.php:288