Class SourcePosition

java.lang.Object
dev.frostlake.executor.expressions.SourcePosition

public final class SourcePosition extends Object
Where a node sits inside the expression TEXT it was parsed from — a line (1-based) and a character offset within that line (0-based), the two numbers Snowflake reports as error line 1 at position 7.

Fragment-relative, never statement-relative. This is the invariant that keeps the expression AST cache correct: ExpressionEvaluator caches a parsed AST BY ITS TEXT, so two occurrences of the same expression anywhere in any statement share one AST. A position stored here is therefore a pure function of that text and stays true for every occurrence. Storing an absolute statement offset instead would let the first occurrence's offset be reported for all the others — a wrong answer rather than a missing one.

The statement-relative position a message quotes is produced late, by adding the ORIGIN of the fragment being evaluated. See ExpressionSource.

  • Constructor Details

    • SourcePosition

      public SourcePosition(int line, int charPositionInLine)
  • Method Details

    • getLine

      public int getLine()
      1-based, as Snowflake counts lines.
    • getCharPositionInLine

      public int getCharPositionInLine()
      0-based within the line, as Snowflake counts positions.
    • toString

      public String toString()
      Overrides:
      toString in class Object