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.

Printing a grammar backdoctest
$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

$declarationsDeclarationPrinterWrites declarations
$rulesRulePrinterWrites rules
Calls 2
public function print(GrammarFile $file): string

Writes the whole file.

Parameters

$fileGrammarFileThe tree

Returns

string The grammar file, one item per line
Test cases 2
Calls 2

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
Other tests reaching this symbol 4