UNPKG

pip-services4-expressions-node

Version:

Tokenizers, parsers and expression calculators in Node.js / ES2017

51 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExpressionWordState = void 0; /** @module calculator */ const GenericWordState_1 = require("../../tokenizers/generic/GenericWordState"); const Token_1 = require("../../tokenizers/Token"); const TokenType_1 = require("../../tokenizers/TokenType"); /** * Implements a word state object. */ class ExpressionWordState extends GenericWordState_1.GenericWordState { /** * Constructs an instance of this class. */ constructor() { super(); /** * Supported expression keywords. */ this.keywords = [ "AND", "OR", "NOT", "XOR", "LIKE", "IS", "IN", "NULL", "TRUE", "FALSE" ]; this.clearWordChars(); this.setWordChars('a'.charCodeAt(0), 'z'.charCodeAt(0), true); this.setWordChars('A'.charCodeAt(0), 'Z'.charCodeAt(0), true); this.setWordChars('0'.charCodeAt(0), '9'.charCodeAt(0), true); this.setWordChars('_'.charCodeAt(0), '_'.charCodeAt(0), true); this.setWordChars(0x00c0, 0x00ff, true); this.setWordChars(0x0100, 0xfffe, true); } /** * Gets the next token from the stream started from the character linked to this state. * @param scanner A textual string to be tokenized. * @param tokenizer A tokenizer class that controls the process. * @returns The next token from the top of the stream. */ nextToken(scanner, tokenizer) { const line = scanner.peekLine(); const column = scanner.peekColumn(); const token = super.nextToken(scanner, tokenizer); const value = token.value.toUpperCase(); for (const keyword of this.keywords) { if (keyword == value) { return new Token_1.Token(TokenType_1.TokenType.Keyword, token.value, line, column); } } return token; } } exports.ExpressionWordState = ExpressionWordState; //# sourceMappingURL=ExpressionWordState.js.map