Skip to content

Instantly share code, notes, and snippets.

@mdallastella
Created July 4, 2016 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdallastella/c0944f72f6243fb32b906c73f80eac08 to your computer and use it in GitHub Desktop.
Save mdallastella/c0944f72f6243fb32b906c73f80eac08 to your computer and use it in GitHub Desktop.
Simple die parser
(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