Skip to content

Commit 908005a

Browse files
committed
Add position of relation
1 parent 95764ea commit 908005a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cql.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ var CQLSearchClause = function (field, fielduri, relation, relationuri,
7373
this.scr = scr || DEFAULT_SERVER_CHOICE_RELATION;
7474
this._pos = null;
7575
this._range = null;
76+
this._relpos = null;
7677
}
7778

7879
CQLSearchClause.prototype = {
@@ -136,6 +137,7 @@ CQLSearchClause.prototype = {
136137
}
137138
if (this._pos !== null) s += ', "@pos": ' + this._pos;
138139
if (this._range !== null) s += ', "@range": ' + JSON.stringify(this._range);
140+
if (this._relpos !== null) s += ', "relation@pos": ' + this._relpos;
139141
s += '}';
140142
return s;
141143
},
@@ -226,6 +228,7 @@ var CQLParser = function () {
226228
this.lval = null;
227229
this.val = null;
228230
this._exprStart = null;
231+
this._exprRelStart = null;
229232
this.prefixes = new Object();
230233
this.tree = null;
231234
this.scf = null;
@@ -451,7 +454,8 @@ CQLParser.prototype = {
451454
this.scf,
452455
this.scr);
453456
sc._range = [this._exprStart, _tend];
454-
this._exprStart = null;
457+
sc._relpos = this._exprRelStart;
458+
this._exprStart = this._exprRelStart = null;
455459
return sc;
456460
}
457461
// prefixes
@@ -499,6 +503,7 @@ CQLParser.prototype = {
499503
} else if (this._strchr("<>=", c)) {
500504
this.look = c;
501505
this.qi++;
506+
this._exprRelStart = this.qi;
502507
//comparitors can repeat, could be if
503508
while (this.qi < this.ql
504509
&& this._strchr("<>=", this.qs.charAt(this.qi))) {

index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
let range = obj["@range"];
1717
s += '\n' + ("".padStart(range[0] - 1) + "t".padEnd(range[1] - range[0] + 1, "-")).padEnd(query.length + 1 + lvl) + "[term:" + range + "]"
1818
}
19+
if ("relation@pos" in obj) {
20+
let relpos = obj["relation@pos"];
21+
let relmodend = Math.max(...Object.entries(obj).filter(x => x[0].endsWith("@range") && x[0].length > 6).map(([_, range]) => range[1]));
22+
s += '\n' + ("".padStart(relpos - 1) + "r".padEnd(relmodend - relpos + 1, "-")).padEnd(query.length + 1 + lvl + 1) + "[term:rel:" + obj["relation"] + ":" + relpos + "]"
23+
}
1924
Object.entries(obj).filter(x => x[0].endsWith("@range") && x[0].length > 6).map(([_, range]) => {
20-
s += '\n' + ("".padStart(range[0] - 1) + "m".padEnd(range[1] - range[0] + 1, "-")).padEnd(query.length + 1 + lvl + 1) + "[term:mod:" + range + "]"
25+
s += '\n' + ("".padStart(range[0] - 1) + "m".padEnd(range[1] - range[0] + 1, "-")).padEnd(query.length + 1 + lvl + 2) + "[term:mod:" + range + "]"
2126
})
2227
} else if ("op" in obj) {
2328
if ("@range" in obj) {

0 commit comments

Comments
 (0)