mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 07:44:03 +09:00
tvdos: parsing pipe operator
This commit is contained in:
@@ -138,14 +138,15 @@ shell.getPwdString = function() { return "\\" + (shell_pwd.concat([""])).join("\
|
|||||||
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
|
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
|
||||||
// example input: echo "the string" > subdir\test.txt
|
// example input: echo "the string" > subdir\test.txt
|
||||||
shell.parse = function(input) {
|
shell.parse = function(input) {
|
||||||
var tokens = [];
|
let tokens = [];
|
||||||
var stringBuffer = "";
|
let stringBuffer = "";
|
||||||
var mode = "LITERAL"; // LITERAL, QUOTE, ESCAPE, LIMBO
|
let mode = "LITERAL"; // LITERAL, QUOTE, ESCAPE, LIMBO, OP
|
||||||
var i = 0
|
let i = 0
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
const c = input[i];
|
const c = input[i];
|
||||||
/*digraph g {
|
/*digraph g {
|
||||||
LITERAL -> QUOTE [label="\""]
|
LITERAL -> QUOTE [label="\""]
|
||||||
|
LITERAL -> OP [label="pipe"]
|
||||||
LITERAL -> LIMBO [label="space"]
|
LITERAL -> LIMBO [label="space"]
|
||||||
LITERAL -> LITERAL [label=else]
|
LITERAL -> LITERAL [label=else]
|
||||||
|
|
||||||
@@ -158,6 +159,11 @@ shell.parse = function(input) {
|
|||||||
LIMBO -> LITERAL [label="not space"]
|
LIMBO -> LITERAL [label="not space"]
|
||||||
LIMBO -> QUOTE [label="\""]
|
LIMBO -> QUOTE [label="\""]
|
||||||
LIMBO -> LIMBO [label="space"]
|
LIMBO -> LIMBO [label="space"]
|
||||||
|
LIMBO -> OP [label="pipe"]
|
||||||
|
|
||||||
|
OP -> QUOTE [label="\""]
|
||||||
|
OP -> LIMBO [label="space"]
|
||||||
|
OP -> LITERAL [label=else]
|
||||||
}*/
|
}*/
|
||||||
if ("LITERAL" == mode) {
|
if ("LITERAL" == mode) {
|
||||||
if (' ' == c) {
|
if (' ' == c) {
|
||||||
@@ -168,6 +174,10 @@ shell.parse = function(input) {
|
|||||||
tokens.push(stringBuffer); stringBuffer = "";
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
mode = "QUOTE";
|
mode = "QUOTE";
|
||||||
}
|
}
|
||||||
|
else if ('|' == c || '>' == c || '&' == c || '<' == c) {
|
||||||
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
|
mode = "OP"
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
stringBuffer += c;
|
stringBuffer += c;
|
||||||
}
|
}
|
||||||
@@ -176,6 +186,10 @@ shell.parse = function(input) {
|
|||||||
if ('"' == c) {
|
if ('"' == c) {
|
||||||
mode = "QUOTE";
|
mode = "QUOTE";
|
||||||
}
|
}
|
||||||
|
else if ('|' == c || '>' == c || '&' == c || '<' == c) {
|
||||||
|
mode = "OP"
|
||||||
|
stringBuffer += c
|
||||||
|
}
|
||||||
else if (c != ' ') {
|
else if (c != ' ') {
|
||||||
mode = "LITERAL";
|
mode = "LITERAL";
|
||||||
stringBuffer += c;
|
stringBuffer += c;
|
||||||
@@ -193,6 +207,23 @@ shell.parse = function(input) {
|
|||||||
stringBuffer += c;
|
stringBuffer += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ("OP" == mode) {
|
||||||
|
if (' ' == c) {
|
||||||
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
|
mode = "LIMBO";
|
||||||
|
}
|
||||||
|
else if ('|' == c || '>' == c || '&' == c || '<' == c) {
|
||||||
|
stringBuffer += c
|
||||||
|
}
|
||||||
|
else if ('"' == c) {
|
||||||
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
|
mode = "QUOTE";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
|
mode = "LITERAL";
|
||||||
|
}
|
||||||
|
}
|
||||||
else if ("ESCAPE" == mode) {
|
else if ("ESCAPE" == mode) {
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
@@ -204,6 +235,8 @@ shell.parse = function(input) {
|
|||||||
tokens.push(stringBuffer);
|
tokens.push(stringBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(tokens)
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
shell.resolvePathInput = function(input) {
|
shell.resolvePathInput = function(input) {
|
||||||
|
|||||||
Reference in New Issue
Block a user