Your "semantics" have side effects. The parser shouldn't be printing
to stdout, because it's still in the middle of backtracking and
deciding what matches. Instead the semantics should be more like (fn
[x] (str "ANY: " x)); then you won't see any results unless a complete
parse happens.

On Apr 11, 3:54 am, LordGeoffrey <lordgeoff...@optusnet.com.au> wrote:
> Exercising the code below with (f "ab") produces:
> A: a
> ANY: a
> ANY: b
>
> Which implies (at least to me) that - alt seems to match "a" twice once
> against the lit and once against anything. Any suggestions would be
> appreciated.
>
> fnparse v: 2.2.7
> clojure v: 1.2.0
> ---
> (use 'name.choi.joshua.fnparse)
>
> (defn run-p
>    [parser input]
>    (let [result (rule-match parser
>                             #(prn "fail:" %&)
>                             #(prn "incomplete:" %&)
>                             {:remainder input})]
>      (cond (nil? result) nil
>            (vector? result) (apply str result)
>            :else (str result))))
>
> (defn f [str]
>    (run-p
>     (rep*
>      (alt (semantics (lit \a) (fn [x] (println "A:" x)))
>           (semantics anything (fn [x] (println "ANY:" x)))))
>     str) )

-- 
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