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...)
@roman
Copy link

roman commented Apr 8, 2012

If you change the order on the choice vector, the = works but the # doesn't...

uhmm it seems we have an issue here with the buffer not having the content back after going to the next choice :-/

Need to figure out why that's happening

@roman
Copy link

roman commented Apr 8, 2012

(def id3 
  (around whitespaces (*> (char \#) 
                                          (<* number (choice [(char \=) 
                                                                           char \#)])))))

Try this one out

@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