@creationix/rex 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/rex-cli.js +615 -269
- package/rex-cli.ts +32 -11
- package/rex-repl.js +582 -256
- package/rex-repl.ts +4 -3
- package/rex.js +310 -180
- package/rex.ohm +50 -22
- package/rex.ohm-bundle.cjs +1 -1
- package/rex.ohm-bundle.d.ts +26 -8
- package/rex.ohm-bundle.js +1 -1
- package/rex.ts +342 -201
- package/rexc-interpreter.ts +262 -85
package/rex-repl.ts
CHANGED
|
@@ -24,7 +24,7 @@ const C = {
|
|
|
24
24
|
// ── Syntax highlighting ───────────────────────────────────────
|
|
25
25
|
|
|
26
26
|
const TOKEN_RE =
|
|
27
|
-
/(?<blockComment>\/\*[\s\S]*?(?:\*\/|$))|(?<lineComment>\/\/[^\n]*)|(?<dstring>"(?:[^"\\]|\\.)*"?)|(?<sstring>'(?:[^'\\]|\\.)*'?)|(?<keyword>\b(?:when|unless|while|for|do|end|in|of|and|or|else|break|continue|delete|self)(?![a-zA-Z0-9_-]))|(?<literal>\b(?:true|false|null|undefined|nan)(?![a-zA-Z0-9_-])|-?\binf\b)|(?<typePred>\b(?:string|number|object|array|boolean)(?![a-zA-Z0-9_-]))|(?<num>\b(?:0x[0-9a-fA-F]+|0b[01]+|(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)\b)/g;
|
|
27
|
+
/(?<blockComment>\/\*[\s\S]*?(?:\*\/|$))|(?<lineComment>\/\/[^\n]*)|(?<dstring>"(?:[^"\\]|\\.)*"?)|(?<sstring>'(?:[^'\\]|\\.)*'?)|(?<keyword>\b(?:when|unless|while|for|do|end|in|of|and|or|nor|else|break|continue|delete|self)(?![a-zA-Z0-9_-]))|(?<literal>\b(?:true|false|null|undefined|nan)(?![a-zA-Z0-9_-])|-?\binf\b)|(?<typePred>\b(?:string|number|object|array|boolean)(?![a-zA-Z0-9_-]))|(?<num>\b(?:0x[0-9a-fA-F]+|0b[01]+|(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)\b)/g;
|
|
28
28
|
|
|
29
29
|
export function highlightLine(line: string): string {
|
|
30
30
|
let result = "";
|
|
@@ -143,6 +143,7 @@ export function highlightRexc(text: string): string {
|
|
|
143
143
|
break;
|
|
144
144
|
}
|
|
145
145
|
case "=": // assignment
|
|
146
|
+
case "/": // swap-assign
|
|
146
147
|
case "~": // delete
|
|
147
148
|
out += C.red + prefix + tag + C.reset;
|
|
148
149
|
i++;
|
|
@@ -257,7 +258,7 @@ export function isIncomplete(buffer: string): boolean {
|
|
|
257
258
|
// Trailing binary operator or keyword suggests continuation
|
|
258
259
|
const trimmed = buffer.trimEnd();
|
|
259
260
|
if (/[+\-*/%&|^=<>]$/.test(trimmed)) return true;
|
|
260
|
-
if (/\b(?:and|or|do|in|of)\s*$/.test(trimmed)) return true;
|
|
261
|
+
if (/\b(?:and|or|nor|do|in|of)\s*$/.test(trimmed)) return true;
|
|
261
262
|
|
|
262
263
|
return false;
|
|
263
264
|
}
|
|
@@ -309,7 +310,7 @@ export function formatVarState(vars: Record<string, unknown>): string {
|
|
|
309
310
|
|
|
310
311
|
const KEYWORDS = [
|
|
311
312
|
"when", "unless", "while", "for", "do", "end", "in", "of",
|
|
312
|
-
"and", "or", "else", "break", "continue", "delete",
|
|
313
|
+
"and", "or", "nor", "else", "break", "continue", "delete",
|
|
313
314
|
"self", "true", "false", "null", "undefined", "nan", "inf",
|
|
314
315
|
"string", "number", "object", "array", "boolean",
|
|
315
316
|
];
|