UNPKG

@kermank/nldp

Version:

A modular date/time parser for converting natural language into dates and times

50 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.debugTrace = exports.createDebugTrace = void 0; const Logger_1 = require("./Logger"); const createDebugTraceState = () => ({ currentTrace: null, lastTrace: null }); const createDebugTrace = () => { const state = createDebugTraceState(); return { startTrace: (input) => { state.currentTrace = { input, matchAttempts: [] }; }, addRuleMatch: (trace) => { if (!state.currentTrace) return; state.currentTrace.matchAttempts.push(trace); Logger_1.Logger.debug('Rule match attempt', { ruleName: trace.ruleName, input: trace.input, matched: trace.matched, pattern: trace.pattern, matches: trace.matches }); }, endTrace: () => { if (!state.currentTrace) return; Logger_1.Logger.debug('Parse complete', { input: state.currentTrace.input, matchAttempts: state.currentTrace.matchAttempts }); state.lastTrace = state.currentTrace; state.currentTrace = null; }, getTrace: () => state.lastTrace || state.currentTrace, clear: () => { state.currentTrace = null; state.lastTrace = null; } }; }; exports.createDebugTrace = createDebugTrace; // Create a singleton instance for backward compatibility exports.debugTrace = (0, exports.createDebugTrace)(); //# sourceMappingURL=debug-trace.js.map