Class SyntaxProbe

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

public final class SyntaxProbe extends Object
THE parse-only check of a piece of EK9 text, for every repair: the syntax errors the ANTLR parser reports, no symbol phase run. Use this - a file's first error (first(String)), whether it parses (parses(String)), whether a caller's statement entry parses inside a throwaway body (statementParses(String)) - rather than building another ParserSpec and ErrorListener by hand.

A SyntaxProbe.SyntaxError also renders as the diagnostic map every repair reads (SyntaxProbe.SyntaxError.asDiagnostic()): line 1-based, column 0-based, errorCode (empty for an uncoded parser error) and message - the keys the MCP diagnostics carry, so a CLI caller and an MCP caller hand the repairs the same thing.

  • Method Details

    • parse

      public static Optional<SyntaxProbe.Parsed> parse(String source)
      THE parse of source into a tree and its tokens, whether or not it parses cleanly (the parser recovers); empty when it could not be read at all.
    • errors

      public static List<SyntaxProbe.SyntaxError> errors(String source)
      Every syntax error in source, in text order; empty when it parses (or is null).
    • first

      public static Optional<SyntaxProbe.SyntaxError> first(String source)
      The first syntax error in source; empty when it parses.
    • parses

      public static boolean parses(String source)
      True when source parses.
    • statementParses

      public static boolean statementParses(String entry)
      True when entry - one statement, possibly several lines with its relative indentation - parses as the body of a function. Its lines are re-indented as a block, the shallowest to the body's indent.
    • indentOf

      static int indentOf(String line)
      The number of leading spaces of line.