classPrinter
final class Printer
Public API: explicitly declared with
@visibility public.Writes a tree back as a grammar file Lemon reads to the same tree.
Every rule and declaration goes on a line of its own, in file order. Printing is stable: the printed text reads back to a tree that prints the same.
$file = (new \LemonParser\Parser())->parse("%left PLUS.\nexpr(A) ::= expr(B) PLUS expr(C). [PLUS] { A = B + C; } // add\n");
(new \LemonParser\Printer\Printer())->print($file) // => "%left PLUS.\nexpr(A) ::= expr(B) PLUS expr(C). [PLUS] { A = B + C; }\n"Methods§
public function __construct(
private DeclarationPrinter $declarations = new \LemonParser\Printer\DeclarationPrinter(),
private RulePrinter $rules = new \LemonParser\Printer\RulePrinter(),
)Parameters
$declarations | DeclarationPrinter | Writes declarations |
$rules | RulePrinter | Writes rules |
Calls 2
public function print(GrammarFile $file): stringWrites the whole file.
Parameters
$file | GrammarFile | The tree |
Returns
string The grammar file, one item per lineTest cases 2
ParseBench::benchRoundTripcallsPrinterTest::testPrintcalls
Calls 2
- method-call RulePrinter::print() line 46
- method-call DeclarationPrinter::print() line 46
Private surface 2§
Implementation details, listed for orientation only.
private DeclarationPrinter $declarations = new \LemonParser\Printer\DeclarationPrinter()private RulePrinter $rules = new \LemonParser\Printer\RulePrinter()Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
PrinterTest::testPrintcalls
Other tests reaching this symbol 4
ParseBench::benchRoundTripcallsParseBench::setUpcallsLemonGrammarCompilerTestcallsLemonGrammarReaderTestcalls