classCodeReader
final class CodeReader
Reads host code as Bison's scanner does: braced code, a prologue, or one unit of either.
Braces nest, the digraphs <% and %> count as braces, and braces inside comments, strings and character literals do not count. A backslash-newline, which C splices away, may fall between the two characters of /*, * /, //, <%, %> and <<, and inside a string or character literal, exactly as scan-gram.l allows.
Constants§
public const SPLICE = '(?:\\\\[ \f\t\v]*\r?\n)*'Backslash-newlines that C splices away, as a regular expression fragment.
Methods§
public function braced(Cursor $cursor): stringReads the braced code the cursor is at and returns the text between the braces.
Parameters
$cursor | Cursor | Positioned at the opening brace |
Returns
string The code without its bracesThrows
SyntaxException When the file ends before the closing braceTest cases 5
Called from 2
Calls 7
- method-call Cursor::location() line 38
- method-call Cursor::take() line 39
- method-call Cursor::eof() line 42
- method-call CodeReader::unit() line 43
- method-call CodeReader::opens() line 44
- method-call CodeReader::closes() line 46
- static-call SyntaxException::unterminated() line 54
public function prologue(Cursor $cursor): stringReads the prologue the cursor is at and returns the text between %{ and %}.
Parameters
$cursor | Cursor | Positioned at `%{` |
Returns
string The code without its delimitersThrows
SyntaxException When the file ends before `%}`Test cases 2
Called from 1
Calls 6
- method-call Cursor::location() line 68
- method-call Cursor::take() line 69
- method-call Cursor::eof() line 71
- method-call Cursor::startsWith() line 72
- method-call CodeReader::unit() line 77
- static-call SyntaxException::unterminated() line 79
public function unit(Cursor $cursor): stringReads one unit of host code: a comment, a string, a character literal, a digraph, or one byte.
Parameters
$cursor | Cursor | Positioned at the unit |
Returns
string The unit as writtenThrows
SyntaxException When a comment, string or character literal is not closedTest cases 4
Called from 2
Calls 7
- method-call Cursor::location() line 93
- method-call Cursor::match() line 94
- class-const CodeReader::SPLICE() line 94
- static-call SyntaxException::unterminated() line 98
- method-call Cursor::peek() line 107
- function-call
preg_quoteline 109 - method-call Cursor::take() line 118
public function opens(string $unit): boolReports whether a unit opens a brace: { or the digraph <%, possibly spliced.
Parameters
$unit | string | The unit |
Returns
bool True for an opening braceTest cases 1
Called from 1
Calls 2
- function-call
preg_matchline 130 - class-const CodeReader::SPLICE() line 130
public function closes(string $unit): boolReports whether a unit closes a brace: } or the digraph %>, possibly spliced.
Parameters
$unit | string | The unit |
Returns
bool True for a closing braceTest cases 1
Called from 1
Calls 2
- function-call
preg_matchline 142 - class-const CodeReader::SPLICE() line 142
Test cases 21§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
CodeReaderTest::testBracedcallsCodeReaderTest::testBracedClosesOnTheBraceThatBalancesADigraphcallsCodeReaderTest::testBracedNeverClosesOnADigraphcallsCodeReaderTest::testBracedRejectsAnUnterminatedBlockcallsCodeReaderTest::testBracedSplicesBackslashNewlinescallsCodeReaderTest::testClosescallsCodeReaderTest::testOpenscallsCodeReaderTest::testProloguecallsCodeReaderTest::testPrologueRejectsAnUnterminatedBlockcallsCodeReaderTest::testUnitcallsCodeReaderTest::testUnitRejectsAnUnterminatedCharacterLiteralcallsCodeReaderTest::testUnitRejectsAnUnterminatedCommentcallsCodeReaderTest::testUnitRejectsAnUnterminatedStringcalls
Other tests reaching this symbol 8
BisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsScannerTestcallsDeclarationParserTestcallsGrammarParserTestcallsRuleParserTestcallsSymbolListParserTestcalls