Class ExcludedKeywordOrError

java.lang.Object
org.ek9lang.compiler.phase1.ExcludedKeywordOrError

final class ExcludedKeywordOrError extends Object
Detects excluded keywords and emits clear educational error messages. EK9 deliberately excludes break, continue, return, null, new, goto, and semicolons based on 50+ years of production bug evidence. When developers (or AI assistants) try to use these constructs, they receive helpful error messages explaining why EK9 excludes them and what alternatives to use.

This checker REJECTS these keywords in TWO contexts:

  • As statements/expressions (break, continue, return, goto, null, new)
  • As identifiers (variable names, function names, class names) - these words cause cognitive confusion even when used as names

The grammar recognizes these keywords to enable helpful error messages instead of cryptic ANTLR parse errors. But they are NOT allowed in EK9.

Exception: Module segment names CAN contain these words (e.g., bad.break.usage) because they are read as hierarchical paths, not executable code.

  • Constructor Details

    • ExcludedKeywordOrError

      ExcludedKeywordOrError(ErrorListener errorListener)
  • Method Details

    • checkIdentifier

      void checkIdentifier(EK9Parser.IdentifierContext ctx)
      Check if an identifier is an excluded keyword. Called when an identifier is used as a name for variable, function, class, etc. Module segment names are allowed to contain these keywords.
    • checkExcludedControlFlowStatement

      void checkExcludedControlFlowStatement(EK9Parser.ExcludedControlFlowStatementContext ctx)
      Check for excluded control flow statements (break, continue, return, goto, elif, def).
    • checkExcludedInstantiation

      void checkExcludedInstantiation(EK9Parser.ExcludedInstantiationContext ctx)
      Check for excluded instantiation (new TypeName()). EK9 uses TypeName() directly, not new TypeName().
    • checkExcludedLiteral

      void checkExcludedLiteral(EK9Parser.ExcludedLiteralContext ctx)
      Check for excluded literal (null, None).
    • checkSemicolon

      void checkSemicolon(EK9Parser.InstructionBlockContext ctx)
      Check for semicolons in instruction blocks. Called when processing an instruction block to detect semicolons.
    • checkExcludedListComprehension

      void checkExcludedListComprehension(EK9Parser.ExcludedListComprehensionContext ctx)
      Check for Python list comprehensions. EK9 uses stream pipelines instead.