@@ -27,6 +27,8 @@ var CQLModifier = function () {
27
27
this . name = null ;
28
28
this . relation = null ;
29
29
this . value = null ;
30
+ this . _pos = null ;
31
+ this . _range = null ;
30
32
}
31
33
32
34
CQLModifier . prototype = {
@@ -52,6 +54,8 @@ CQLModifier.prototype = {
52
54
//we assume 'true'
53
55
var value = this . value . length > 0 ? this . value : "true" ;
54
56
var s = '"' + this . name + '": "' + value + '"' ;
57
+ if ( this . _pos !== null ) s += ', "' + this . name + '@pos": ' + this . _pos ;
58
+ if ( this . _range !== null ) s += ', "' + this . name + '@range": ' + JSON . stringify ( this . _range ) ;
55
59
return s ;
56
60
}
57
61
}
@@ -67,6 +71,8 @@ var CQLSearchClause = function (field, fielduri, relation, relationuri,
67
71
this . term = term ;
68
72
this . scf = scf || DEFAULT_SERVER_CHOICE_FIELD ;
69
73
this . scr = scr || DEFAULT_SERVER_CHOICE_RELATION ;
74
+ this . _pos = null ;
75
+ this . _range = null ;
70
76
}
71
77
72
78
CQLSearchClause . prototype = {
@@ -128,6 +134,8 @@ CQLSearchClause.prototype = {
128
134
continue ;
129
135
s += ', ' + this . modifiers [ i ] . toFQ ( ) ;
130
136
}
137
+ if ( this . _pos !== null ) s += ', "@pos": ' + this . _pos ;
138
+ if ( this . _range !== null ) s += ', "@range": ' + JSON . stringify ( this . _range ) ;
131
139
s += '}' ;
132
140
return s ;
133
141
} ,
@@ -163,6 +171,7 @@ var CQLBoolean = function () {
163
171
this . modifiers = null ;
164
172
this . left = null ;
165
173
this . right = null ;
174
+ this . _pos = null ;
166
175
}
167
176
168
177
CQLBoolean . prototype = {
@@ -199,6 +208,7 @@ CQLBoolean.prototype = {
199
208
s += ', ' + this . modifiers [ i ] . toFQ ( ) ;
200
209
s += ',' + nl + indent ( n , c ) + ' "s1": ' + this . left . toFQ ( n + 1 , c , nl ) ;
201
210
s += ',' + nl + indent ( n , c ) + ' "s2": ' + this . right . toFQ ( n + 1 , c , nl ) ;
211
+ if ( this . _pos !== null ) s += ',' + nl + indent ( n , c ) + ' "@pos": ' + this . _pos ;
202
212
var fill = n && c ? ' ' : '' ;
203
213
s += nl + indent ( n - 1 , c ) + fill + '}' ;
204
214
return s ;
@@ -213,6 +223,7 @@ var CQLParser = function () {
213
223
this . look = null ;
214
224
this . lval = null ;
215
225
this . val = null ;
226
+ this . _exprStart = null ;
216
227
this . prefixes = new Object ( ) ;
217
228
this . tree = null ;
218
229
this . scf = null ;
@@ -230,6 +241,7 @@ CQLParser.prototype = {
230
241
this . qs = query ;
231
242
this . ql = this . qs . length ;
232
243
this . qi = 0 ;
244
+ this . lval = this . val = this . _exprStart = null ;
233
245
this . _move ( ) ;
234
246
this . tree = this . _parseQuery ( this . scf , this . scr , new Array ( ) ) ;
235
247
if ( this . look != "" )
@@ -285,6 +297,8 @@ CQLParser.prototype = {
285
297
for ( var key in fq ) {
286
298
if ( key == 'term' || key == 'field' || key == 'relation' )
287
299
continue ;
300
+ if ( key . endsWith ( "@pos" ) || key . endsWith ( "@range" ) )
301
+ continue ;
288
302
var mod = new CQLModifier ( ) ;
289
303
mod . name = key ;
290
304
mod . relation = '=' ;
@@ -315,6 +329,7 @@ CQLParser.prototype = {
315
329
this . lval == "not" ||
316
330
this . lval == "prox" ) ) {
317
331
var b = new CQLBoolean ( ) ;
332
+ b . _pos = this . qi - this . lval . length + 1 ;
318
333
b . op = this . lval ;
319
334
this . _move ( ) ;
320
335
b . modifiers = this . _parseModifiers ( ) ;
@@ -327,27 +342,35 @@ CQLParser.prototype = {
327
342
_parseModifiers : function ( ) {
328
343
var ar = new Array ( ) ;
329
344
while ( this . look == "/" ) {
345
+ let _mstart = this . qi ;
330
346
this . _move ( ) ;
331
347
if ( this . look != "s" && this . look != "q" )
332
348
throw new CQLError ( "Invalid modifier." , this . qs , this . qi , this . look , this . val , this . lval )
333
349
334
350
var name = this . lval ;
351
+ let _mpos = this . qi - this . lval . length + 1 ;
352
+ let _mend = this . qi ;
335
353
this . _move ( ) ;
336
354
if ( this . look . length > 0
337
355
&& this . _strchr ( "<>=" , this . look . charAt ( 0 ) ) ) {
338
356
var rel = this . look ;
339
357
this . _move ( ) ;
358
+ _mend = this . qi ;
340
359
if ( this . look != "s" && this . look != "q" )
341
360
throw new CQLError ( "Invalid relation within the modifier." , this . qs , this . qi , this . look , this . val , this . lval ) ;
342
361
343
362
var m = new CQLModifier ( ) ;
363
+ m . _pos = _mpos ;
364
+ m . _range = [ _mstart , _mend ] ;
344
365
m . name = name ;
345
366
m . relation = rel ;
346
367
m . value = this . val ;
347
368
ar . push ( m ) ;
348
369
this . _move ( ) ;
349
370
} else {
350
371
var m = new CQLModifier ( ) ;
372
+ m . _pos = _mpos ;
373
+ m . _range = [ _mstart , _mend ] ;
351
374
m . name = name ;
352
375
m . relation = "" ;
353
376
m . value = "" ;
@@ -358,6 +381,7 @@ CQLParser.prototype = {
358
381
} ,
359
382
_parseSearchClause : function ( field , relation , modifiers ) {
360
383
if ( this . look == "(" ) {
384
+ let _qi = this . qi ;
361
385
this . _move ( ) ;
362
386
var b = this . _parseQuery ( field , relation , modifiers ) ;
363
387
if ( this . look == ")" )
@@ -368,6 +392,9 @@ CQLParser.prototype = {
368
392
return b ;
369
393
} else if ( this . look == "s" || this . look == "q" ) {
370
394
var first = this . val ; // dont know if field or term yet
395
+ if ( this . _exprStart === null )
396
+ this . _exprStart = this . qi - this . val . length + 1 ;
397
+ let _tend = this . qi ;
371
398
this . _move ( ) ;
372
399
if ( this . look == "q" ||
373
400
( this . look == "s" &&
@@ -414,6 +441,8 @@ CQLParser.prototype = {
414
441
first ,
415
442
this . scf ,
416
443
this . scr ) ;
444
+ sc . _range = [ this . _exprStart , _tend ] ;
445
+ this . _exprStart = null ;
417
446
return sc ;
418
447
}
419
448
// prefixes
@@ -469,6 +498,8 @@ CQLParser.prototype = {
469
498
}
470
499
//quoted string
471
500
} else if ( this . _strchr ( "\"'" , c ) ) {
501
+ if ( this . _exprStart === null )
502
+ this . _exprStart = this . qi + 1 ;
472
503
this . look = "q" ;
473
504
//remember quote char
474
505
var mark = c ;
0 commit comments