jql-parser
Version:
* Validating queries
99 lines (98 loc) • 3.5 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Expression = void 0;
var Parenthesis_1 = require("./Parenthesis");
var separators_1 = require("./separators");
var Term_1 = require("./Term");
var Token_1 = require("./Token");
/**
* expression(Or,And) :== term [ separator(Or,And) { paren{expression} | expression } ]
*/
var Expression = /** @class */ (function (_super) {
__extends(Expression, _super);
function Expression() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Expression.prototype, "end", {
get: function () {
var end = this.term.end;
if (this.separator) {
end += this.separator.end;
}
if (this.paren) {
if (this.paren.end > 0) {
end += this.paren.end;
}
else if (this.expression) {
end += this.expression.end;
}
}
return end;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Expression.prototype, "content", {
get: function () {
var str = this.term.content;
if (this.separator) {
str += " " + this.separator.content + " ";
}
if (this.expression) {
str += " " + this.expression.content;
}
return str;
},
set: function (value) {
throw new Error("Method not implemented.");
},
enumerable: false,
configurable: true
});
// TODO flatten expressions!
Expression.prototype.parse = function (input) {
this.term = new Term_1.Term();
if (this.term.parse(input)) {
var next = input.substr(this.term.end);
if (next === "" || next === " ") {
return true;
}
this.separator = parseSeparator(next);
if (this.separator) {
next = next.substr(this.separator.end);
this.expression = new Expression();
this.paren = new Parenthesis_1.Parenthesis();
if (this.paren.parse(next)) {
return this.expression.parse(this.paren.content);
}
return this.expression.parse(next);
}
}
return false;
};
return Expression;
}(Token_1.Token));
exports.Expression = Expression;
var SEPARATORS = [function () { return new separators_1.And(); }, function () { return new separators_1.Or(); }];
function parseSeparator(jql) {
for (var _i = 0, SEPARATORS_1 = SEPARATORS; _i < SEPARATORS_1.length; _i++) {
var separator = SEPARATORS_1[_i];
var s = separator();
if (s.parse(jql)) {
return s;
}
}
}