freemarker-parser
Version:
Freemarker Parser is a javascript implementation of the Freemarker
127 lines • 4.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maxUnaryOps = exports.maxBinaryOps = exports.getMaxKeyLength = exports.BinaryOps = exports.UnaryOps = exports.Literals = exports.Operators = void 0;
var Operators;
(function (Operators) {
Operators["FALSE"] = "false";
Operators["TRUE"] = "true";
Operators["RAW_STRING"] = "\"";
Operators["RAW_STRING2"] = "'";
Operators["DOT"] = ".";
Operators["DOT_DOT"] = "..";
Operators["DOT_DOT_LESS"] = "..<";
Operators["DOT_DOT_NOT"] = "..!";
Operators["DOT_DOT_ASTERISK"] = "..*";
Operators["BUILT_IN"] = "?";
Operators["EXISTS"] = "??";
Operators["EQUALS"] = "=";
Operators["DOUBLE_EQUALS"] = "==";
Operators["NOT_EQUALS"] = "!=";
Operators["PLUS_EQUALS"] = "+=";
Operators["MINUS_EQUALS"] = "-=";
Operators["TIMES_EQUALS"] = "*=";
Operators["DIV_EQUALS"] = "/=";
Operators["MOD_EQUALS"] = "%=";
Operators["PLUS_PLUS"] = "++";
Operators["MINUS_MINUS"] = "--";
Operators["ESCAPED_LT"] = "lt";
Operators["ESCAPED_LTE"] = "lte";
Operators["NATURAL_LT"] = "<";
Operators["NATURAL_LTE"] = "<=";
Operators["ESCAPED_GT"] = "gt";
Operators["ESCAPED_GTE"] = "gte";
Operators["NATURAL_GT"] = ">";
Operators["NATURAL_GTE"] = ">=";
Operators["PLUS"] = "+";
Operators["MINUS"] = "-";
Operators["TIMES"] = "*";
Operators["DOUBLE_STAR"] = "**";
Operators["ELLIPSIS"] = "...";
Operators["DIVIDE"] = "/";
Operators["PERCENT"] = "%";
Operators["AND"] = "&&";
Operators["OR"] = "||";
Operators["EXCLAM"] = "!";
Operators["COMMA"] = ",";
Operators["SEMICOLON"] = ";";
Operators["COLON"] = ":";
Operators["OPEN_BRACKET"] = "[";
Operators["CLOSE_BRACKET"] = "]";
Operators["OPEN_PAREN"] = "(";
Operators["CLOSE_PAREN"] = ")";
Operators["OPENING_CURLY_BRACKET"] = "{";
Operators["CLOSING_CURLY_BRACKET"] = "}";
Operators["IN"] = "in";
Operators["AS"] = "as";
Operators["USING"] = "using";
})(Operators = exports.Operators || (exports.Operators = {}));
// Store the values to return for the various literals we may encounter
exports.Literals = {
[]: true,
[]: false,
};
// Use a quickly-accessible map to store all of the unary operators
exports.UnaryOps = {
[]: true,
[]: true,
[]: true,
[]: true,
[]: true,
[]: true,
[]: true,
};
/**
* @see http://en.wikipedia.org/wiki/Order_of_operations#Programming_language
*/
exports.BinaryOps = {
// Assignment operators (right to left)
[]: 0,
[]: 0,
[]: 0,
[]: 0,
[]: 0,
[]: 0,
[]: 0,
[]: 0,
[]: 0,
// Logical OR
[]: 1,
// Logical AND
[]: 2,
// Comparisons: equal and not equal
[]: 6,
[]: 6,
// Comparisons: less-than and greater-than
[]: 7,
[]: 7,
[]: 7,
[]: 7,
[]: 7,
[]: 7,
[]: 7,
[]: 7,
// unary operators
[]: 9,
[]: 9,
[]: 10,
[]: 10,
[]: 10,
// Custom
[]: 11,
};
// Get return the longest key length of any object
function getMaxKeyLength(obj) {
let maxLen = 0;
let len;
for (const key of Object.keys(obj)) {
len = key.length;
if (len > maxLen) {
maxLen = len;
}
}
return maxLen;
}
exports.getMaxKeyLength = getMaxKeyLength;
exports.maxBinaryOps = getMaxKeyLength(exports.BinaryOps);
exports.maxUnaryOps = getMaxKeyLength(exports.UnaryOps);
//# sourceMappingURL=Operators.js.map