Assemble kernel on the client #1
24
asm.js
24
asm.js
@@ -9,9 +9,11 @@ class Tokenizer {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.delims = new Set([" ", "\r", "\n", "\t"]);
|
this.delims = new Set([" ", "\r", "\n", "\t"]);
|
||||||
this.skips = new Set([" ", "\r", "\t"]);
|
this.skips = new Set([" ", "\r", "\t"]);
|
||||||
this.comment_start = ";"
|
this.comment_start = ";";
|
||||||
|
this.string_quote = '"';
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.comment = false;
|
this.comment = false;
|
||||||
|
this.string = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip() {
|
skip() {
|
||||||
@@ -19,11 +21,31 @@ class Tokenizer {
|
|||||||
this.buffer = idx == -1 ? [] : this.buffer.slice(idx);
|
this.buffer = idx == -1 ? [] : this.buffer.slice(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next_string() {
|
||||||
|
const idx = this.buffer.findIndex((cp) => cp == this.string_quote);
|
||||||
|
if (idx == -1) {
|
||||||
|
this.string = true;
|
||||||
|
} else {
|
||||||
|
const string = this.buffer.slice(0, idx).join("");
|
||||||
|
this.buffer = this.buffer.slice(idx + 1);
|
||||||
|
this.string = false;
|
||||||
|
return { string: string };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
next() {
|
next() {
|
||||||
|
if (this.string)
|
||||||
|
return this.next_string();
|
||||||
|
|
||||||
this.skip();
|
this.skip();
|
||||||
if (this.buffer[0] == LINE_END)
|
if (this.buffer[0] == LINE_END)
|
||||||
return this.buffer.shift();
|
return this.buffer.shift();
|
||||||
|
|
||||||
|
if (this.buffer[0] == this.string_quote) {
|
||||||
|
this.buffer.shift();
|
||||||
|
return this.next_string();
|
||||||
|
}
|
||||||
|
|
||||||
const idx = this.buffer.findIndex((cp) => this.delims.has(cp));
|
const idx = this.buffer.findIndex((cp) => this.delims.has(cp));
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
const token = this.buffer.slice(0, idx).join("");
|
const token = this.buffer.slice(0, idx).join("");
|
||||||
|
|||||||
Reference in New Issue
Block a user