Class ExcludedKeywordOrError
java.lang.Object
org.ek9lang.compiler.phase1.ExcludedKeywordOrError
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidCheck for excluded control flow statements (break, continue, return, goto, elif, def).(package private) voidCheck for excluded instantiation (new TypeName()).(package private) voidCheck for Python list comprehensions.(package private) voidCheck for excluded literal (null, None).(package private) voidCheck if an identifier is an excluded keyword.(package private) voidCheck for semicolons in instruction blocks.
-
Constructor Details
-
ExcludedKeywordOrError
ExcludedKeywordOrError(ErrorListener errorListener)
-
-
Method Details
-
checkIdentifier
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
Check for excluded control flow statements (break, continue, return, goto, elif, def). -
checkExcludedInstantiation
Check for excluded instantiation (new TypeName()). EK9 uses TypeName() directly, not new TypeName(). -
checkExcludedLiteral
Check for excluded literal (null, None). -
checkSemicolon
Check for semicolons in instruction blocks. Called when processing an instruction block to detect semicolons. -
checkExcludedListComprehension
Check for Python list comprehensions. EK9 uses stream pipelines instead.
-