mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-29 12:27:07 +02:00
Added InputStream, Tokenizer, and Parser(unfinished) class. Changed Newerth to Aevum
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/* InputStream class. Creates a "stream object" that provides operations to read
|
||||
* from a string. */
|
||||
function InputStream(input) {
|
||||
var pos = 0, line = 1, col = 0;
|
||||
return {
|
||||
next : next,
|
||||
peek : peek,
|
||||
eof : eof,
|
||||
croak : croak,
|
||||
};
|
||||
function next() {
|
||||
var ch = input.charAt(pos++);
|
||||
if (ch == "\n") line++, col = 0; else col++;
|
||||
return ch;
|
||||
}
|
||||
function peek() {
|
||||
return input.charAt(pos);
|
||||
}
|
||||
function eof() {
|
||||
return peek() == "";
|
||||
}
|
||||
function croak(msg) {
|
||||
throw new Error(msg + " (" + line + ":" + col + ")");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user