CodeToHscript

loreline.CodeToHscript (Class)

Preprocesses Loreline script code to make it compatible with HScript. This class converts Loreline syntax into valid HScript syntax by:

  • Converting 'and' and 'or' operators to '&&' and '||'
  • Adding parentheses around control structure conditions
  • Adding semicolons and braces where needed
  • Processing string literals and comments

Instance Members

input: String

The input Loreline script code


output: Utf8Buf

Buffer for the processed output


process(input: String): String

Processes a Loreline script code string and converts it to HScript compatible code.

Name Type Description
input String The Loreline script code to process
Returns Description
String The processed HScript compatible code

toLorelinePos(funcPos: Position, pmin: Int, pmax: Int): Position
Name Type
funcPos Position
pmin Int
pmax Int
Returns
Position

inputPosFromProcessedPos(pos: Int): Int
Name Type
pos Int
Returns
Int

processedPosFromInputPos(pos: Int): Int
Name Type
pos Int
Returns
Int

new(): Void

Creates a new CodeToHscript instance.

Private Members

CONTROL_KEYWORDS: Array<String>

List of control flow keywords that may need special handling


index: Int

Current position in the input string


lineOutput: Utf8Buf

Buffer for tracking the current line


length: Int

Length of the input string


indent: Int

Current indentation level


inComment: Bool

Whether currently processing a comment


inString: Bool

Whether currently processing a string literal


posOffsets: Array<Int>

Tracks position offsets for error reporting


currentPosOffset: Int

Current position offset


inControl: Bool

Whether currently processing a control structure


inControlWithoutParens: Bool

Whether currently processing a control structure without explicit parentheses


indentLevel: Int

Current indentation level


indentStack: Array<Int>

Stack of indentation levels


A stack to keep track of whether we are inside an object or array literal or not


processInput(?until: Int = -1): Void

Main input processing loop that handles each character in the input.

Name Type Default
until Int -1

processString(): Void

Processes a string literal, preserving its content and escape sequences.


processComplexInterpolation(): Void

processFieldAccessInterpolation(): Void

processIdentifier(): Void

isDigit(c: Int): Bool

Checks if a character is a digit (0-9). @*

Name Type Description
c Int Character code to check
Returns Description
Bool Whether the character is a digit

isIdentifierStart(c: Int): Bool

Checks if a character is valid as the start of an identifier. Valid identifier starts are letters and underscore.

Name Type Description
c Int Character code to check
Returns Description
Bool Whether the character can start an identifier

isIdentifierPart(c: Int): Bool

Checks if a character is valid as part of an identifier. Valid identifier parts are letters, numbers, and underscore.

Name Type Description
c Int Character code to check
Returns Description
Bool Whether the character can be part of an identifier

processComment(): Void

Processes comments, preserving their layout while replacing content with spaces to maintain character positions for error reporting.


endsWithChar(line: String, c: Int): Bool

Checks if a line ends with a specific character.

Name Type Description
line String The line to check
c Int The character code to look for
Returns Description
Bool True if the line ends with the character, false otherwise

followsWithChar(c: Int, pos: Int): Bool

Checks if the next non-whitespace, non-comment character in the input is a specific character.

Name Type Description
c Int The character code to look for
pos Int The position to start looking from
Returns Description
Bool True if the next meaningful character is the one we're looking for, false otherwise

endsOrFollowsWithChar(line: String, c: Int, pos: Int, ?hxpos: Null<haxe.PosInfos>): Bool

Checks if a line ends with a specific character or if the character follows in the input.

Name Type Default Description
line String The line to check
c Int The character code to look for
pos Int The position to start looking from if the character is not at the end of the line
hxpos Null<haxe.PosInfos> (optional)
Returns Description
Bool True if the character is found at the end of the line or as the next meaningful character

nextLineIndentOffset(line: String, pos: Int): Int

Calculates the indentation change between the current line and the next non-empty line.

Name Type Description
line String The current line
pos Int The position to start looking from for the next line
Returns Description
Int A positive number for indent, negative for dedent, or zero for no change

followsWithIf(pos: Int): Bool

Checks if the next non-whitespace, non-comment token is the "if" keyword. Used to detect "else if" constructs that shouldn't add braces between else and if.

Name Type Description
pos Int The position to start looking from
Returns Description
Bool True if the next token is "if", false otherwise

endsWithControlKeyword(line: String, pos: Int): Bool

Checks if a line ends with a control flow keyword (if, for, while, etc.).

Name Type Description
line String The line to check
pos Int The position to use for validating what follows the potential keyword
Returns Description
Bool True if the line ends with a control keyword, false otherwise

endsWithArrayIndexable(line: String): Bool
Name Type
line String
Returns
Bool

isWhitespace(c: Int): Bool

Checks if a character is a whitespace character.

Name Type Description
c Int The character code to check
Returns Description
Bool True if the character is whitespace, false otherwise

isAlphaNumeric(c: Int): Bool

Checks if a character is alphanumeric or underscore.

Name Type Description
c Int The character code to check
Returns Description
Bool True if the character is alphanumeric or underscore, false otherwise

addExtra(c: Int): Void

Adds a character to the output, and increment index

Name Type
c Int

add(c: Int): Void

Adds a character to the output without incrementing index

Name Type
c Int

inStatementsBlock(): Bool
Returns
Bool

inObjectBlock(): Bool
Returns
Bool

inArrayBlock(): Bool
Returns
Bool

isLabelStart(pos: Int): Bool

Returns whether the input at the given position begins with a label pattern (identifier:).

Name Type Description
pos Int Position to check from
Returns Description
Bool True if a label starts at the position, false otherwise

skipWhitespaceAndComments(pos: Int): Int
Name Type
pos Int
Returns
Int

stackPush(item: CodeToHscriptStackType): Void
Name Type
item CodeToHscriptStackType

Returns
Null<CodeToHscriptStackType>

error(message: String): Void
Name Type
message String

Metadata

Name Parameters
:hxGen -