Class ConstraintLiterals

java.lang.Object
org.ek9lang.compiler.symbolic.ConstraintLiterals

public final class ConstraintLiterals extends Object
THE shared reading of a constraint's literals as magnitude + suffix — use this, do not re-derive it.

🔑 A suffixed value varies along TWO axes. Money is an amount AND a currency; Dimension is a magnitude AND a unit. Everything that generates or judges such a value has to keep the two apart: the fuzz generator moves the magnitude while pinning the suffix (ConstraintValueSearch), and the front end rejects a constraint whose literals disagree about the suffix in the first place. One splitter serves both, so they cannot disagree about where a magnitude ends.

Why cross-suffix comparison is a hard error rather than a curiosity. The compile-time evaluator answers UNKNOWN, not FAIL, when the suffixes differ — measured, 10cm against >= 500mm is UNKNOWN even though 10cm is plainly below 500mm, and 100.00#USD against a GBP range likewise. UNKNOWN never raises E08260, so such a value slips past every compile-time check and Panics at run time instead. A constraint that mixes suffixes therefore cannot be satisfied by anything, and a generated value carrying the wrong suffix is a test that fails for a reason having nothing to do with the code under test.

  • Method Details

    • magnitudeOf

      public static Double magnitudeOf(String literal)
      A literal's leading numeric magnitude — 10000 of 10000#GBP, 500 of 500mm — or null when it has none, or when what follows is not a bare suffix.
      Parameters:
      literal - the literal source text
      Returns:
      the magnitude, or null
    • suffixOf

      public static String suffixOf(String literal)
      A literal's trailing suffix — #GBP, mm — or empty for a bare number and for anything that is not a suffixed quantity at all.
      Parameters:
      literal - the literal source text
      Returns:
      the suffix, never null
    • distinctSuffixes

      public static Set<String> distinctSuffixes(ConstraintExpr expr)
      Every distinct non-empty suffix the constraint's literals carry, in first-seen order.

      More than one means the constraint compares across suffixes somewhere, which nothing can satisfy — see this class's note on UNKNOWN verdicts.

      Parameters:
      expr - the constraint, may be null
      Returns:
      the distinct suffixes