202 lines
4.2 KiB
JavaScript
202 lines
4.2 KiB
JavaScript
this.Token = class Token {
|
|
constructor(tokenizer, type, value, string_value) {
|
|
this.tokenizer = tokenizer;
|
|
this.type = type;
|
|
this.value = value;
|
|
this.string_value = string_value;
|
|
this.line = this.tokenizer.line;
|
|
this.column = this.tokenizer.column;
|
|
this.start = this.tokenizer.token_start;
|
|
this.length = this.tokenizer.index - this.start;
|
|
this.index = this.tokenizer.index;
|
|
if (this.type === Token.TYPE_IDENTIFIER && Token.predefined.hasOwnProperty(this.value)) {
|
|
this.type = Token.predefined[this.value];
|
|
this.reserved_keyword = true;
|
|
}
|
|
this.is_binary_operator = (this.type >= 30 && this.type <= 39) || (this.type >= 200 && this.type <= 201) || (this.type >= 2 && this.type <= 7);
|
|
}
|
|
|
|
toString() {
|
|
return this.value + " : " + this.type;
|
|
}
|
|
|
|
};
|
|
|
|
this.Token.TYPE_EQUALS = 1;
|
|
|
|
this.Token.TYPE_DOUBLE_EQUALS = 2;
|
|
|
|
this.Token.TYPE_GREATER = 3;
|
|
|
|
this.Token.TYPE_GREATER_OR_EQUALS = 4;
|
|
|
|
this.Token.TYPE_LOWER = 5;
|
|
|
|
this.Token.TYPE_LOWER_OR_EQUALS = 6;
|
|
|
|
this.Token.TYPE_UNEQUALS = 7;
|
|
|
|
this.Token.TYPE_IDENTIFIER = 10;
|
|
|
|
this.Token.TYPE_NUMBER = 11;
|
|
|
|
this.Token.TYPE_STRING = 12;
|
|
|
|
this.Token.TYPE_OPEN_BRACE = 20;
|
|
|
|
this.Token.TYPE_CLOSED_BRACE = 21;
|
|
|
|
// @Token.TYPE_OPEN_CURLY_BRACE = 22
|
|
// @Token.TYPE_CLOSED_CURLY_BRACE = 23
|
|
this.Token.TYPE_OPEN_BRACKET = 24;
|
|
|
|
this.Token.TYPE_CLOSED_BRACKET = 25;
|
|
|
|
this.Token.TYPE_COMMA = 26;
|
|
|
|
this.Token.TYPE_DOT = 27;
|
|
|
|
this.Token.TYPE_PLUS = 30;
|
|
|
|
this.Token.TYPE_MINUS = 31;
|
|
|
|
this.Token.TYPE_MULTIPLY = 32;
|
|
|
|
this.Token.TYPE_DIVIDE = 33;
|
|
|
|
this.Token.TYPE_POWER = 34;
|
|
|
|
this.Token.TYPE_MODULO = 35;
|
|
|
|
this.Token.TYPE_BINARY_AND = 36;
|
|
|
|
this.Token.TYPE_BINARY_OR = 37;
|
|
|
|
this.Token.TYPE_SHIFT_LEFT = 38;
|
|
|
|
this.Token.TYPE_SHIFT_RIGHT = 39;
|
|
|
|
this.Token.TYPE_PLUS_EQUALS = 40;
|
|
|
|
this.Token.TYPE_MINUS_EQUALS = 41;
|
|
|
|
this.Token.TYPE_MULTIPLY_EQUALS = 42;
|
|
|
|
this.Token.TYPE_DIVIDE_EQUALS = 43;
|
|
|
|
this.Token.TYPE_MODULO_EQUALS = 44;
|
|
|
|
this.Token.TYPE_AND_EQUALS = 45;
|
|
|
|
this.Token.TYPE_OR_EQUALS = 46;
|
|
|
|
this.Token.TYPE_RETURN = 50;
|
|
|
|
this.Token.TYPE_BREAK = 51;
|
|
|
|
this.Token.TYPE_CONTINUE = 52;
|
|
|
|
this.Token.TYPE_FUNCTION = 60;
|
|
|
|
this.Token.TYPE_AFTER = 61;
|
|
|
|
this.Token.TYPE_EVERY = 62;
|
|
|
|
this.Token.TYPE_DO = 63;
|
|
|
|
this.Token.TYPE_SLEEP = 64;
|
|
|
|
this.Token.TYPE_LOCAL = 70;
|
|
|
|
this.Token.TYPE_OBJECT = 80;
|
|
|
|
this.Token.TYPE_CLASS = 90;
|
|
|
|
this.Token.TYPE_EXTENDS = 91;
|
|
|
|
this.Token.TYPE_NEW = 92;
|
|
|
|
this.Token.TYPE_FOR = 100;
|
|
|
|
this.Token.TYPE_TO = 101;
|
|
|
|
this.Token.TYPE_BY = 102;
|
|
|
|
this.Token.TYPE_IN = 103;
|
|
|
|
this.Token.TYPE_WHILE = 104;
|
|
|
|
this.Token.TYPE_IF = 105;
|
|
|
|
this.Token.TYPE_THEN = 106;
|
|
|
|
this.Token.TYPE_ELSE = 107;
|
|
|
|
this.Token.TYPE_ELSIF = 108;
|
|
|
|
this.Token.TYPE_END = 120;
|
|
|
|
this.Token.TYPE_AND = 200;
|
|
|
|
this.Token.TYPE_OR = 201;
|
|
|
|
this.Token.TYPE_NOT = 202;
|
|
|
|
this.Token.TYPE_ERROR = 404;
|
|
|
|
this.Token.predefined = {};
|
|
|
|
this.Token.predefined["return"] = this.Token.TYPE_RETURN;
|
|
|
|
this.Token.predefined["break"] = this.Token.TYPE_BREAK;
|
|
|
|
this.Token.predefined["continue"] = this.Token.TYPE_CONTINUE;
|
|
|
|
this.Token.predefined["function"] = this.Token.TYPE_FUNCTION;
|
|
|
|
this.Token.predefined["for"] = this.Token.TYPE_FOR;
|
|
|
|
this.Token.predefined["to"] = this.Token.TYPE_TO;
|
|
|
|
this.Token.predefined["by"] = this.Token.TYPE_BY;
|
|
|
|
this.Token.predefined["in"] = this.Token.TYPE_IN;
|
|
|
|
this.Token.predefined["while"] = this.Token.TYPE_WHILE;
|
|
|
|
this.Token.predefined["if"] = this.Token.TYPE_IF;
|
|
|
|
this.Token.predefined["then"] = this.Token.TYPE_THEN;
|
|
|
|
this.Token.predefined["else"] = this.Token.TYPE_ELSE;
|
|
|
|
this.Token.predefined["elsif"] = this.Token.TYPE_ELSIF;
|
|
|
|
this.Token.predefined["end"] = this.Token.TYPE_END;
|
|
|
|
this.Token.predefined["object"] = this.Token.TYPE_OBJECT;
|
|
|
|
this.Token.predefined["class"] = this.Token.TYPE_CLASS;
|
|
|
|
this.Token.predefined["extends"] = this.Token.TYPE_EXTENDS;
|
|
|
|
this.Token.predefined["new"] = this.Token.TYPE_NEW;
|
|
|
|
this.Token.predefined["and"] = this.Token.TYPE_AND;
|
|
|
|
this.Token.predefined["or"] = this.Token.TYPE_OR;
|
|
|
|
this.Token.predefined["not"] = this.Token.TYPE_NOT;
|
|
|
|
this.Token.predefined["after"] = this.Token.TYPE_AFTER;
|
|
|
|
this.Token.predefined["every"] = this.Token.TYPE_EVERY;
|
|
|
|
this.Token.predefined["do"] = this.Token.TYPE_DO;
|
|
|
|
this.Token.predefined["sleep"] = this.Token.TYPE_SLEEP;
|
|
|
|
this.Token.predefined["delete"] = this.Token.TYPE_DELETE;
|
|
|
|
this.Token.predefined["local"] = this.Token.TYPE_LOCAL;
|