phase 3
This commit is contained in:
@@ -1,2 +1,42 @@
|
||||
const message: string = "Hello, World!";
|
||||
console.log(message);
|
||||
|
||||
function parse(input: string) {
|
||||
let buffer: string[] = [];
|
||||
const tokens: string[] = [];
|
||||
let state: string = "";
|
||||
let escape = false;
|
||||
|
||||
for (const char of input) {
|
||||
if (state.length === 0) {
|
||||
if (char === " ") {
|
||||
tokens.push(buffer.join(""));
|
||||
buffer = [];
|
||||
continue;
|
||||
}
|
||||
if (char === "'" || char === '"') {
|
||||
state = char;
|
||||
continue;
|
||||
}
|
||||
buffer.push(char);
|
||||
continue;
|
||||
} else {
|
||||
if (char === state) {
|
||||
state = "";
|
||||
tokens.push(buffer.join(""));
|
||||
buffer = [];
|
||||
continue;
|
||||
}
|
||||
if (char === "\\") {
|
||||
escape = true;
|
||||
continue;
|
||||
}
|
||||
buffer.push(char);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
tokens.push(buffer.join(""));
|
||||
return tokens;
|
||||
}
|
||||
|
||||
console.log(parse('"Hello World"'));
|
||||
|
||||
Reference in New Issue
Block a user