Class ModuleNameProblem

java.lang.Object
org.ek9lang.compiler.support.ModuleNameProblem
All Implemented Interfaces:
Function<String, Optional<String>>

public final class ModuleNameProblem extends Object implements Function<String, Optional<String>>
THE validator for an EK9 module name — use this (or IsValidModuleName), do not hand-roll a regex. Gives the first reason a candidate is not a legal module name, or empty when it is legal; the message names the offending segment where one can be identified, so a UI field or an MCP error can say WHY rather than just "invalid".

A module name is the grammar's dottedName (EK9.g4:753): moduleSegment (DOT moduleSegment)*, where a segment is an Identifier (Letter LetterOrDigit*, so it must START with an ASCII letter — not _, not a digit) or one of ~50 explicitly-listed safe keywords.

Why this parses instead of pattern-matching. A character-class regex is necessary but not sufficient, and the insufficiency is not obvious: regexes operate on characters, not tokens, so any plausible pattern accepts EVERY keyword — including the ones moduleSegment does not list. com.acme.range is legal (RANGE is one of the 105 alternatives); com.acme.mod is not (MOD is absent) — yet both match the same regex. A hand-rolled pattern therefore accepts names that will not parse, and drifts out of sync every time that keyword list changes. Running the real dottedName rule is the only implementation that cannot drift.

The permitted list is wider than intuition suggests. moduleSegment allows if, for, switch and while as segments; the only word-like keywords it excludes are defines, mod, rem, tee, uniq and xor. Do not guess which side a keyword falls on — ask this class. Ek9ModuleNameTest pins both sets.

Validation only: this says whether a name is LEGAL, not whether it is conventional (the grammar permits Com.Acme; any lower-case convention belongs in a compiler warning, not here).