Created
June 4, 2012 21:35
-
-
Save dmdavis/2870968 to your computer and use it in GitHub Desktop.
Simple PEG.js dice roller
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 | |
= additive | |
additive | |
= left:dice "+" right:additive { return left + right; } | |
/ left:dice "-" right:additive { return left - right; } | |
/ dice | |
dice | |
= left:primary "d" right:primary { var s = 0; for(var i = 0; i < left; i++ ) { s += Math.floor(Math.random() * right) + 1; } return s; } | |
/ primary | |
primary | |
= integer | |
/ "(" additive:additive ")" { return additive; } | |
integer "integer" | |
= digits:[0-9]+ { return parseInt(digits.join(""), 10); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment