-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for :keywords as operators in expressions #18
base: master
Are you sure you want to change the base?
Conversation
Ok, I just realized that as this doesn't recur unless the first symbol is a keyword, it won't work for nested expression where the parent expression doesn't have a keyword op. Yay for premature optimization ;-) So totally unsuitable for real-world usage. But the question of "should esrap support such usage" remains. |
seems it doesn't work for more complex expressions (I don't know what esrap is doing, obviously). |
Thank you for the suggestion. I think allowing users to refer to the operators of the Esrap expression grammar via additional names is best done as a custom
In summary, as mentioned above, I would recommend a user-defined macro like (defun transform-expression (expression)
(labels ((rec (expression)
(typecase expression
((cons (eql :+)) `(cl:+ ,(rec (second expression))))
;; TODO handle rest of the expression grammar
)))
(rec expression)))
(defmacro my-defrule (name expression &body options)
`(esrap:defrule ,name ,(transform-expression expression)
,@options))
(my-defrule test (:+ "foo"))
(esrap:parse 'test "foofoo") => ("foo" "foo"), NIL, T Instead of |
Thank you for your kind, oh-so detailed reply. So, if it doesn't strike you as "syntactically disgusting", would it be acceptable in the core, or would this belong in "compat" package (which could use the wisdom imparted) ? EDIT: and a few DSLs allow/require the :whatever for the "key words" to stand out... Except symbol pollution, I like it. |
hopefully not too hacky.
created because having ie. + imported from generic-cl resulted in "weirdly failing" code (+ captured first instance, and expected end of stream).
and using cl:+ or esrap:+ in expressions looked way too ugly (I'm writing some code for "demo of elegance" purposes, so having to explain some wart is a big no-no).
Example:
could this be - in principle, not necesarilly my impl. - included into esrap ?