Position

loreline.Position (Class)

Represents a position within source code, tracking line number, column, and offset information. Used throughout the compiler to pinpoint locations of tokens, nodes, and error messages.

Static Members

fromContentAndIndex(content: String, offset: Int, ?length: Int = 0): Position

Creates a Position object by analyzing a string content up to the specified offset. Calculates the correct line and column numbers based on line breaks in the content.

Name Type Default Description
content String The string content to analyze
offset Int The character offset from the start of the content
length Int 0 The length of the position (or 0 if not provided)
Returns Description
Position A new Position object with proper line and column information

Instance Members

line: Int

The line number in the source code, starting from 1.


column: Int

The column number in the source code, starting from 1. Represents the character position within the current line.


offset: Int

The absolute character offset from the start of the source code. Used for precise positioning and span calculations.


length: Int

The length of the source text span this position represents. A value of 0 indicates a point position rather than a span.


toString(): String

Converts the position to a human-readable string representation. Useful for error messages and debugging.

Returns Description
String String in format "(line X col Y)"

toJson(): Dynamic

Converts the position to a JSON-compatible object structure. Only includes the length field if it's non-zero.

Returns Description
Dynamic Dynamic object containing position data

withOffset(content: String, additionalOffset: Int, ?newLength: Int = 0, ?contentStart: Int = 0): Position

Creates a new position that is offset from this position. This maintains the same line/column tracking but with an adjusted offset. Supports both positive and negative offsets.

Name Type Default Description
content String String content to analyze for line/column tracking
additionalOffset Int Number of characters to offset from current position (can be negative)
newLength Int 0 Optional new length for the offset position (default: 0)
contentStart Int 0
Returns Description
Position New Position object at the offset location

extendedTo(endPos: Position): Position

Creates a new position that extends from this position's start to another position's end. Useful for creating spans that encompass multiple tokens or nodes.

Name Type Description
endPos Position Position marking the end of the span
Returns Description
Position New Position object representing the extended span

new(line: Int, column: Int, offset: Int, ?length: Int = 0): Void

Creates a new position instance with the specified coordinates.

Name Type Default Description
line Int Line number in the source (1-based)
column Int Column number in the source (1-based)
offset Int Character offset from start of source
length Int 0 Optional length of the source span (default: 0)

Metadata

Name Parameters
:hxGen -