Skip to content

Instantly share code, notes, and snippets.

@DarrenN
Last active Dec 4, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@DarrenN 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