refactor: compiler pipeline hardening — parser diagnostics + exhaustive switches + golden equivalence
grammar.ts:
- Replace 2 parseAssertion console.warn + return-null patterns with
this.errorWithCode() throws, producing structured ParseError
diagnostics instead of silently skipping invalid clauses
- Maintain parseBlock's return-null contract for unmatched tokens
(caller loops over tokens expecting null for non-block starters)
compiler.ts:
- buildOptionsFromAssertion: convert 3 standalone ifs to if/else if/else
with never-exhausted throw on unknown assertion type
- compileToFormula: replace silent return-null with throw on unknown
assertion type
validator.ts:
- validateAssertion: replace silent return {valid:true} for unknown
assertion types with throw
fol-compiler.ts:
- compileSingleAssertion: replace silent return-null with throw
Golden equivalence tests (fol-equivalence-golden.test.ts):
7 new deterministic tests covering gaps identified in REFACTOR item 5:
- Size assertions: atLeast, atMost, between (fluent vs dense)
- Compound assertions: .and chain, .or chain
- Options: gap, tolerance in jnd
Documents known discrepancy: fluent size.* prefix vs dense canonical name
(fol-compiler normalizes at FormulaNode level, canonical path does not)
Existing property-based equivalence tests cover spatial, quantifier,
and frame equivalence. Topology predicates have no fluent API surface
(dense-DSL-only), so equivalence must be verified at evaluation level
(already covered by hard E2E topology tests).
662 tests pass (315 DSL + 141 core + 149 solver + 57 E2E).
This commit is contained in:
@@ -363,7 +363,7 @@ export function validateAssertion(assertion: any): ValidationResult {
|
||||
return validateRelation(assertion)
|
||||
}
|
||||
|
||||
return { valid: true, diagnostics: [] }
|
||||
throw new Error(`validateAssertion: unknown assertion type "${String(assertion.type)}"`)
|
||||
}
|
||||
|
||||
// ---- Batch Validation ----
|
||||
|
||||
Reference in New Issue
Block a user