Class QuestionMarkWithValue

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

public final class QuestionMarkWithValue extends Object
THE repair of a declaration written with a ? AND a value - <- rtn as String?: String() becomes <- rtn as String: String() - for every editing tool. Use this; do not re-derive it.

The grammar's variableDeclaration takes an optional ? before any of its four assignments - :, :=, =, :~: - but beside a value the ? MEANS NOTHING. On a declaration WITHOUT a value it marks the variable uninitialised (the flow checks, E08050); WITH one it only sets nullAllowed, which no compiler code reads. Measured 2026-09-28, in a property, a local and a return: Type? : v, ? := v, ? = v and ? :~: v each compile byte-identically to the same line without the ?.

Written WITHOUT the space, the lexer takes the ? into a longer token - ?: (the Elvis operator, which also swallows the start of := and :~:) - and the declaration is a syntax error: "unexpected '?:'". (?= is no longer a token - the guard was removed, Steve 2026-10-07 - so Type?= v lexes as Type? = v, the spaced form, and E07300 brings it here.) The repair keeps the value and the assignment the caller wrote and drops the ?: the program their tokens denote, in its idiomatic spelling. (Spacing it instead - the first version - left a dead ? telling a reader "no value" about a variable that has one: Steve's catch.) A spaced form compiles, so no diagnostic ever brings it here.

Measured (2026-09-28): 17 recorded runs carried ?: and 14 of them FAILED - the model resends it, 40 refusals across edit_file, write_file, insert_statements and add_method; it was 7 of cycle 8's 10 qwen3-coder failures on modify T10. The other joined spellings were never recorded; they are the same rule.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    The rewritten text and one note per rewrite; notes empty means nothing moved.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final Pattern
    [<-] name as [sanitized] Type? <op> value - the ? joined to its assignment or spaced from it.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    True when text has a line of the shape, joined or spaced - the cheap gate before a probe compile.
    repair(String text, List<Map<String,Object>> diagnostics)
    Repair every declaration a diagnostic proves carries the ?: the parser's "unexpected '?:'" (no error code) with its column exactly on the joined ?, or the compiler's E07300 with its column exactly on the NAME of a spaced one.
    static String
    line with its declaration's JOINED ? dropped, the assignment and value kept; null when the line is not that shape.
    static String
    entry with every such line repaired; null when no line is that shape.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SHAPE

      static final Pattern SHAPE
      [<-] name as [sanitized] Type? <op> value - the ? joined to its assignment or spaced from it. Groups: 1 the lead (<-), 2 the name, 3 as Type (it ends where the ? starts), 4 the assignment, 5 the value.
  • Method Details

    • repaired

      public static String repaired(String line)
      line with its declaration's JOINED ? dropped, the assignment and value kept; null when the line is not that shape. For statements, before the parser sees them - a spaced ? parses, and the compile's E07300 brings it to repair(String, List).
    • repairedLines

      public static String repairedLines(String entry)
      entry with every such line repaired; null when no line is that shape.
    • mayApply

      public static boolean mayApply(String text)
      True when text has a line of the shape, joined or spaced - the cheap gate before a probe compile.
    • repair

      public static QuestionMarkWithValue.Result repair(String text, List<Map<String,Object>> diagnostics)
      Repair every declaration a diagnostic proves carries the ?: the parser's "unexpected '?:'" (no error code) with its column exactly on the joined ?, or the compiler's E07300 with its column exactly on the NAME of a spaced one. Anything less certain is skipped and the caller's refusal stands. Rewrites within one line, so the receipts can follow (SourceRepairs).