Skip to content

Instantly share code, notes, and snippets.

@takeoutweight
Forked from roman/gist:2338825
Created April 8, 2012 18:15
Show Gist options
  • Save takeoutweight/2338894 to your computer and use it in GitHub Desktop.
Save takeoutweight/2338894 to your computer and use it in GitHub Desktop.
;Hrm... I actually tried a similar approach before but:
(def identifier2
(around
whitespaces
(choice
[(*> (string "#")
(<* number (string "#")))
(*> (string "#")
(<* number (string "=")))])))
(z/parse-once identifier2 "#234=")
#zetta.core.ResultFailure{:remainder (\=), :stack [], :msg "Failed reading: take-with"}
parse> (z/parse-once identifier2 "#234#")
#zetta.core.ResultDone{:remainder (), :result 234}
;I think i probably should read some attoparsec tutorials -- I'm pretty ignorant of the basics so I'm not ;sure where to begin fixing (i.e. maybe I've just built things wrong or loaded something incorrectly...)
@takeoutweight
Copy link
Author

Yep that parses for me now. Am I able to distinguish between which choice is made with this approach? (i.e I want #'s to mean reference ids and ='s to mean id definitions)

I guess the trick would be not to throw away the parsed = and #, but throw the number and the matched char to a higher function with <$> ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment