Created
July 4, 2016 09:51
-
-
Save mdallastella/c0944f72f6243fb32b906c73f80eac08 to your computer and use it in GitHub Desktop.
Simple die parser
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
(ns die-parser.example | |
(:require [instaparse.core :as i])) | |
(def roller-grammar | |
"die = times <'d'> faces | |
times = number | |
faces = number | |
<number> = #'[0-9]+'") | |
(defn roll | |
[input] | |
(let [parser (i/parser roller-grammar)] | |
(->> (i/parse parser input)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment