Some small fixes

This commit is contained in:
Mewrry the Kitty 2025-12-31 16:10:35 -06:00
parent 5767f131a1
commit c258f046b2

117
spinny.js
View file

@ -23,7 +23,7 @@ function onRun() {
}
const fileSpincVersion = file.split("\n")[1].split("@");
let isSpincFile = false;
if (fileSpincVersion.slice(0,2) === ["SPINC","spinny:itty" ]) {
if (fileSpincVersion.slice(0,2).join("\n") === "SPINC\nspinny:itty") {
// This is a spinny source file
if (fileSpincVersion[2] !== "noversion") {
let niceversion = spileSpincVersion[2].replace(
@ -97,7 +97,7 @@ function showVersion(){
// . 1 . 2 . 3 . 4 . 5 . 6
// ^
"Spinny for itty\n" +
"Version 0.0.1\n" +
"Version 0.0.2\n" +
"Known spinc versions:\n"
" • `noversion'\n"
)
@ -135,17 +135,17 @@ function parseCliArgs() {
}
if (flag) {
if (arg === "compile" || arg === "c") {
compileonly = true;
compileOnly = true;
} else if (arg === "help" || arg === "h") {
showhelp();
showHelp();
quit();
} else if (arg === "version" || arg === "v") {
showversion();
showVersion();
quit();
} else if (arg === "output" || arg === "o") {
nextisoutput = true;
nextIsOutput = true;
} else if (arg === "" && !letterFlag) {
nomoreflags = true;
noMoreFlags = true;
} else {
if (letterFlag){
display.print(`Spinny: Unrecognized flag \`-${arg}'.`);
@ -162,7 +162,7 @@ function parseCliArgs() {
}
return {
filename: filename,
compile_only: compileOnly,
compileOnly: compileOnly,
output: output
};
}
@ -181,8 +181,8 @@ class spinnyParser {
// A bunch of lines
while (this.index+1 < this.file.length) {
if (now() == "\n") {
next();
if (this.now() == "\n") {
this.next();
continue
}
lines.push(parseLine("F"))
@ -200,12 +200,12 @@ class spinnyParser {
let words = []
wordLoop:
while (1) {
switch (now()) {
switch (this.now()) {
case " ":
case "\t":
// advance past whitespace till
// next word
next();
this.next();
continue
case "#":
parseComment();
@ -223,11 +223,11 @@ class spinnyParser {
break wordLoop
break
case "\\":
if (now() == "\\" && peek() == "\n") {
if (this.now() == "\\" && this.peek() == "\n") {
// Line continuation
// Go to next line
next(); // skip `\\'
next(); // skip `\n'
this.next(); // skip `\\'
this.next(); // skip `\n'
continue
}
break
@ -242,14 +242,14 @@ class spinnyParser {
this.debugStack.push(["Comment", this.index])
commentLoop:
while (1) {
switch (now()) {
switch (this.now()) {
case "\n":
break commentLoop
case "\\":
if (peek() == "\n")
if (this.peek() == "\n")
break commentLoop
default:
next();
this.next();
}
}
this.debugStack.pop()
@ -257,13 +257,18 @@ class spinnyParser {
parseWord(inside) {
this.debugStack.push(["Word", this.index])
switch (now()) {
let bang = false;
if (this.now() === "!") {
bang = true;
this.next();
}
switch (this.now()) {
case "{":
return {type:"lazy",lines:parseLazy()}
return {bang:bang,type:"lazy",lines:parseLazy()}
case "`":
return {type:"literal",parts:parseLiteral()}
return {bang:bang,type:"literal",parts:parseLiteral()}
default:
return {type:"identifier",parts:parseIdentifier(inside)}
return {bang:bang,type:"identifier",parts:parseIdentifier(inside)}
}
this.debugStack.pop()
@ -271,9 +276,9 @@ class spinnyParser {
parseLazy() {
this.debugStack.push(["Lazy", this.index])
next(); // Skip `{'
this.next(); // Skip `{'
let lines = []
while (now() !== "}") {
while (this.now() !== "}") {
lines.push(parseLine("L"))
}
this.debugStack.pop()
@ -282,10 +287,10 @@ class spinnyParser {
parseLiteral() {
this.debugStack.push(["Literal", this.index])
next(); // Skip `\`'
let parts = []
while (now() !== "\'") {
switch (now()) {
this.next(); // Skip `\`'
let parts = [""]
while (this.now() !== "\'") {
switch (this.now()) {
case "\\":
parts[parts.length-1]+=parseEscape();
break
@ -296,8 +301,8 @@ class spinnyParser {
parts.push("")
break
default:
parts[parts.length-1]+=now();
next();
parts[parts.length-1]+=this.now();
this.next();
break
}
}
@ -307,46 +312,50 @@ class spinnyParser {
parseEscape() {
this.debugStack.push(["Literal", this.index])
next(); // skip `\\'
this.next(); // skip `\\'
let out = "";
switch (now()) {
switch (this.now()) {
case "<":
next(); // skip `\<'
this.next(); // skip `\<'
out = "<";
break
case "x":
next(); // skip `x'
out = String.fromCharCode(next()+next());
this.next(); // skip `x'
out = String.fromCharCode( parseInt(
this.next()+this.next()
,16));
break
case "u":
next(); // skip `u'
out = String.fromCharCode(
next()+next()+next()+next()
this.next(); // skip `u'
out = String.fromCharCode( parseInt(
this.next()+this.next()+this.next()+this.next()
,16));
);
break
case "U":
next(); // skip `U'
out = String.fromCharCode(
next()+next()+next()+next()+
next()+next()+next()+next()
this.next(); // skip `U'
out = String.fromCharCode( parseInt(
this.next()+this.next()+this.next()+this.next()+
this.next()+this.next()+this.next()+this.next()
,16));
);
break
case "s":
next(); // skip `s'
this.next(); // skip `s'
out = " ";
break
case "t":
next(); // skip `t'
this.next(); // skip `t'
out = "\t";
break
case "n":
next(); // skip `n'
this.next(); // skip `n'
out = "\n";
break
default:
// Just send the character:
out = now(); // record the thing after the `\\'
next(); // skip over it
out = this.now(); // record the thing after the `\\'
this.next(); // skip over it
break
}
@ -356,22 +365,22 @@ class spinnyParser {
parseInterpolation() {
this.debugStack.push(["Interpolation", this.index])
next(); // skip `\<'
this.next(); // skip `\<'
let line
while (now() !== ">") {
while (this.now() !== ">") {
line = parseLine("I")
}
next(); // skip `>'
this.next(); // skip `>'
this.debugStack.pop()
return line
}
parseIdentifier(inside) {
this.debugStack.push(["Identifier", this.index])
let parts = []
let parts = [""]
idLoop:
while (1) {
switch (now()) {
switch (this.now()) {
case "\\":
parts[parts.length-1]+=parseEscape();
continue
@ -392,8 +401,8 @@ class spinnyParser {
case "#":
break idLoop
}
parts[parts.length-1]+=now();
next();
parts[parts.length-1]+=this.now();
this.next();
}
this.debugStack.pop();
return parts