Class SourcePreProcessor

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

final class SourcePreProcessor extends Object
Pre-processes EK9 source that does not parse, applying simple text-level fixes to make it parseable before the formatting pipeline runs.

Fixes applied in order:

  1. CRLF line endings — normalized to LF
  2. Missing #!ek9 shebang — inserted as line 1
  3. Tab characters — replaced with 2 spaces
  4. Odd-width indentation — normalized to 2-space-per-level
  5. Misspelled structural keywords — fuzzy-corrected via positional matching

Keyword correction uses positional rules (not blind matching) to avoid false positives on user identifiers and module names:

  • First word on a line: checked against control flow and structural keywords
  • Word after defines: checked against block-type keywords
  • Word after override/default: checked against operator
  • Last 3 words on line: checked against end-of-line modifiers (pure, abstract, open, dispatcher) matching the grammar pattern AS? PURE? (ABSTRACT | OPEN)?
  • Word at position 1 after uppercase identifier: checked against extends
  • Any lowercase word of 7+ chars: checked against constrain
  • Constructor Details

    • SourcePreProcessor

      SourcePreProcessor()
  • Method Details

    • preProcess

      String preProcess(String source)
      Apply all pre-processing fixes to the source.
      Parameters:
      source - The EK9 source that does not parse.
      Returns:
      The pre-processed source (may or may not parse after fixes).