forked from ucscXena/ucsc-xena-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.peg
51 lines (41 loc) · 1.33 KB
/
search.peg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
function last(arr) {
return arr[arr.length - 1];
}
function concat(arr, arrs) {
return arr.concat(arrs);
}
}
start = Expression
Expression
= left:Term tail:(_ 'OR' _ Term)* {
return tail.length ? concat(['or', left], tail.map(last)) : left;
}
Term
= left:Factor tail:(_ ('AND' _)? Factor)* {
return tail.length ? concat(['and', left], tail.map(last)) : left;
}
Factor
= Grouping / Field / Value
Grouping
= '(' exp:Expression ')' { return ['group', exp]; }
Field
= left:FieldName ":" _ right: Value {
return ['field', left, right];
}
Value = NeValue / LeValue / GeValue / LtValue / GtValue / EqValue / QuotedValue / PlainValue
PlainValue = ! 'OR' [^ \t()]+ { return ['value', text()]; }
QuotedValue = '"' [^"]* '"' {
var val = text();
return ['quoted-value', val.slice(1, val.length - 1)];
}
EqValue = '=' value:(QuotedValue / PlainValue) { return value; }
NeValue = '!=' value:(QuotedValue / PlainValue) { return ['ne', value]; }
GtValue = '>' value:PlainValue { return ['gt', value[1]]; }
LtValue = '<' value:PlainValue { return ['lt', value[1]]; }
GeValue = '>=' value:PlainValue { return ['ge', value[1]]; }
LeValue = '<=' value:PlainValue { return ['le', value[1]]; }
FieldName
= ! 'OR' [a-zA-Z][^ \t:=]* { return text(); }
_ "whitespace"
= [ \t\n\r]* {return text(); }