numenor
Version:
Customizable, safe evaluator of JavaScript-like expressions.
173 lines (91 loc) • 8.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExpressionLexer = void 0;
var _Lexer2 = require("./Lexer");
var _Whitespace = require("./Lexer/Scanner/Whitespace");
var _Identifier = require("./Lexer/Scanner/Identifier");
var _StringLiteral = require("./Lexer/Scanner/StringLiteral");
var _NumberLiteral = require("./Lexer/Scanner/NumberLiteral");
var _Punctuation = require("./Lexer/Scanner/Punctuation");
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var ExpressionLexer =
/*#__PURE__*/
function (_Lexer) {
_inherits(ExpressionLexer, _Lexer);
function ExpressionLexer() {
var _this;
_classCallCheck(this, ExpressionLexer);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ExpressionLexer).call(this));
_this.appendScanner(_Whitespace.Whitespace);
_this.appendScanner(_Whitespace.LineTerminator);
_this.appendScanner(_Identifier.Identifier); // also handles keywords
_this.appendScanner(_StringLiteral.StringLiteral);
_this.appendScanner(_NumberLiteral.NumberLiteral);
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('...', _Lexer2.TokenType.Ellipsis));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('.', _Lexer2.TokenType.Dot));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('(', _Lexer2.TokenType.LParen));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)(')', _Lexer2.TokenType.RParen));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('[', _Lexer2.TokenType.LBracket));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)(']', _Lexer2.TokenType.RBracket));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('{', _Lexer2.TokenType.LBrace));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('}', _Lexer2.TokenType.RBrace));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)(',', _Lexer2.TokenType.Comma));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)(':', _Lexer2.TokenType.Colon));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('++', _Lexer2.TokenType.PlusPlus, _Lexer2.TokenType.Plus));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('+=', _Lexer2.TokenType.PlusEq, _Lexer2.TokenType.Plus));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('+', _Lexer2.TokenType.Plus));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('--', _Lexer2.TokenType.MinusMinus, _Lexer2.TokenType.Minus));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('-=', _Lexer2.TokenType.MinusEq, _Lexer2.TokenType.Minus));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('-', _Lexer2.TokenType.Minus));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('=>', _Lexer2.TokenType.RightArrow));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('===', _Lexer2.TokenType.EqEqEq));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('==', _Lexer2.TokenType.EqEq));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('=', _Lexer2.TokenType.Eq, _Lexer2.TokenType.Eq));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('!==', _Lexer2.TokenType.BangEqEq));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('!=', _Lexer2.TokenType.BangEq));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('!', _Lexer2.TokenType.Bang));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('&&', _Lexer2.TokenType.AmpAmp));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('&=', _Lexer2.TokenType.AmpEq, _Lexer2.TokenType.Amp));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('&', _Lexer2.TokenType.Amp));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('||', _Lexer2.TokenType.PipePipe));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('|=', _Lexer2.TokenType.PipeEq, _Lexer2.TokenType.Pipe));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('|', _Lexer2.TokenType.Pipe));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('^=', _Lexer2.TokenType.CaretEq, _Lexer2.TokenType.Caret));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('^', _Lexer2.TokenType.Caret));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('~=', _Lexer2.TokenType.TildeEq, _Lexer2.TokenType.Tilde));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('~', _Lexer2.TokenType.Tilde));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('**=', _Lexer2.TokenType.StarStarEq, _Lexer2.TokenType.StarStar));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('**', _Lexer2.TokenType.StarStar));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('*=', _Lexer2.TokenType.StarEq, _Lexer2.TokenType.Star));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('*', _Lexer2.TokenType.Star));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('/=', _Lexer2.TokenType.SlashEq, _Lexer2.TokenType.Slash));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('/', _Lexer2.TokenType.Slash));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('%=', _Lexer2.TokenType.PercentEq, _Lexer2.TokenType.Percent));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('%', _Lexer2.TokenType.Percent));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('<<=', _Lexer2.TokenType.LtLtEq, _Lexer2.TokenType.LtLt));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('<<', _Lexer2.TokenType.LtLt));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('<=', _Lexer2.TokenType.LtEq, _Lexer2.TokenType.Lt));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('<', _Lexer2.TokenType.Lt));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('>>>=', _Lexer2.TokenType.GtGtGtEq, _Lexer2.TokenType.GtGtGt));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('>>>', _Lexer2.TokenType.GtGtGt));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('>>=', _Lexer2.TokenType.GtGtEq, _Lexer2.TokenType.GtGt));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('>>', _Lexer2.TokenType.GtGt));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('>=', _Lexer2.TokenType.GtEq, _Lexer2.TokenType.Gt));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('>', _Lexer2.TokenType.Gt));
_this.appendScanner((0, _Punctuation.makeOperatorScanner)('??=', _Lexer2.TokenType.QuestionQuestionEq, _Lexer2.TokenType.QuestionQuestion));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('??', _Lexer2.TokenType.QuestionQuestion));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('?.', _Lexer2.TokenType.QuestionDot));
_this.appendScanner((0, _Punctuation.makePunctuationScanner)('?', _Lexer2.TokenType.Question));
return _this;
}
return ExpressionLexer;
}(_Lexer2.Lexer);
exports.ExpressionLexer = ExpressionLexer;