Class SourceText

java.lang.Object
org.ek9lang.compiler.support.SourceText
All Implemented Interfaces:
Function<org.antlr.v4.runtime.ParserRuleContext, String>

public final class SourceText extends Object implements Function<org.antlr.v4.runtime.ParserRuleContext, String>
THE source of a parse rule as the developer wrote it: the characters it spans in the char stream, spaces kept. Use it wherever source text is shown to a person or embedded in a message - ctx.getText() joins the tokens with nothing between them, so name? and age? becomes name?andage?. Falls back to getText() only when the char stream is unavailable.

Hold one and apply it. On one line it is SourceTextOnOneLine; in a run-time message it is SourceTextForMessage.

  • Field Details

    • MESSAGE_LENGTH

      public static final int MESSAGE_LENGTH
      The longest source text embedded in a run-time message (an assert or require failure).
      See Also:
  • Constructor Details

    • SourceText

      public SourceText()
  • Method Details

    • apply

      public String apply(org.antlr.v4.runtime.ParserRuleContext ctx)
      The characters ctx spans, as written.
      Specified by:
      apply in interface Function<org.antlr.v4.runtime.ParserRuleContext, String>