This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gql): adds support for top level ops.
- Adds support for is, is not, in , not in - Adds support for parens - let AND and OR be used without wrapping in parens. - there is still an issue with lack of operator priority - can still be solved with parens though
- Loading branch information
Shane Wilson
committed
Feb 18, 2015
1 parent
0aa7cc4
commit 784d48d
Showing
2 changed files
with
138 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,134 @@ | ||
start = sexp | ||
|
||
sexp = "(" ops:ops ")" | ||
{ return ops } | ||
|
||
ops = group_op / list_op / value_op | ||
|
||
// Group Operators take >1 sexps | ||
group_op = op:group_op_terms ':' args:group_args | ||
{ return {"op": op, "content": args} } | ||
|
||
group_op_terms = "and" / "or" | ||
|
||
group_args = xs:sexps+ x:sexp | ||
{ xs.push(x); return xs } | ||
|
||
sexps = xs:(sexp ",") | ||
{ return xs[0] } | ||
start | ||
= _* node:node+ _* | ||
{ | ||
return node[0]; | ||
} | ||
/ _* | ||
{ | ||
return {}; | ||
} | ||
/ EOF | ||
{ | ||
return {}; | ||
} | ||
|
||
node | ||
= group_expr | ||
/ exprs | ||
|
||
exprs | ||
= list_expr | ||
/ value_expr | ||
/ parens | ||
|
||
parens | ||
= "(" node:node ")" | ||
{ | ||
return node; | ||
} | ||
|
||
// Group Operators | ||
group_expr | ||
= left:exprs operator:group_operator_expr right:node | ||
{ | ||
return { | ||
op: operator, | ||
content: [left, right] | ||
} | ||
} | ||
|
||
group_operator_expr | ||
= _ operator:("or"i / "and"i) _ | ||
{ | ||
return operator; | ||
} | ||
|
||
// List Operators take a field and a list of terms | ||
list_op = op:list_op_terms ":" args:list_args | ||
{ return {"op": op, "content": args}} | ||
|
||
list_op_terms = "in" / "out" | ||
|
||
list_args = f:word "," "[" v:terms "]" | ||
{ return {"field": f, "value": v }} | ||
|
||
list_expr | ||
= field:unquoted_term operator:list_operator_expr terms:terms | ||
{ | ||
return { | ||
op: operator, | ||
content: { | ||
field: field, | ||
terms: terms | ||
} | ||
} | ||
} | ||
|
||
list_operator_expr | ||
= _ operator:list_operators _ | ||
{ | ||
return operator; | ||
} | ||
|
||
list_operators | ||
= "not in"i | ||
/ "in"i | ||
|
||
// Value Operators take a field and a value | ||
value_op = op:value_op_terms ":" args:value_args | ||
{ return {"op": op, "content": args}} | ||
|
||
value_op_terms = "is" / "not" / "gt" / "gte" / "lt" / "lte" | ||
|
||
value_args = f:word "," v:term | ||
{ return {"field": f, "value": v }} | ||
|
||
arg = xs:(term / sexp) | ||
|
||
terms = xs:_terms+ x:term | ||
{ xs.push(x); return xs } | ||
|
||
_terms = xs:(term ',') | ||
{return xs[0] } | ||
|
||
term = word / text | ||
|
||
text = quote .+ quote | ||
|
||
quote = '"' | ||
|
||
word = cs:$char+ | ||
{ return cs } | ||
|
||
char = [A-Za-z0-9_-] | ||
value_expr | ||
= field:unquoted_term operator:value_operator_expr term:term | ||
{ | ||
return { | ||
op: operator, | ||
content: { | ||
field: field, | ||
term: term | ||
} | ||
} | ||
} | ||
|
||
value_operator_expr | ||
= _ operator:value_operators _ | ||
{ | ||
return operator; | ||
} | ||
|
||
value_operators | ||
= "is not"i | ||
/ "is"i | ||
/ "gte"i | ||
/ "gt"i | ||
/ "lte"i | ||
/ "lt"i | ||
|
||
|
||
terms | ||
= "[" x:term xs:_terms* "]" | ||
{ | ||
var ts = [x]; | ||
if (xs.length) { | ||
ts = ts.concat(xs) | ||
} | ||
|
||
return ts; | ||
} | ||
|
||
_terms | ||
= xs:(_ term) | ||
{ | ||
return xs[1]; | ||
} | ||
|
||
term | ||
= unquoted_term | ||
/ quoted_term | ||
|
||
unquoted_term | ||
= term:$[^: \t\r\n\f\{\}()"+-/^~\[\]]+ | ||
{ | ||
return term; | ||
} | ||
|
||
quoted_term | ||
= '"' term:$[^"]+ '"' | ||
{ | ||
return term; | ||
} | ||
|
||
_ "whitespace" | ||
= [ \t\r\n\f,]+ | ||
|
||
EOF | ||
= !. |