summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-07-11 15:25:36 -0300
committerEuAndreh <eu@euandre.org>2025-07-11 15:25:36 -0300
commit689f3a0d0cab399717d1152da21929c980061e9b (patch)
treea3dc3ca03eee63331072e9ba36e32b54cc7f3fe2 /src
parenttests/paca.mjs (test_tokenizeRegexStep): Compute `char` and `index` (diff)
downloadpaca-689f3a0d0cab399717d1152da21929c980061e9b.tar.gz
paca-689f3a0d0cab399717d1152da21929c980061e9b.tar.xz
src/paca.mjs: Move error detection from tokenizeRegexStep => tokenizeRegex
Diffstat (limited to 'src')
-rw-r--r--src/paca.mjs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/paca.mjs b/src/paca.mjs
index 993d26c..380200a 100644
--- a/src/paca.mjs
+++ b/src/paca.mjs
@@ -36,12 +36,6 @@ const tokenizeRegexStep = chars => ({ out, state }, char, index) => {
}
if (char === "\\") {
- if (next === undefined) {
- throw new SyntaxError(
- `bad trailing escape character: ${chars}`,
- );
- }
-
return {
out,
state: ConcatStep.ESCAPING,
@@ -61,8 +55,18 @@ const tokenizeRegexFn = chars =>
state: ConcatStep.ACCEPTING,
});
-const tokenizeRegex = chars =>
- tokenizeRegexFn(chars).out;
+const tokenizeRegex = chars => {
+ const tokens = tokenizeRegexFn(chars);
+ if (!!tokens.error) {
+ throw tokens.error;
+ }
+
+ if (tokens.state !== ConcatStep.ACCEPTING) {
+ throw new SyntaxError("bad ending state: " + tokens.state);
+ }
+
+ return tokens.out;
+};
const PRECEDENCE = {
"(": 4,