rip-lang 1.1.3 → 1.1.4
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/docs/dist/rip.browser.js +57 -27
- package/docs/dist/rip.browser.min.js +12 -12
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/package.json +1 -1
- package/src/compiler.js +54 -43
package/docs/dist/rip.browser.js
CHANGED
|
@@ -6545,7 +6545,45 @@ ${this.indent()}}`;
|
|
|
6545
6545
|
}
|
|
6546
6546
|
}
|
|
6547
6547
|
// src/compiler.js
|
|
6548
|
-
var INLINE_FORMS = [
|
|
6548
|
+
var INLINE_FORMS = new Set([
|
|
6549
|
+
"+",
|
|
6550
|
+
"-",
|
|
6551
|
+
"*",
|
|
6552
|
+
"/",
|
|
6553
|
+
"\\",
|
|
6554
|
+
"#",
|
|
6555
|
+
"**",
|
|
6556
|
+
"_",
|
|
6557
|
+
"=",
|
|
6558
|
+
"<",
|
|
6559
|
+
">",
|
|
6560
|
+
"[",
|
|
6561
|
+
"]",
|
|
6562
|
+
"]]",
|
|
6563
|
+
"!",
|
|
6564
|
+
"&",
|
|
6565
|
+
"?",
|
|
6566
|
+
"'",
|
|
6567
|
+
"not",
|
|
6568
|
+
"var",
|
|
6569
|
+
"num",
|
|
6570
|
+
"str",
|
|
6571
|
+
"global",
|
|
6572
|
+
"naked-global",
|
|
6573
|
+
"tag",
|
|
6574
|
+
"entryref",
|
|
6575
|
+
"assign",
|
|
6576
|
+
"pass-by-ref",
|
|
6577
|
+
"newline",
|
|
6578
|
+
"formfeed",
|
|
6579
|
+
"tab",
|
|
6580
|
+
"ascii",
|
|
6581
|
+
"value",
|
|
6582
|
+
"read-var",
|
|
6583
|
+
"read-newline",
|
|
6584
|
+
"lock-var",
|
|
6585
|
+
"lock-incr",
|
|
6586
|
+
"lock-decr",
|
|
6549
6587
|
".",
|
|
6550
6588
|
"?.",
|
|
6551
6589
|
"::",
|
|
@@ -6554,18 +6592,11 @@ var INLINE_FORMS = [
|
|
|
6554
6592
|
"?[]",
|
|
6555
6593
|
"optindex",
|
|
6556
6594
|
"optcall",
|
|
6557
|
-
"+",
|
|
6558
|
-
"-",
|
|
6559
|
-
"*",
|
|
6560
|
-
"/",
|
|
6561
6595
|
"%",
|
|
6562
|
-
"**",
|
|
6563
6596
|
"//",
|
|
6564
6597
|
"%%",
|
|
6565
6598
|
"==",
|
|
6566
6599
|
"!=",
|
|
6567
|
-
"<",
|
|
6568
|
-
">",
|
|
6569
6600
|
"<=",
|
|
6570
6601
|
">=",
|
|
6571
6602
|
"===",
|
|
@@ -6583,23 +6614,22 @@ var INLINE_FORMS = [
|
|
|
6583
6614
|
"default",
|
|
6584
6615
|
"...",
|
|
6585
6616
|
"expansion"
|
|
6586
|
-
];
|
|
6617
|
+
]);
|
|
6587
6618
|
function isInline(arr) {
|
|
6588
6619
|
if (!Array.isArray(arr) || arr.length === 0)
|
|
6589
6620
|
return false;
|
|
6590
|
-
const head = arr[0]?.valueOf
|
|
6591
|
-
if (INLINE_FORMS.
|
|
6621
|
+
const head = arr[0]?.valueOf?.() ?? arr[0];
|
|
6622
|
+
if (INLINE_FORMS.has(head))
|
|
6592
6623
|
return true;
|
|
6593
|
-
|
|
6594
|
-
return !arr.some((elem) => Array.isArray(elem));
|
|
6595
|
-
}
|
|
6596
|
-
return false;
|
|
6624
|
+
return arr.length <= 4 && !arr.some(Array.isArray);
|
|
6597
6625
|
}
|
|
6598
|
-
function formatAtom(elem
|
|
6626
|
+
function formatAtom(elem) {
|
|
6599
6627
|
if (Array.isArray(elem))
|
|
6600
6628
|
return "(???)";
|
|
6601
6629
|
if (typeof elem === "number")
|
|
6602
6630
|
return String(elem);
|
|
6631
|
+
if (elem === null)
|
|
6632
|
+
return "null";
|
|
6603
6633
|
if (elem === "")
|
|
6604
6634
|
return '""';
|
|
6605
6635
|
const str = String(elem);
|
|
@@ -6623,14 +6653,14 @@ function formatAtom(elem, indent = 0) {
|
|
|
6623
6653
|
}
|
|
6624
6654
|
function formatSExpr(arr, indent = 0, isTopLevel = false) {
|
|
6625
6655
|
if (!Array.isArray(arr))
|
|
6626
|
-
return formatAtom(arr
|
|
6656
|
+
return formatAtom(arr);
|
|
6627
6657
|
if (isInline(arr)) {
|
|
6628
|
-
const parts = arr.map((elem) => Array.isArray(elem) ? formatSExpr(elem, 0, false) : formatAtom(elem
|
|
6629
|
-
return
|
|
6658
|
+
const parts = arr.map((elem) => Array.isArray(elem) ? formatSExpr(elem, 0, false) : formatAtom(elem));
|
|
6659
|
+
return `(${parts.join(" ")})`;
|
|
6630
6660
|
}
|
|
6631
6661
|
if (isTopLevel && arr[0] === "program") {
|
|
6632
6662
|
const secondElem = arr[1];
|
|
6633
|
-
const header = Array.isArray(secondElem) ? "(program" : "(program " + formatAtom(secondElem
|
|
6663
|
+
const header = Array.isArray(secondElem) ? "(program" : "(program " + formatAtom(secondElem);
|
|
6634
6664
|
const lines2 = [header];
|
|
6635
6665
|
const startIndex = Array.isArray(secondElem) ? 1 : 2;
|
|
6636
6666
|
for (let i = startIndex;i < arr.length; i++) {
|
|
@@ -6644,21 +6674,21 @@ function formatSExpr(arr, indent = 0, isTopLevel = false) {
|
|
|
6644
6674
|
return lines2.join(`
|
|
6645
6675
|
`);
|
|
6646
6676
|
}
|
|
6647
|
-
const lines = [];
|
|
6648
6677
|
const spaces = " ".repeat(indent);
|
|
6649
|
-
const
|
|
6650
|
-
|
|
6678
|
+
const lines = [];
|
|
6679
|
+
const head = Array.isArray(arr[0]) ? formatSExpr(arr[0], 0, false) : formatAtom(arr[0]);
|
|
6680
|
+
lines.push(`${spaces}(${head}`);
|
|
6651
6681
|
for (let i = 1;i < arr.length; i++) {
|
|
6652
6682
|
const elem = arr[i];
|
|
6653
6683
|
if (Array.isArray(elem)) {
|
|
6654
6684
|
const formatted = formatSExpr(elem, indent + 2, false);
|
|
6655
6685
|
if (isInline(elem)) {
|
|
6656
|
-
lines[lines.length - 1] +=
|
|
6686
|
+
lines[lines.length - 1] += ` ${formatted}`;
|
|
6657
6687
|
} else {
|
|
6658
6688
|
lines.push(formatted);
|
|
6659
6689
|
}
|
|
6660
6690
|
} else {
|
|
6661
|
-
lines[lines.length - 1] +=
|
|
6691
|
+
lines[lines.length - 1] += ` ${formatAtom(elem)}`;
|
|
6662
6692
|
}
|
|
6663
6693
|
}
|
|
6664
6694
|
lines[lines.length - 1] += ")";
|
|
@@ -6772,8 +6802,8 @@ function compileToJS(source, options = {}) {
|
|
|
6772
6802
|
return compiler.compileToJS(source);
|
|
6773
6803
|
}
|
|
6774
6804
|
// src/browser.js
|
|
6775
|
-
var VERSION = "1.1.
|
|
6776
|
-
var BUILD_DATE = "2025-11-
|
|
6805
|
+
var VERSION = "1.1.4";
|
|
6806
|
+
var BUILD_DATE = "2025-11-03@23:02:48GMT";
|
|
6777
6807
|
var dedent = (s) => {
|
|
6778
6808
|
const m = s.match(/^[ \t]*(?=\S)/gm);
|
|
6779
6809
|
const i = Math.min(...(m || []).map((x) => x.length));
|