summaryrefslogtreecommitdiff
path: root/src/paca.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/paca.mjs')
-rw-r--r--src/paca.mjs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/paca.mjs b/src/paca.mjs
index 77a7a4b..216dc2e 100644
--- a/src/paca.mjs
+++ b/src/paca.mjs
@@ -761,10 +761,34 @@ const allDirects = (stateID, nodes) =>
).flat(),
)].toSorted();
+const interpretMetacharacter = ({ op, to, matches, ranges }, char) => {
+ if (!op) {
+ return null;
+ }
+
+ if (op === true) {
+ return to;
+ }
+
+ if (matches.has(char)) {
+ return op === "includes" && to;
+ }
+
+ if (inRange(ranges, char)) {
+ return op === "includes" && to;
+ }
+
+ return op === "excludes" && to;
+};
+
+const performTransition = (nodes, char) => id =>
+ nodes[id].transitions[char] ||
+ interpretMetacharacter(nodes[id].meta || {}, char);
+
const searchNFAStep = nodes => (directStates, char) =>
[...new Set(
directStates
- .map(id => nodes[id].transitions[char])
+ .map(performTransition(nodes, char))
.filter(x => !!x)
.map(id => allDirects(id, nodes))
.flat()