Class SourceRepairs

java.lang.Object
org.ek9lang.compiler.repair.SourceRepairs

public final class SourceRepairs extends Object
THE source repair engine - the one place an EK9 source is repaired automatically, for every door: ek9 -ff and ek9_format (the TEXT layer), and the MCP editors, ek9_write_file, ek9_edit_file and ek9_compile (the DIAGNOSTIC layer). Use this; never add a private fixer to a tool - two fixers for one slip behave differently, and they did (2026-10-05 parse-failure report: tabs, indentation and the shebang were each handled two or three ways, one of them wrong).

Text layer (repairText(String)): needs no compile. The LayoutRepairs first (byte-order mark, line endings, shebang, layout tabs, odd base indent), then a LOOP: parse, take the first syntax error, offer it to each TextRule; a rewrite is kept only if the parse then gets further than before (it removes its own error and adds none ahead of it). Up to 32 passes. What stays unparseable is reported with the ParseSuggestions for it.

Diagnostic layer (repairAgainst(String, List)): one PASS over a compile's diagnostics (the §1.1 maps - line 1-based, column 0-based, errorCode, message). The compiler stops at the first phase that fails, so the caller LOOPS: repair, re-verify, repair what the re-verify revealed (the MCP's AppliedRepairs.repairUntilClean). Each repair is keyed on the diagnostic that proves it; the text rules answer the first SYNTAX diagnostic when the keyed repairs had nothing to say.

The tier rule (docs/tooling/EK9_TOOLING_IMPROVEMENT_METHOD.md §2): a rule APPLIES only where its shape has exactly one reading and the literal reading does not compile; anything needing a choice is a SUGGESTION. Nothing here renames: a misspelt keyword is a suggestion, never a rewrite. Every applied repair is reported - corrected[] in an MCP response, the ek9 -ff report on the command line.

Hold one (private final SourceRepairs sourceRepairs = new SourceRepairs();): it holds every repair and text rule and is stateless, so one instance serves any thread.

  • Field Details

    • MAX_TEXT_PASSES

      public static final int MAX_TEXT_PASSES
      The most text-layer passes; each is one parse.
      See Also:
  • Constructor Details

    • SourceRepairs

      public SourceRepairs()
  • Method Details

    • repairText

      public SourceRepairs.TextResult repairText(String source)
      THE text layer - see the class javadoc.
    • layout

      public String layout(String source)
      The layout repairs alone (LayoutRepairs) - what the canonical indenter applies before giving up on a source that does not parse.
    • layoutTabsReplaced

      public String layoutTabsReplaced(String text)
      text with every LAYOUT tab replaced by two spaces - a tab inside a String, character or regex literal, or a comment, is kept (the lexer decides). THE tab rule, for a whole file or one statement entry.
    • suggestionsFor

      public List<String> suggestionsFor(String text)
      The suggestions for the first syntax error in text; empty when it parses.
    • repairAgainst

      public SourceRepairs.Repaired repairAgainst(String text, List<Map<String,Object>> diagnostics)
      THE diagnostic layer, one pass - see the class javadoc.
    • repairAgainst

      public SourceRepairs.Repaired repairAgainst(String text, List<Map<String,Object>> diagnostics, Predicate<DoubleQuotedInterpolation.Result> keepInterpolation)
      As repairAgainst(String, List), with a veto over the double-quoted interpolation repair (E07901): a caller that cannot re-verify the whole repair as one - ek9_write_file writes with no line receipts - checks that every name the interpolation introduces resolves, and refuses it otherwise.
    • mayApply

      public boolean mayApply(String text)
      True when repairAgainst(String, List) might change text - the cheap gate before a probe compile: the text does not parse, or it holds a shape one of the keyed repairs answers.