fix: NaN guard in normalizeOptionValue + warn on silent parser drops
compiler.ts: normalizeOptionValue now rejects NaN numbers and empty strings. Previously typeof NaN === 'number' passed through and propagated into option values, causing predicate comparisons like value >= NaN to produce silent wrong results. grammar.ts: parseAssertion now emits console.warn when silently skipping unexpected tokens or failed clauses. Previously these returns-null were invisible to developers. 454 solver+DSL + 57 E2E tests pass.
This commit is contained in:
@@ -73,7 +73,11 @@ function defaultNextId(prefix: string): string {
|
|||||||
|
|
||||||
function normalizeOptionValue(raw: unknown): number | string | undefined {
|
function normalizeOptionValue(raw: unknown): number | string | undefined {
|
||||||
if (raw === undefined || raw === null) return undefined
|
if (raw === undefined || raw === null) return undefined
|
||||||
if (typeof raw === 'number' || typeof raw === 'string') return raw
|
if (typeof raw === 'number') return Number.isNaN(raw) ? undefined : raw
|
||||||
|
if (typeof raw === 'string') {
|
||||||
|
const trimmed = raw.trim()
|
||||||
|
return trimmed.length > 0 ? trimmed : undefined
|
||||||
|
}
|
||||||
|
|
||||||
// String-parser/fluent path: LiteralNode or ToleranceLiteralNode
|
// String-parser/fluent path: LiteralNode or ToleranceLiteralNode
|
||||||
if (typeof raw === 'object') {
|
if (typeof raw === 'object') {
|
||||||
|
|||||||
@@ -952,6 +952,7 @@ export class GrammarParser {
|
|||||||
if (negated) {
|
if (negated) {
|
||||||
throw this.error(`Expected assertion after 'not'`)
|
throw this.error(`Expected assertion after 'not'`)
|
||||||
}
|
}
|
||||||
|
console.warn(`[imhotep-dsl] parseAssertion: unexpected token "${this.currentToken().value}" at line ${this.currentToken().start?.line}, skipping`)
|
||||||
this.advance()
|
this.advance()
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -968,6 +969,7 @@ export class GrammarParser {
|
|||||||
if (quantifier) {
|
if (quantifier) {
|
||||||
throw this.error(`Expected assertion after quantifier '${quantifier.kind}'`)
|
throw this.error(`Expected assertion after quantifier '${quantifier.kind}'`)
|
||||||
}
|
}
|
||||||
|
console.warn(`[imhotep-dsl] parseAssertion: could not parse clause for subject "${subject.value}" at line ${start?.line}, skipping`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user