Less 'magic'

This commit is contained in:
Mewrry the Kitty 2025-12-31 16:46:17 -06:00
parent c258f046b2
commit 8274e559e0

View file

@ -97,7 +97,7 @@ function showVersion(){
// . 1 . 2 . 3 . 4 . 5 . 6 // . 1 . 2 . 3 . 4 . 5 . 6
// ^ // ^
"Spinny for itty\n" + "Spinny for itty\n" +
"Version 0.0.2\n" + "Version 0.0.3\n" +
"Known spinc versions:\n" "Known spinc versions:\n"
" • `noversion'\n" " • `noversion'\n"
) )
@ -169,11 +169,16 @@ function parseCliArgs() {
class spinnyParser { class spinnyParser {
const INSIDE = {
FILE: 0,
INTER: 1,
LAZY: 2
}
compile(sourceFileContents) { compile(sourceFileContents) {
this.file = sourceFileContents; this.file = sourceFileContents;
this.index = 0; this.index = 0;
this.debugStack = []; this.debugStack = [];
return parseFile() return this.parseFile()
} }
parseFile() { parseFile() {
this.debugStack.push(["File", this.index]); this.debugStack.push(["File", this.index]);
@ -185,7 +190,7 @@ class spinnyParser {
this.next(); this.next();
continue continue
} }
lines.push(parseLine("F")) lines.push(this.parseLine(INSIDE.FILE))
} }
this.debugStack.pop(); this.debugStack.pop();
return lines return lines
@ -208,18 +213,19 @@ class spinnyParser {
this.next(); this.next();
continue continue
case "#": case "#":
parseComment(); this.parseComment();
continue continue
case "}": case "}":
if (inside === "L") if (inside === INSIDE.LAZY)
break wordLoop break wordLoop
break break
case ">": case ">":
if (inside === "I") if (inside === INSIDE.INTER)
break wordLoop break wordLoop
break break
case "\n": case "\n":
if (inside === "F") if (inside === INSIDE.FILE
|| inside == INSIDE.LAZY)
break wordLoop break wordLoop
break break
case "\\": case "\\":
@ -232,7 +238,7 @@ class spinnyParser {
} }
break break
} }
words.push(parseWord(inside)); words.push(this.parseWord(inside));
} }
this.debugStack.pop() this.debugStack.pop()
return words return words
@ -264,11 +270,23 @@ class spinnyParser {
} }
switch (this.now()) { switch (this.now()) {
case "{": case "{":
return {bang:bang,type:"lazy",lines:parseLazy()} return {
CMPVER.KEYS.BANG:bang,
CMPVER.KEYS.TYPE:CMPVER.TYPE.LAZY,
CMPVER.KEYS.LINES:this.parseLazy()
}
case "`": case "`":
return {bang:bang,type:"literal",parts:parseLiteral()} return {
CMPVER.KEYS.BANG:bang,
CMPVER.KEYS.TYPE:CMPVER.TYPE.LIT,
CMPVER.KEYS.PARTS:this.parseLiteral()
}
default: default:
return {bang:bang,type:"identifier",parts:parseIdentifier(inside)} return {
CMPVER.KEYS.BANG:bang,
CMPVER.KEYS.TYPE:CMPVER.TYPE.ID,
CMPVER.KEYS.PARTS:this.parseIdentifier(inside)
}
} }
this.debugStack.pop() this.debugStack.pop()
@ -279,7 +297,7 @@ class spinnyParser {
this.next(); // Skip `{' this.next(); // Skip `{'
let lines = [] let lines = []
while (this.now() !== "}") { while (this.now() !== "}") {
lines.push(parseLine("L")) lines.push(this.parseLine(INSIDE.LAZY))
} }
this.debugStack.pop() this.debugStack.pop()
return lines return lines
@ -292,11 +310,11 @@ class spinnyParser {
while (this.now() !== "\'") { while (this.now() !== "\'") {
switch (this.now()) { switch (this.now()) {
case "\\": case "\\":
parts[parts.length-1]+=parseEscape(); parts[parts.length-1]+=this.parseEscape();
break break
case "<": case "<":
parts.push( parts.push(
parseInterpolation() this.parseInterpolation()
); );
parts.push("") parts.push("")
break break
@ -330,7 +348,6 @@ class spinnyParser {
out = String.fromCharCode( parseInt( out = String.fromCharCode( parseInt(
this.next()+this.next()+this.next()+this.next() this.next()+this.next()+this.next()+this.next()
,16)); ,16));
);
break break
case "U": case "U":
this.next(); // skip `U' this.next(); // skip `U'
@ -338,7 +355,6 @@ class spinnyParser {
this.next()+this.next()+this.next()+this.next()+ this.next()+this.next()+this.next()+this.next()+
this.next()+this.next()+this.next()+this.next() this.next()+this.next()+this.next()+this.next()
,16)); ,16));
);
break break
case "s": case "s":
this.next(); // skip `s' this.next(); // skip `s'
@ -368,7 +384,7 @@ class spinnyParser {
this.next(); // skip `\<' this.next(); // skip `\<'
let line let line
while (this.now() !== ">") { while (this.now() !== ">") {
line = parseLine("I") line = this.parseLine(INSIDE.INTER)
} }
this.next(); // skip `>' this.next(); // skip `>'
this.debugStack.pop() this.debugStack.pop()
@ -382,20 +398,20 @@ class spinnyParser {
while (1) { while (1) {
switch (this.now()) { switch (this.now()) {
case "\\": case "\\":
parts[parts.length-1]+=parseEscape(); parts[parts.length-1]+=this.parseEscape();
continue continue
case "<": case "<":
parts.push( parts.push(
parseInterpolation() this.parseInterpolation()
); );
parts.push("") parts.push("")
continue continue
case "}": case "}":
if (inside === "L") if (inside === INSIDE.LAZY)
break idLoop break idLoop
break break
case ">": case ">":
if (inside === "I") if (inside === INSIDE.INTER)
break idLoop break idLoop
break break
case "#": case "#":
@ -407,9 +423,25 @@ class spinnyParser {
this.debugStack.pop(); this.debugStack.pop();
return parts return parts
} }
} }
const SPIDNEY = {//spinny identifiers
"noversion": {
NAME: "noversion",
KEYS: {
TYPE: "t",
BANG: "b",
PARTS: "p",
LINES: "l"
},
TYPE: {
LIT: 0,
ID: 1,
LAZY: 2
}
}
}
const CMPVER = SPIDNEY["noversion"] //compileversion
// When the program starts: // When the program starts:
onRun(); onRun();