From d16864711631747538c156a90eda9878588c1cd2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 20 Jul 2025 09:54:38 -0300 Subject: src/paca.mjs: Rename buildDFA -> toDFA --- src/paca.mjs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/paca.mjs') diff --git a/src/paca.mjs b/src/paca.mjs index f1e3e50..38100ff 100644 --- a/src/paca.mjs +++ b/src/paca.mjs @@ -874,7 +874,7 @@ const computePending = (pending, transitions) => .map(nodeID)) ].toSorted().map(unNodeID); -const buildDFANodes = (end, nfaNodes, pending, dfaNodes) => { +const toDFANodes = (end, nfaNodes, pending, dfaNodes) => { if (pending.length === 0) { return dfaNodes; } @@ -882,12 +882,12 @@ const buildDFANodes = (end, nfaNodes, pending, dfaNodes) => { const states = pending[0]; const stateID = nodeID(states); if (!!dfaNodes[stateID]) { - return buildDFANodes(end, nfaNodes, pending.slice(1), dfaNodes); + return toDFANodes(end, nfaNodes, pending.slice(1), dfaNodes); } const transitions = collectTransitions(nfaNodes, states); const newPending = computePending(pending, Object.values(transitions)); - return buildDFANodes(end, nfaNodes, newPending, { + return toDFANodes(end, nfaNodes, newPending, { ...dfaNodes, [stateID]: { end: states.includes(end), @@ -896,11 +896,11 @@ const buildDFANodes = (end, nfaNodes, pending, dfaNodes) => { }); }; -const buildDFA = nfa => { +const toDFA = nfa => { const start = allDirects(nfa.start, nfa.nodes); return { start: nodeID(start), - nodes: buildDFANodes(nfa.end, nfa.nodes, [start], {}), + nodes: toDFANodes(nfa.end, nfa.nodes, [start], {}), }; }; @@ -913,11 +913,14 @@ const searchDFAFn = (dfa, string) => const searchDFA = (dfa, string) => !!dfa.nodes[searchDFAFn(dfa, string)]?.end +const parse = regex => + toPostfix(tokenizeRegex(explode(regex))); + const compileNFA = regex => - buildNFA(toPostfix(tokenizeRegex(explode(regex)))); + buildNFA(parse(regex)); const compileDFA = regex => - buildDFA(compileNFA(regex)); + toDFA(compileNFA(regex)); export const compile = regex => { const nfa = compileDFA(regex); -- cgit v1.2.3