summaryrefslogtreecommitdiff
path: root/src/paca.mjs
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-07-11 15:29:22 -0300
committerEuAndreh <eu@euandre.org>2025-07-11 15:29:22 -0300
commitebcaf686e938e31e160bc0610df2a0c52c472ff9 (patch)
tree55167c21269a8ce7c8e6cda79b0959cc3f03febf /src/paca.mjs
parentsrc/paca.mjs: Move error detection from tokenizeRegexStep => tokenizeRegex (diff)
downloadpaca-ebcaf686e938e31e160bc0610df2a0c52c472ff9.tar.gz
paca-ebcaf686e938e31e160bc0610df2a0c52c472ff9.tar.xz
src/paca.mjs (tokenizeRegexStep): Include `context` key in reduced state
Diffstat (limited to 'src/paca.mjs')
-rw-r--r--src/paca.mjs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/paca.mjs b/src/paca.mjs
index 380200a..e68cd77 100644
--- a/src/paca.mjs
+++ b/src/paca.mjs
@@ -17,12 +17,13 @@ const shouldConcat = (char, next) =>
next !== undefined &&
char !== "(" &&
char !== "|" &&
+ char !== "{" &&
!nonConcatOperators.has(next);
const isOperator = char =>
nonConcatOperators.has(char) || char == "(";
-const tokenizeRegexStep = chars => ({ out, state }, char, index) => {
+const tokenizeRegexStep = chars => ({ out, state, context }, char, index) => {
const next = chars[index + 1];
const maybeConcat = shouldConcat(char, next)
? [{operator: "concat"}]
@@ -32,6 +33,7 @@ const tokenizeRegexStep = chars => ({ out, state }, char, index) => {
return {
out: out.concat(char, maybeConcat),
state: ConcatStep.ACCEPTING,
+ context,
};
}
@@ -39,6 +41,7 @@ const tokenizeRegexStep = chars => ({ out, state }, char, index) => {
return {
out,
state: ConcatStep.ESCAPING,
+ context,
};
}
@@ -46,13 +49,15 @@ const tokenizeRegexStep = chars => ({ out, state }, char, index) => {
return {
out: out.concat(op, maybeConcat),
state,
+ context,
};
};
const tokenizeRegexFn = chars =>
chars.reduce(tokenizeRegexStep(chars), {
- out: [],
- state: ConcatStep.ACCEPTING,
+ out: [],
+ state: ConcatStep.ACCEPTING,
+ context: null,
});
const tokenizeRegex = chars => {