Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/tests/dron_regex_reference.js
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 18 minutes ago History
dron_regex_reference.js · 1.5 KB · 38 lines
1// The ECMAScript reading of the DRON regular-expression cases (docs/dron.md,
2// "Regular expressions"). It reads {"patterns": [...], "refused": [...],
3// "samples": [...]} on stdin and writes, for each pattern, the samples the
4// WHOLE of which it matches under the `u` flag: `^(?:pattern)$`.
5//
6// python tests/test_dron_regex.py | node tests/dron_regex_reference.js \
7// > tests/dron_regex_ecmascript.json
8//
9// tests/test_dron_regex.py compares the engine with the file this writes, and
10// runs this script itself when `node` is installed.
11"use strict";
12
13let input = "";
14process.stdin.setEncoding("utf8");
15process.stdin.on("data", (chunk) => { input += chunk; });
16process.stdin.on("end", () => {
17 const cases = JSON.parse(input);
18 const compiles = (pattern, flags) => {
19 try { new RegExp("^(?:" + pattern + ")$", flags); return true; } catch (error) { return false; }
20 };
21 const matches = {};
22 for (const pattern of cases.patterns) {
23 const whole = new RegExp("^(?:" + pattern + ")$", "u");
24 matches[pattern] = cases.samples
25 .map((sample, index) => (whole.test(sample) ? index : -1))
26 .filter((index) => index >= 0);
27 }
28 const refused = {};
29 for (const pattern of cases.refused) {
30 refused[pattern] = compiles(pattern, "u");
31 }
32 process.stdout.write(JSON.stringify({
33 samples: cases.samples,
34 matches,
35 refused_compiles_in_ecmascript: refused,
36 }, null, 1).replace(/[^\x00-\x7e]/g, (unit) =>
37 "\\u" + unit.charCodeAt(0).toString(16).padStart(4, "0")) + "\n");
38});