Skip to content

Instantly share code, notes, and snippets.

@sherwinyu
Last active August 29, 2015 13:56
Show Gist options
  • Save sherwinyu/8995920 to your computer and use it in GitHub Desktop.
Save sherwinyu/8995920 to your computer and use it in GitHub Desktop.
start =
Seq
Seq =
first: Expr "_" rest:Seq {return {tag: "Seq", first: first, rest: rest} }
/ Expr
Expr =
WrappedEvent
/ Event
/ "(" e:Event ")" {return e;}
/ "(" e:Seq ")" {return e;}
Event =
BasicEvent
/ MultiEvent
BasicEvent =
letters:[a-z]+ { return letters.join(""); }
MultiEvent =
"{" (BasicEvent ","?)+ "}"
WrappedEvent =
wrap:Event "+" inner:Expr { return {outer: wrap, inner: inner} }
/ wrap:Event "+" inner:WrappedEvent { return {outer: wrap, inner: inner} }
{
pairsToObject = function(pairs) {
var ret = {};
pairs.forEach( function(pair) {
ret[pair[0]] = pair[1];
});
return ret;
}
}
start =
Seq
Seq =
first:Expr
SequentiationOperator
rest:Seq
{return {tag: "Seq", first: first, rest: rest} }
/ Expr
SequentiationOperator = "_"+
Expr =
e:WrappedEvent
opts:OptionList?
{ e.opts = opts; return e;}
/ e:Event
opts:OptionList?
{ e.opts = opts; return e;}
/ "("
e:Event
opts:OptionList?
")"
{e.opts = opts; return e;}
/ "("
e:Seq
opts:OptionList?
")"
{ e.opts = opts; return e;}
Event =
BasicEvent
/ MultiEvent
BasicEvent =
letters:[a-z]+ { return {event: letters.join("")}; }
MultiEvent =
MultiEventStart
events:(e:BasicEvent MultiEventSeparator? {return e})+
MultiEventEnd
{ return {tag: "multi", events: events} }
MultiEventStart = "{"
MultiEventSeparator = ","
MultiEventEnd = "}"
WrappedEvent =
wrap:Event "+" inner:Expr
{ return {outer: wrap, inner: inner} }
/ wrap:Event "+" inner:WrappedEvent
{ return {outer: wrap, inner: inner} }
Option =
key:[a-z]+ "=" val:[a-z]+ { return [key.join(""), val.join("")] }
OptionList =
WhiteSpace "::" WhiteSpace first:Option rest:(OptionSeparator o:Option {return o})* { return pairsToObject([first].concat(rest)) }
OptionSeparator =
WhiteSpace ";" WhiteSpace
WhiteSpace =
[ \t]*
{
pairsToObject = function(pairs) {
var ret = {};
pairs.forEach( function(pair) {
ret[pair[0]] = pair[1];
});
return ret;
}
}
start =
Seq
Seq =
first:Expr
SequentiationOperator
rest:Seq
{return {tag: "Seq", first: first, rest: rest} }
/ Expr
SequentiationOperator = [_|.]+
Expr =
e:WrappedEvent
opts:OptionList?
{ e.opts = opts; return e;}
/ e:Event
opts:OptionList?
{ e.opts = opts; return e;}
/ "("
e:Event
opts:OptionList?
")"
{e.opts = opts; return e;}
/ "("
e:Seq
opts:OptionList?
")"
{ e.opts = opts; return e;}
Event =
BasicEvent
/ MultiEvent
BasicEvent =
letters:[a-z0-9]+ { return {event: letters.join("")}; }
MultiEvent =
MultiEventStart
events:(e:BasicEvent MultiEventSeparator? {return e})+
MultiEventEnd
{ return {tag: "multi", events: events} }
MultiEventStart = "{"
MultiEventSeparator = ","
MultiEventEnd = "}"
WrappedEvent =
wrap:Event "+" inner:Expr
{ return {outer: wrap, inner: inner} }
/ wrap:Event "+" inner:WrappedEvent
{ return {outer: wrap, inner: inner} }
Option =
key:[a-z]+ "=" val:[a-z]+ { return [key.join(""), val.join("")] }
OptionList =
WhiteSpace "::" WhiteSpace first:Option rest:(OptionSeparator o:Option {return o})* { return pairsToObject([first].concat(rest)) }
OptionSeparator =
WhiteSpace ";" WhiteSpace
WhiteSpace =
[ \t]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment