From 761f9b626487edcd73ad0c3942ed5dcc8658077b Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 12 May 2022 20:52:43 +0900 Subject: [PATCH] tvdos: parsing pipe operator --- assets/disk0/tvdos/bin/command.js | 41 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index b97e082..558dadd 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -138,14 +138,15 @@ shell.getPwdString = function() { return "\\" + (shell_pwd.concat([""])).join("\ shell.getCurrentDrive = function() { return CURRENT_DRIVE; } // example input: echo "the string" > subdir\test.txt shell.parse = function(input) { - var tokens = []; - var stringBuffer = ""; - var mode = "LITERAL"; // LITERAL, QUOTE, ESCAPE, LIMBO - var i = 0 + let tokens = []; + let stringBuffer = ""; + let mode = "LITERAL"; // LITERAL, QUOTE, ESCAPE, LIMBO, OP + let i = 0 while (i < input.length) { const c = input[i]; /*digraph g { LITERAL -> QUOTE [label="\""] + LITERAL -> OP [label="pipe"] LITERAL -> LIMBO [label="space"] LITERAL -> LITERAL [label=else] @@ -158,6 +159,11 @@ shell.parse = function(input) { LIMBO -> LITERAL [label="not space"] LIMBO -> QUOTE [label="\""] LIMBO -> LIMBO [label="space"] + LIMBO -> OP [label="pipe"] + + OP -> QUOTE [label="\""] + OP -> LIMBO [label="space"] + OP -> LITERAL [label=else] }*/ if ("LITERAL" == mode) { if (' ' == c) { @@ -168,6 +174,10 @@ shell.parse = function(input) { tokens.push(stringBuffer); stringBuffer = ""; mode = "QUOTE"; } + else if ('|' == c || '>' == c || '&' == c || '<' == c) { + tokens.push(stringBuffer); stringBuffer = ""; + mode = "OP" + } else { stringBuffer += c; } @@ -176,6 +186,10 @@ shell.parse = function(input) { if ('"' == c) { mode = "QUOTE"; } + else if ('|' == c || '>' == c || '&' == c || '<' == c) { + mode = "OP" + stringBuffer += c + } else if (c != ' ') { mode = "LITERAL"; stringBuffer += c; @@ -193,6 +207,23 @@ shell.parse = function(input) { 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) { TODO(); } @@ -204,6 +235,8 @@ shell.parse = function(input) { tokens.push(stringBuffer); } + println(tokens) + return tokens; } shell.resolvePathInput = function(input) {