UNPKG

nerdamer-ts

Version:

javascript light-weight symbolic math expression evaluator

41 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Token = void 0; class Token { constructor(node, node_type, column, operator) { this.is_prefix = false; this.column = 0; this.precedence = 0; this.leftAssoc = false; this.type = node_type; this.value = node; if (column !== undefined) { this.column = column + 1; } if (node_type === Token.OPERATOR && operator) { //copy everything over from the operator for (let x in operator) { this[x] = operator[x]; } } else if (node_type === Token.FUNCTION) { this.precedence = Token.MAX_PRECEDENCE; //leave enough roon this.leftAssoc = false; } } toString() { if (this.is_prefix) { return '`' + this.value; } return this.value; } } exports.Token = Token; //some constants Token.OPERATOR = 'OPERATOR'; Token.VARIABLE_OR_LITERAL = 'VARIABLE_OR_LITERAL'; Token.FUNCTION = 'FUNCTION'; Token.UNIT = 'UNIT'; Token.KEYWORD = 'KEYWORD'; Token.MAX_PRECEDENCE = 999; //# sourceMappingURL=Token.js.map