Last active
August 29, 2015 14:06
-
-
Save cgrand/257de60e11458ee2749a to your computer and use it in GitHub Desktop.
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
; helper functions are missing, be it for char ranges or for lookaheads | |
; however this snippet demoes: | |
; * error-correction (the change in correction between the 3rd and 4th case shows that parsnip looks for a minimal deletion) | |
; * lookahead | |
=> (let [alpha (fn [c] (<= (int \a) (int c) (int \z))) | |
p (parser :map | |
{:map ["{" (* :sym (? :ws) :sym) "}"] | |
:ws (+ " ") | |
:sym [(+ (->InlineAsm [:PRED alpha])) | |
(->InlineAsm [:PEEK (complement alpha)])]})] | |
(doseq [input ["{aaaa}" "{aa aa}" "{a aa a}" "{a aa a}"]] | |
(prn input '-> (p input)))) | |
"{aaaa}" -> [[:map "{" [:skip "aaaa"] "}"]] | |
"{aa aa}" -> [[:map "{" [:sym "aa"] [:ws " "] [:sym "aa"] "}"]] | |
"{a aa a}" -> [[:map "{" [:sym "a" [:skip " "] "aa"] [:ws " "] [:sym "a"] "}"]] | |
"{a aa a}" -> [[:map "{" [:sym "a"] [:ws " "] [:sym "aa" [:skip " "] "a"] "}"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment