Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

and-predicate? #4

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Hi, thanks for the library!

I'm working on bringing the markdown PEG specification 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:

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

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

richard-lyman commented Nov 2, 2016

Complete transition to a new implementation. The new implementation does not yet have predicates, and or not, but it would be trivial to implement them once they're needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment