Class CanonicalIndenter

java.lang.Object
org.ek9lang.compiler.formatter.CanonicalIndenter

public final class CanonicalIndenter extends Object
Pass 1 of the EK9 source formatter: Canonical Indentation.

Parses the EK9 source to obtain the token stream with INDENT/DEDENT tokens, builds a map of line numbers to indent levels, then re-writes each source line with canonical 2-space indentation.

Also handles:

  • Trailing whitespace stripping on every line
  • Maximum 1 consecutive blank line
  • File ends with exactly one newline
  • #!ek9 always at line 1, column 0
  • Constructor Details

    • CanonicalIndenter

      public CanonicalIndenter()
  • Method Details

    • indent

      public String indent(String source)
      Apply canonical indentation to the given EK9 source. The source must be parseable (INDENT/DEDENT tokens must be valid).
      Parameters:
      source - The EK9 source code to re-indent.
      Returns:
      The source with canonical 2-space indentation, or null if parsing fails.