Skip to content

Commit 2561bf9

Browse files
authored
[Issue #5] Support expression inside expand (#6)
1 parent 3ca7434 commit 2561bf9

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/odata.pegjs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ top = "$top=" a:INT { return { '$top': ~~a }; }
204204
expand = "$expand=" list:expandList { return { "$expand": list }; }
205205
/ "$expand=" .* { return {"error": 'invalid $expand parameter'}; }
206206

207-
expandList = i:identifierPath list:("," WSP? l:expandList {return l;})? {
207+
expandList = i:identifierPath e:("(" e:exp ")" {return e;})? list:("," WSP? l:expandList {return l;})? {
208208
if (list === "") list = [];
209-
if (require('util').isArray(list[0])) {
210-
list = list[0];
209+
210+
var elem = i;
211+
if (e) {
212+
elem = [ i, e ];
211213
}
212-
list.unshift(i);
214+
list.unshift(elem);
215+
213216
return list;
214217
}
215218

@@ -276,12 +279,12 @@ filter = "$filter=" list:filterExpr {
276279
}
277280
/ "$filter=" .* { return {"error": 'invalid $filter parameter'}; }
278281

279-
filterExpr =
282+
filterExpr =
280283
left:("(" WSP? filter:filterExpr WSP? ")"{return filter}) right:( WSP type:("and"/"or") WSP value:filterExpr{
281284
return { type: type, value: value}
282285
})? {
283286
return filterExprHelper(left, right);
284-
} /
287+
} /
285288
left:cond right:( WSP type:("and"/"or") WSP value:filterExpr{
286289
return { type: type, value: value}
287290
})? {

test/parser.specs.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,19 @@ describe('odata.parser grammar', function () {
449449
assert.equal(ast.error, 'invalid $resultFormat parameter');
450450
assert.equal(ast.$count, undefined);
451451
});
452+
});
452453

454+
describe('Expression inside expression', function() {
455+
it('should parse $expand=Sensors,Observations($select=result),Datastream',
456+
function() {
457+
var ast = parser.parse(
458+
'$expand=Sensors,Observations($select=result),Datastream'
459+
);
460+
assert.deepEqual(ast.$expand, [
461+
'Sensors',
462+
['Observations', {'$select': ['result']}],
463+
'Datastream'
464+
]);
465+
});
453466
});
454467
});

0 commit comments

Comments
 (0)