Class LayoutTokens

java.lang.Object
org.ek9lang.compiler.support.LayoutTokens

public final class LayoutTokens extends Object
THE shared knowledge of EK9's LAYOUT tokens — INDENT / DEDENT / NL / EOF — and the one correction every consumer of a parse-rule's END position needs because of them.

🔑 In an indentation grammar a rule that ends in DEDENT has a stop token belonging to the NEXT construct. The lexer emits the DEDENT at the first token of the following line, so ctx.getStop().getLine() over-runs onto that line: a dynamic function declared on lines 21-22 reports stopping on line 23, the line of the statement AFTER it. Anything that asks "does this construct span line N?" from getStop() therefore claims the next sibling's first line — and when that sibling has no scope of its own (a plain statement), the earlier construct wins the lookup outright. That mis-anchored the cursor-based Lock Fingerprint, data-touch and blast-radius enquiries onto a MutexKey body for the require lock.enter(key) line beneath it.

Use lastContentLine(ParseTree) for the true last line — the last real-content token, layout skipped. Consolidated 2026-09-14 from a package-private copy in GenusBlockInserter (which the guard writer already reused) so the line-based scope resolver in assist could share it without a dependency on the editors. Never re-derive a getStop() correction beside this.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Set<Integer>
    The token types whose positions are synthetic — never the end of anything a reader sees.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isLayout(org.antlr.v4.runtime.Token token)
    Is this a layout token (INDENT / DEDENT / NL / EOF)?
    static int
    lastContentLine(org.antlr.v4.runtime.tree.ParseTree node)
    The 1-based line of the LAST real-content token under node, or -1 when it holds none.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LAYOUT_TOKENS

      public static final Set<Integer> LAYOUT_TOKENS
      The token types whose positions are synthetic — never the end of anything a reader sees.
  • Method Details

    • isLayout

      public static boolean isLayout(org.antlr.v4.runtime.Token token)
      Is this a layout token (INDENT / DEDENT / NL / EOF)?
    • lastContentLine

      public static int lastContentLine(org.antlr.v4.runtime.tree.ParseTree node)
      The 1-based line of the LAST real-content token under node, or -1 when it holds none. Unlike ctx.getStop().getLine() this never over-runs onto the trailing DEDENT.