pL first tries anbn: many parses zero \a's; then times has to parse zero 
\b's; and the parser returns the concatenation of two empty lists. An empty 
list isn't a failure as far as the parser either is concerned, so it won't 
try xdny in that case.

On Wednesday, August 22, 2012 5:38:56 PM UTC-7, Alexsandro Soares wrote:
>
> Hi all,
>
>    I'm using the Parsatron library to build parser combinators. I have the 
> following definition:
>
> (defparser anbn [] 
>   (let->> [as  (many (char \a))
>               bs  (times (count as) (char \b))]
>     (always (concat as bs))))
>
> (defparser xdny []
>   (let->> [ds (between (char \x) (char \y) 
>                        (many (char \d)))]
>     (always (concat '(\x) ds '(\y)))))
>
> (defparser pL []
>   (either 
>     (anbn)
>     (xdny)))
>
> When I use this definition in REPL with some examples, I have:
>
> user=> (run (pL) "xddy")
> ()
>
> user=> (run (pL) "aabb")
> (\a \a \b \b)
>
> user=> (run (xdny) "xddy")
> (\x \d \d \y)
>
> I didn't understand why the first answer is not (\x \d \d \y). The second 
> and third answers are correct for me.
>
> Can anyone help me?
>
> Regards,
> Alex
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to