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

enableComments: Bool

Set to false to ignore comments.


clear(): Void

Resets the printer to its initial state.


indent(): Void

Increases the current indentation level by one.


unindent(): Void

Decreases the current indentation level by one.


write(s: String): Printer

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

writeln(): Printer

Writes a line break to the output.

Returns Description
Printer This printer instance for chaining

newline(): Printer

Adds a newline to the output, limiting consecutive blank lines to 1.

Returns Description
Printer This printer instance for chaining

tab(): Printer

Adds indentation at the current level to the output.

Returns Description
Printer This printer instance for chaining

line(): Printer

Alias for newline().

Returns Description
Printer This printer instance for chaining

toString(): String

Returns the current content of the output buffer.

Returns Description
String Generated source code

print(node: Node): String

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

new(?indent: String = " ", ?newline: String = "\n"): Void

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

printNode(node: Node, ?sameLine: Bool = false): Void

Dispatches a node to its appropriate printing function based on type.

Name Type Default Description
node Node Node to print
sameLine Bool false

printLeadingComments(node: AstNode): Void

Prints any leading comments attached to a node.

Name Type Description
node AstNode Node with potential comments

printTrailingComments(node: AstNode): Void

Prints any trailing comments attached to a node.

Name Type Description
node AstNode Node with potential comments

printImport(imp: NImportStatement): Void

Prints an import statement.

Name Type Description
imp NImportStatement Import statement node

printScript(script: Script): Void

Prints a complete Loreline script node.

Name Type Description
script Script Script node to print

printStateDecl(state: NStateDecl): Void

Prints a state declaration node.

Name Type Description
state NStateDecl State declaration to print

printCharacterDecl(char: NCharacterDecl): Void

Prints a character declaration node.

Name Type Description
char NCharacterDecl Character declaration to print

printBeatDecl(beat: NBeatDecl): Void

Prints a beat declaration node.

Name Type Description
beat NBeatDecl Beat declaration to print

printFunctionDecl(func: NFunctionDecl): Void

Prints a function declaration node.

Name Type Description
func NFunctionDecl Function declaration to print

printTextStatement(text: NTextStatement): Void

Prints a text statement node.

Name Type Description
text NTextStatement Text statement to print

printDialogueStatement(dialogue: NDialogueStatement): Void

Prints a dialogue statement node.

Name Type Description
dialogue NDialogueStatement Dialogue statement to print

printChoiceStatement(choice: NChoiceStatement): Void

Prints a choice statement node.

Name Type Description
choice NChoiceStatement Choice statement to print

printImportStatement(imp: NImportStatement): Void

Prints an import statement node.

Name Type Description
imp NImportStatement Import statement to print

printChoiceOption(option: NChoiceOption): Void

Prints a choice option node.

Name Type Description
option NChoiceOption Choice option to print

printIfStatement(ifStmt: NIfStatement, ?isElseIf: Bool = false): Void

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

needsEmptyLines(node: AstNode): Bool
Name Type
node AstNode
Returns
Bool

printTransition(trans: NTransition, sameLine: Bool): Void

Prints a transition node.

Name Type Description
trans NTransition Transition to print
sameLine Bool

printInsertion(insert: NInsertion): Void

Prints an insertion node.

Name Type Description
insert NInsertion Insertion to print

printStringLiteral(str: NStringLiteral): Void

Prints a string literal node, handling both plain strings and strings with quotes.

Name Type Description
str NStringLiteral String literal to print

printLiteral(lit: NLiteral): Void

Prints a literal value node (numbers, booleans, arrays, objects).

Name Type Description
lit NLiteral Literal node to print

printAccess(access: NAccess): Void

Prints a field access expression (object.field).

Name Type Description
access NAccess Field access node to print

printArrayAccess(access: NArrayAccess): Void

Prints an array access expression (array[index]).

Name Type Description
access NArrayAccess Array access node to print

printCall(call: NCall): Void

Prints a function call expression.

Name Type Description
call NCall Function call node to print

printBinary(binary: NBinary, ?skipParen: Bool = false): Void

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

printUnary(unary: NUnary): Void

Prints a unary operation expression (!x, -x).

Name Type Description
unary NUnary Unary operation node to print

printAssignment(assign: NAssign): Void

Prints an assignment expression (a = b, a += b).

Name Type Description
assign NAssign Assignment node to print

printInLineExpression(expr: NExpr, parens: Bool): Void

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

Metadata

Name Parameters
:hxGen -