Skip to content

Instantly share code, notes, and snippets.

@takeoutweight
Forked from roman/gist:2338825
Created April 8, 2012 18:15
Show Gist options
  • Select an option

  • Save takeoutweight/2338894 to your computer and use it in GitHub Desktop.

Select an option

Save takeoutweight/2338894 to your computer and use it in GitHub Desktop.
(def identifier
(around
whitespaces
(choice
[(<$> (partial apply vector)
(*> (string "#")
(<* number (string "#"))))
; ^ I think you should be using just number here right?
; you are trying to parse (many1 digit)
(<$> (partial apply vector)
(*> (string "#")
(<* number (string "="))))])))
; ^ same applies here
@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