Skip to content

Instantly share code, notes, and snippets.

@DarrenN
Last active December 4, 2015 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarrenN/f8df201ffd0810af3a3b to your computer and use it in GitHub Desktop.
Save DarrenN/f8df201ffd0810af3a3b to your computer and use it in GitHub Desktop.
PEG Sexprs
{
function getType(def, head) {
switch (head) {
case "and":
case "or":
case "not":
return "booleanOperator";
case "eq":
case "ne":
case "lt":
case "lte":
case "gt":
case "gte":
case "exists":
return "filterOperator";
case "interval":
case "groupBy":
case "granularity":
case "filter":
return "field";
default:
return def;
}
}
}
List
= "(" head:Atom _ tail:(_ (Integer / String / Pair / List) _)+ ")" {
var ret = { type: getType('List', head) };
tail = tail.map(function(i) {
return i.filter(function(j) { return !Array.isArray(j); });
});
ret.head = head;
ret.tail = tail.map(function(i) { return i[0]; });
return ret;
}
Pair
= "(" head:Atom _ tail:String ")" {
var ret = { type: getType('Pair', head) };
ret.head = head;
ret.tail = tail;
return ret;
}
String "string"
= '"' atom:Atom '"' { return atom; }
Integer "integer"
= [0-9]+ { return parseInt(text(), 10); }
Atom "atom"
= [a-zA-Z0-9]* { return text(); }
_ "whitespace"
= [ \t\n\r]*
@DarrenN
Copy link
Author

DarrenN commented Dec 3, 2015

For us with PEG.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment