This commit is contained in:
2026-07-22 21:31:55 +02:00
parent 0a477855c7
commit cab18b74cf
5 changed files with 59 additions and 3 deletions
+40
View File
@@ -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"'));