yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
879 stars 112 forks source link

QUESTION: How does one use "apd" (and predicate operator) #280

Closed pdhahn closed 1 year ago

pdhahn commented 1 year ago

I have been using cpp-peflib for a while now. I use cpp-peglib operators to define my C++ grammar. This is all successful.

However, now I am curious about the "apd" operator, what it does, and how to use it. I cannot find anything about it in the README or it being used in the sample code.

RSVP

Thanks for cpp-peglib!

yhirose commented 1 year ago

@pdhahn, I am glad to hear you're enjoying using cpp-peglib! apd is equivalent to 'AND', and npd is 'NOT' described on page 2 in the document by Bryan Ford.

image

Here is a simple example using 'AND' in PEG grammar and parser combinators:

StartWithA <- &'A' ([A-Z-a-z])+ StartWithA <= seq(apd(chr('A')), oom(cls("A-Za-z")))

Hope it helps!