Closed 3b closed 13 years ago
I added support for guards onto "guards" branch.
(defrule foo (and "foo" (or "bar" "foo"))
(:when *use-foo*))
Does that do the right thing for you?
I'm a bit hesitant to add support for no-arg predicates, since a predicate that isn't purely functional (and consistent for the whole parse) breaks the basic caching assumption of packrat parsing:
(defrule bad ...
(:lambda (res)
(setf *going-bad* t)
res))
(defun worse () *going-bad*)
(defrule worst (and (worse) ...)
...)
is never going to work right.
That works (with small fix at 3b/esrap@1d020a3).
Thanks, merged onto master.
For example, supporting multiple versions of a grammar, or selecting optional extensions.
3b/esrap@7f3d9d907f08ce1a6060c31278a449545b52a404 adds support for this by allowing
(<predicate>)
without arguments, but it seems a bit inconvenient for the common case of just checking a global variable. Possibly it would be better to just add a rule to check a variable directly, or evaluate a chunk of code if that can be implemented efficiently.See
parser.lisp
in 3b/3bmd@519b35ba85b678d04d990d4b682470ff092da4a7 and 3b/3bmd@4aad4867ca5d6e89ba4e6637f3316ad09d498d2d for example use cases.