From c9e5966a7e872692d2e209d69b6d9db4d24c694e Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 13 Jul 2025 20:03:19 -0300 Subject: Add "[" to the possible characters of TRANSITION_FNS. Introducing "[" now we will start to write the code to parse the character class expressions, i.e. [a-z0-9]. The `context` key will contain a `set` with all the literal characters that were found, and all the ranges too. For parsing the ranges, a `range` key equivalent to the one for the {m,n} range is used. Despite the superficial syntax being simmilar, its logic, semantic and implementation will be different. * src/paca.mjs (TRANSITION_FNS) <"[">: Add new transition function for handling the start of a character class expression. * tests/paca.mjs (TRANSITION_FNS): Add a singular test entry, that exercises the conditionless body of the function. --- src/paca.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/paca.mjs b/src/paca.mjs index c1bead1..6843c20 100644 --- a/src/paca.mjs +++ b/src/paca.mjs @@ -121,6 +121,18 @@ const TRANSITION_FNS = { where: "from", }, }), + "[": ({ out, _state, _context }, _char, _index, _next) => ({ + out, + state: ConcatStep.CLASS, + context: { + set: [], + range: { + from: [], + to: [], + where: "from", + }, + }, + }), }; const stateTransitionOperators = new Set(Object.keys(TRANSITION_FNS)); -- cgit v1.2.3