Class Ek9SourceFormatter
java.lang.Object
org.ek9lang.compiler.formatter.Ek9SourceFormatter
Orchestrates the EK9 source code formatting pipeline.
Implements a six-pass approach:
- Pass 1: Canonical indentation (2-space, from INDENT/DEDENT tokens)
- Pass 2: Structural reordering (reference sorting, block ordering, overload colocation)
- Pass 3: Token spacing (operator spacing, canonical whitespace)
- Pass 4: Line splitting (long line breaking for params, streams, expressions)
- Pass 5: Comment formatting (doc comment indentation and wrapping)
- Pass 6: Implicit
org.ek9.lang::prefix stripping
For unparseable files, force mode first runs THE repair engine's text layer, SourceRepairs.repairText(String):
the layout repairs (byte-order mark, line endings, a missing or wrong shebang, layout tabs, odd base indent), then
the one-reading parse repairs in a parse-verified loop. Every repair is reported in
FormatterResult.corrections(). Nothing is renamed: if the repairs do not make the source parse it is
refused, with what still fails and what could be done about it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionforceFormat(String source) Force-format the given EK9 source code: repair it (SourceRepairs.repairText(String)), then the Tier 1 pipeline.Format the given EK9 source code using the Tier 1 pipeline.
-
Constructor Details
-
Ek9SourceFormatter
public Ek9SourceFormatter()
-
-
Method Details
-
format
Format the given EK9 source code using the Tier 1 pipeline. The input must be parseable. If not, returns a failure result.- Parameters:
source- The EK9 source code to format.- Returns:
- The formatting result containing the formatted output or error information.
-
forceFormat
Force-format the given EK9 source code: repair it (SourceRepairs.repairText(String)), then the Tier 1 pipeline. A success carries one correction per repair made.- Parameters:
source- The EK9 source code to format (may be unparseable).- Returns:
- The formatting result containing the formatted output or error information.
-