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