Skip to content

Commit e7a8ad2

Browse files
committed
for, each and class vars are now strings to help the interpreter along a lil bit
1 parent 0ad9683 commit e7a8ad2

File tree

2 files changed

+15283
-2384
lines changed

2 files changed

+15283
-2384
lines changed

Resources/OSL Utils.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ class OSLUtils {
516516
}
517517

518518
evalToken(cur, param) {
519+
const out = this.stringToToken(cur, param)
520+
out.source = cur;
521+
return out
522+
}
523+
524+
stringToToken(cur, param) {
519525
if ((cur[0] === "{" && cur[cur.length - 1] === "}") || (cur[0] === "[" && cur[cur.length - 1] === "]")) {
520526
try {
521527
if (cur[0] === "[") {
@@ -710,8 +716,8 @@ class OSLUtils {
710716
{
711717
type: "str",
712718
data: second.parameters.map(p => p.type === "mtd" ?
713-
(p.data.map(p2 => p2.data).join(".")) : p.data
714-
).join(",")
719+
(p.data.map(p2 => p2.data).join(".")) : p.data
720+
).join(",")
715721
},
716722
ast[3]
717723
]
@@ -757,7 +763,7 @@ class OSLUtils {
757763
}
758764

759765
if (ast.length === 0) return null;
760-
766+
761767
if (ast.length === 2 &&
762768
ast[0].type === "var" &&
763769
(ast[1]?.data === "--" && ast[1]?.type === "unk") ||
@@ -809,6 +815,19 @@ class OSLUtils {
809815
return this.generateAST({ CODE: line, MAIN: true });
810816
});
811817

818+
for (let i = 0; i < lines.length; i++) {
819+
const cur = lines[i]
820+
if (!cur) continue;
821+
if (
822+
cur[0].type === "cmd" &&
823+
["for", "each", "class"].includes(cur[0].data)
824+
) {
825+
if (cur?.[4]?.type === "blk" && cur[0].data === "each") cur[2].type = "str"
826+
cur[1].type = "str"
827+
i++
828+
}
829+
}
830+
812831
return lines.filter((line) => line !== null);
813832
}
814833

@@ -944,6 +963,6 @@ if (typeof Scratch !== "undefined") {
944963
const fs = require("fs");
945964

946965
fs.writeFileSync("lol.json", JSON.stringify(utils.generateFullAST({
947-
CODE: fs.readFileSync("/Users/sophie/Origin-OS/OSL Programs/apps/System/Terminal.osl", "utf-8")
966+
CODE: fs.readFileSync("/Users/sophie/Origin-OS/OSL Programs/apps/System/Studio.osl", "utf-8")
948967
}), null, 2));
949968
}

0 commit comments

Comments
 (0)