richard-lyman/amotoen — pull request #4 by theJohnnyBrown (2013-01-17 21:34:38+00:00)
Title: and-predicate?

Hi, thanks for the library!

I'm working on bringing the [markdown PEG specification](https://github.com/jgm/peg-markdown/blob/master/markdown_parser.leg) over to clojure, but I found the and-predicate (`(& :a)` returns true if `:a` matches, but consumes no input) is used liberally in that grammar. I tried inlining the definition given in the Ford paper, but it didn't work as I expected:
```clojure
(def g {:a [\b '(! (% \a))]})
(am/pegasus :a g (am/wrap-string "ba")) ; Expected {:a [\b true]}
;=> {:a [\b true]}
(am/pegasus :a g (am/wrap-string "bb")) ; Expected nil
;=> {:a [\b true]}

(def h {:a [\b '(! (! \a))]})
(am/pegasus :a h (am/wrap-string "ba")) ; Expected {:a [\b true]}
;=> nil
(am/pegasus :a h (am/wrap-string "bb")) ; Expected nil
;=> nil
```

However, after making the attached change, the following works:

```clojure
(def pred {:a [\b '(& \a)]})
(am/pegasus :a pred (am/wrap-string "ba"))
;=> {:a [\b true]}
(am/pegasus :a pred (am/wrap-string "bb"))
;=> nil
```