Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Created June 22, 2015 19:58
Show Gist options
  • Save StoneCypher/374acd81c3ca00393297 to your computer and use it in GitHub Desktop.
Save StoneCypher/374acd81c3ca00393297 to your computer and use it in GitHub Desktop.
start
= w:(die _)* { return w.map(function(X) { return X[0] }); }
number
= [0-9]
nonzero
= [1-9]
symbol
= [\+-]
count
= integer
diesize
= 'd' int:integer { return int; }
modifier
= '+' int:integer { return int; }
/ '-' int:integer { return -1 * int; }
die
= cnt:count sz:diesize mod:modifier { return { count: cnt, size: sz, adjust: mod }; }
/ cnt:count sz:diesize { return { count: cnt, size: sz, adjust: 0 }; }
/ sz:diesize mod:modifier { return { count: 1, size: sz, adjust: mod }; }
/ sz:diesize { return { count: 1, size: sz, adjust: 0 }; }
integer
= nz:nonzero num:number* { return parseInt(nz + num.join(''), 10); }
// optional whitespace
_ = [ \t\r\n]*
// mandatory whitespace
__ = [ \t\r\n]+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment