From e808ad60c1a2b4f7793fd4ba5b70db37039fb1ea Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 15 Jul 2025 21:11:37 -0300 Subject: Support tokenizing `.` wildcard operator. * src/paca.mjs (isTransition): Add new function as an improved version of the raw usage of `stateTransitionOperators`, equivalent to `isAnchor()` and `isOperator()`. (operatorChars, isOperator): Add new static set `operatorChars` as backing data of `isOperator()`, instead of ad-hoc conditional in its implementation. Also now add the `.` character as an operator by including it in the `operatorChars` set. (tokenizeRegexStep): Use the new `isTransition()` function instead of checking the set directly. Also tweak ternary to fit in 80 columns. (PRECEDENCE): Add `.` operator with lowest precedence, as it is not really operating on anything, and is instead a target to be operated on. * tests/paca.mjs (test_isTransition): Add obligatory test cases. (test_isOperator): Include test case for `.` wildcard operator. --- tests/paca.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/paca.mjs') diff --git a/tests/paca.mjs b/tests/paca.mjs index 134fb77..bc6e1d0 100644 --- a/tests/paca.mjs +++ b/tests/paca.mjs @@ -12,6 +12,7 @@ import { TRANSITION_FNS, ANCHOR_FNS, isAnchor, + isTransition, isOperator, tokenizeRegexStep, tokenizeRegexFn, @@ -618,6 +619,22 @@ const test_isAnchor = t => { }); }; +const test_isTransition = t => { + t.start("isTransition()"); + + t.testing("transition chars are true", () => { + t.assertEq(isTransition("\\"), true); + t.assertEq(isTransition("["), true); + t.assertEq(isTransition("{"), true); + }); + + t.testing("false for everything else", () => { + t.assertEq(isTransition("."), false); + t.assertEq(isTransition("*"), false); + t.assertEq(isTransition("a"), false); + }); +}; + const test_isOperator = t => { t.start("isOperator()"); @@ -628,6 +645,7 @@ const test_isOperator = t => { t.assertEq(isOperator("?"), true); t.assertEq(isOperator("("), true); t.assertEq(isOperator(")"), true); + t.assertEq(isOperator("."), true); }); t.testing("false for everyday non-meta chars", () => { @@ -3030,6 +3048,7 @@ runTests([ test_TRANSITION_FNS, test_ANCHOR_FNS, test_isAnchor, + test_isTransition, test_isOperator, test_tokenizeRegexStep, test_tokenizeRegexFn, -- cgit v1.2.3