Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2013 22:49
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 anonymous/5681884 to your computer and use it in GitHub Desktop.
Save anonymous/5681884 to your computer and use it in GitHub Desktop.
;;- Item A
;;- Item B
;;=> [:ul [:li "Item A"] [:li "Item B"]]
(def markdown "- Item A\n- Item B")
(def parse
(insta/parser
"<root> = ul+
ul = li+
li = '- ' #'[a-zA-Z ]+' '\n'?"))
(parse markdown)
;; => ([:ul [:li "Item A"]] [:ul [:li "Item B"]])
;; Parser reports two possible ways to parse this:
;; 1. ([:ul [:li "- " "Item A" "\n"]] [:ul [:li "- " "Item B"]])
;; 2. ([:ul [:li "- " "Item A" "\n"] [:li "- " "Item B"]]))
;; It chooses the first way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment