Last active
August 29, 2015 13:56
-
-
Save sherwinyu/8995920 to your computer and use it in GitHub Desktop.
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
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} } |
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
{ | |
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]* |
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
{ | |
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