cmd parser

This commit is contained in:
minjaesong
2020-11-01 18:41:39 +09:00
parent 5d66234c47
commit a2e74313a1
2 changed files with 18 additions and 15 deletions

View File

@@ -8,6 +8,11 @@ _TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT;
//TODO //TODO
_TVDOS.defaults = {
path: [
""
]
};
Object.freeze(_TVDOS); Object.freeze(_TVDOS);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -71,12 +76,6 @@ var execApp = function(cmdsrc, args) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Boot script // Boot script
_TVDOS.defaults = {
path: [
""
]
};
filesystem.open("A", "tvdos/command.js", "R"); filesystem.open("A", "tvdos/command.js", "R");
let cmdsrc = filesystem.readAll("A"); let cmdsrc = filesystem.readAll("A");

View File

@@ -36,6 +36,7 @@ shell.parse = function(input) {
ESCAPE -> QUOTE ESCAPE -> QUOTE
LIMBO -> LITERAL [label="not space"] LIMBO -> LITERAL [label="not space"]
LIMBO -> QUOTE [label="\""]
LIMBO -> LIMBO [label="space"] LIMBO -> LIMBO [label="space"]
}*/ }*/
if (mode == "LITERAL") { if (mode == "LITERAL") {
@@ -52,7 +53,10 @@ shell.parse = function(input) {
} }
} }
else if (mode == "LIMBO") { else if (mode == "LIMBO") {
if (c != ' ') { if (c == '"') {
mode = "QUOTE";
}
else if (c != ' ') {
mode = "LITERAL"; mode = "LITERAL";
stringBuffer += c; stringBuffer += c;
} }
@@ -60,6 +64,7 @@ shell.parse = function(input) {
else if (mode == "QUOTE") { else if (mode == "QUOTE") {
if (c == '"') { if (c == '"') {
tokens.push(stringBuffer); stringBuffer = ""; tokens.push(stringBuffer); stringBuffer = "";
mode = "LIMBO";
} }
else if (c == '\\') { else if (c == '\\') {
mode = "ESCAPE"; mode = "ESCAPE";
@@ -72,14 +77,13 @@ shell.parse = function(input) {
} }
// end of the input string
if (i == input.length - 1) {
stringBuffer += c;
tokens.push(stringBuffer);
}
i += 1; i += 1;
} }
if (stringBuffer.length > 0) {
tokens.push(stringBuffer);
}
return tokens; return tokens;
} }
if (exec_args !== undefined) return shell; if (exec_args !== undefined) return shell;
@@ -116,8 +120,8 @@ while (true) {
else if (key === 10 || key === 13) { else if (key === 10 || key === 13) {
println(); println();
try { try {
println("You entered: " + cmdbuf); let tokens = shell.parse(cmdbuf);
tokens.forEach(function(it) { println(it+"_"); });
} }
catch (e) { catch (e) {
printerrln(e); printerrln(e);