You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB
JavaScript

{
function concatRepeat(first, rest, restIndex) {
return [first].concat(rest.map(function(item) {
return item[restIndex];
}));
}
function combineFinal(riotQuery, domQuery) {
var resultObject = {
riotQuery: riotQuery
};
if (domQuery != null) {
resultObject.domQuery = domQuery[1];
}
return resultObject;
}
}
start
= riotQuery:riotQuery? domQuery:domQuerySuffix? { return combineFinal(riotQuery, domQuery) }
riotQuery
= segment:riotQuerySegment subSegments:("/" riotQuerySegment)* { return concatRepeat(segment, subSegments, 1); }
riotQuerySegment
= riotQuerySegmentSelector
/ riotQuerySegmentGroup
riotQuerySegmentGroup
= '{' items:riotQuerySegmentGroupItems '}' { return {type: "group", items: items}; }
riotQuerySegmentGroupItems
= item:riotQuerySegmentGroupItemsItem subItems:("," riotQuerySegmentGroupItemsItem)* { return concatRepeat(item, subItems, 1); }
riotQuerySegmentGroupItemsItem
= riotQuery
/ '' { return [{type: "empty"}]; }
riotQuerySegmentSelector
= riotQueryIdentifier
/ riotQueryWildcard
riotQueryIdentifier
= identifier:[a-z-]+ { return {type: "identifier", value: identifier.join("")}; }
riotQueryWildcard
= "**" { return {type: "wildcard"}; }
domQuery
= query:.+ { return query.join(""); }
domQuerySuffix
= '//' domQuery