Printer
loreline.Printer (Class)
A code printer that converts AST nodes back into formatted Loreline source code.
Handles indentation, newlines, and pretty-printing of all node types.
Instance Members
Set to false to ignore comments.
Resets the printer to its initial state.
Increases the current indentation level by one.
Decreases the current indentation level by one.
Writes a string to the output buffer, handling indentation if at start of line.
| Name |
Type |
Description |
s |
String |
String to write |
| Returns |
Description |
| Printer |
This printer instance for chaining |
Writes a line break to the output.
| Returns |
Description |
| Printer |
This printer instance for chaining |
Adds a newline to the output, limiting consecutive blank lines to 1.
| Returns |
Description |
| Printer |
This printer instance for chaining |
Adds indentation at the current level to the output.
| Returns |
Description |
| Printer |
This printer instance for chaining |
Alias for newline().
| Returns |
Description |
| Printer |
This printer instance for chaining |
Returns the current content of the output buffer.
| Returns |
Description |
| String |
Generated source code |
Main entry point for printing an AST node to source code.
| Name |
Type |
Description |
node |
Node |
Root node to print |
| Returns |
Description |
| String |
Generated source code as string |
Creates a new code printer with customizable formatting options.
| Name |
Type |
Default |
Description |
indent |
String |
" " |
String used for each level of indentation (default: 4 spaces) |
newline |
String |
"\n" |
String used for line breaks (default: \n) |
Private Members
Dispatches a node to its appropriate printing function based on type.
| Name |
Type |
Default |
Description |
node |
Node |
|
Node to print |
sameLine |
Bool |
false |
|
Prints any leading comments attached to a node.
| Name |
Type |
Description |
node |
AstNode |
Node with potential comments |
Prints any trailing comments attached to a node.
| Name |
Type |
Description |
node |
AstNode |
Node with potential comments |
Prints an import statement.
Prints a complete Loreline script node.
| Name |
Type |
Description |
script |
Script |
Script node to print |
Prints a state declaration node.
| Name |
Type |
Description |
state |
NStateDecl |
State declaration to print |
Prints a character declaration node.
| Name |
Type |
Description |
char |
NCharacterDecl |
Character declaration to print |
Prints a beat declaration node.
| Name |
Type |
Description |
beat |
NBeatDecl |
Beat declaration to print |
Prints a function declaration node.
| Name |
Type |
Description |
func |
NFunctionDecl |
Function declaration to print |
printTextStatement(text: NTextStatement): Void
Prints a text statement node.
Prints a dialogue statement node.
Prints a choice statement node.
Prints an import statement node.
Prints a choice option node.
| Name |
Type |
Description |
option |
NChoiceOption |
Choice option to print |
Prints an if statement node, handling both simple if and if-else structures.
| Name |
Type |
Default |
Description |
ifStmt |
NIfStatement |
|
If statement to print |
isElseIf |
Bool |
false |
Whether this is part of an else-if chain |
Prints a transition node.
Prints an insertion node.
| Name |
Type |
Description |
insert |
NInsertion |
Insertion to print |
Prints a string literal node, handling both plain strings and strings with quotes.
Prints a literal value node (numbers, booleans, arrays, objects).
| Name |
Type |
Description |
lit |
NLiteral |
Literal node to print |
Prints a field access expression (object.field).
| Name |
Type |
Description |
access |
NAccess |
Field access node to print |
Prints an array access expression (array[index]).
| Name |
Type |
Description |
access |
NArrayAccess |
Array access node to print |
Prints a function call expression.
| Name |
Type |
Description |
call |
NCall |
Function call node to print |
Prints a binary operation expression (a + b, a && b, etc).
Handles operator precedence with parentheses when needed.
| Name |
Type |
Default |
Description |
binary |
NBinary |
|
Binary operation node to print |
skipParen |
Bool |
false |
|
Prints a unary operation expression (!x, -x).
| Name |
Type |
Description |
unary |
NUnary |
Unary operation node to print |
Prints an assignment expression (a = b, a += b).
| Name |
Type |
Description |
assign |
NAssign |
Assignment node to print |
Prints an in-line expression optionally wrapped in parentheses.
| Name |
Type |
Description |
expr |
NExpr |
Expression to wrap in parentheses |
parens |
Bool |
|
getOperator(op: Anonymous): String
Converts a token type to its corresponding operator string representation.
| Name |
Type |
Description |
op |
Anonymous |
Token type to convert |
| Returns |
Description |
| String |
String representation of the operator |