diff options
| author | EuAndreh <eu@euandre.org> | 2025-07-20 09:54:38 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2025-07-20 09:54:38 -0300 |
| commit | d16864711631747538c156a90eda9878588c1cd2 (patch) | |
| tree | 9bee02b0c9f1d2d668d9cfeb210509555f179389 /src/paca.mjs | |
| parent | src/paca.mjs: Support returning multiple options from `performTransition()` (diff) | |
| download | paca-d16864711631747538c156a90eda9878588c1cd2.tar.gz paca-d16864711631747538c156a90eda9878588c1cd2.tar.xz | |
src/paca.mjs: Rename buildDFA -> toDFA
Diffstat (limited to 'src/paca.mjs')
| -rw-r--r-- | src/paca.mjs | 17 |
1 files changed, 10 insertions, 7 deletions
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); |
