This is a CL question - not specific to LW - but, I find this group much better to interface with than c.l.l (although I know it is a subset of c.l.l), so I hope no one minds...I'm wondering if it's possible to have a contextual reader macro?Here's my specific use-case.Over time, I've been adding more features to my LEXER package for LW (https://github.com/massung/lexer), and I have a code block I'd like to improve (if possible)... specifically the WITH-RE-MATCH macro found here: https://github.com/massung/lexer/blob/master/lexer.lisp#L182.In particular, the macro assumes a finite number of sub-captures in the match. And while this is fine for most cases, what I'd prefer is a macro where the user could use any symbol like $24 if they wanted.The only way I can think to do this is with a reader macro for #\$ that turns into the appropriate AREF call (note: currently the captures are in list form for destructuring-bind, but could easily be a vector if I can get this to work).However, I would only want this reader macro to within the context of the WITH-RE-MATCH macro. But, I can't see that as being possible since the reader has already done its work before calling the macro......or is there a trick I'm missing?Or perhaps there's a better way for me to do what I want that someone can shed some light on?Thanks for any insights!Jeff M.
Jeff Massung <massung@gmail.com> writes: > ...or is there a trick I'm missing? Read this: http://www.nhplace.com/kent/PS/Ambitious.html and ask again. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. _______________________________________________ Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com http://www.lispworks.com/support/lisp-hug.html
I think list might be interested too: http://code.google.com/p/def-symbol-readmacro/wiki/InstallationInEnglish _______________________________________________ Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com http://www.lispworks.com/support/lisp-hug.html
Would it be possible to let the user specify the symbols to use:
(defmacro with-re-match ((v match &rest symbols) &body body)…
If so, you could even dispense with v and the dollars do
(defmacro with-re-match (((&rest symbols) match) &body body) …
Using like
(with-re-match ((a b) (find-re #/{([^}]+)}/ "this {is a} test"))
(print a)
(print b))
"{is a}"
"is a"
"is a"
T
Eivind
From: owner-lisp-hug@lispworks.com [mailto:owner-lisp-hug@lispworks.com] On Behalf Of Jeff Massung
Sent: 17. februar 2013 15:14
To: Lisp Hug Lispworks
Subject: Contextual reader macros
This is a CL question - not specific to LW - but, I find this group much better to interface with than c.l.l (although I know it is a subset of c.l.l), so I hope no one minds...
I'm wondering if it's possible to have a contextual reader macro?
Here's my specific use-case.
Over time, I've been adding more features to my LEXER package for LW (https://github.com/massung/lexer), and I have a code block I'd like to improve (if possible)... specifically the WITH-RE-MATCH macro found here: https://github.com/massung/lexer/blob/master/lexer.lisp#L182.
In particular, the macro assumes a finite number of sub-captures in the match. And while this is fine for most cases, what I'd prefer is a macro where the user could use any symbol like $24 if they wanted.
The only way I can think to do this is with a reader macro for #\$ that turns into the appropriate AREF call (note: currently the captures are in list form for destructuring-bind, but could easily be a vector if I can get this to work).
However, I would only want this reader macro to within the context of the WITH-RE-MATCH macro. But, I can't see that as being possible since the reader has already done its work before calling the macro...
...or is there a trick I'm missing?
Or perhaps there's a better way for me to do what I want that someone can shed some light on?
Thanks for any insights!
Jeff M.
BTW, our lib have such feature as "custom-token-parser". Parsers (one or many) are assigned to package. Any token which is about to be considered as a symbol name from that package, is processed by all custom token parsers. If it matches either parser, some value is returned from the parser and inserted into source tree instead of interning a symbol. E.g. I use this for abbreviating structures access, see point 6 in my Wiki, http://code.google.com/p/def-symbol-readmacro/wiki/InstallationInEnglish _______________________________________________ Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com http://www.lispworks.com/support/lisp-hug.html
Would it be possible to let the user specify the symbols to use:
(defmacro with-re-match ((v match &rest symbols) &body body)…
If so, you could even dispense with v and the dollars do
(defmacro with-re-match (((&rest symbols) match) &body body) …
Using like
(with-re-match ((a b) (find-re #/{([^}]+)}/ "this {is a} test"))
(print a)
(print b))
"{is a}"
"is a"
"is a"
T
Eivind
From: owner-lisp-hug@lispworks.com [mailto:owner-lisp-hug@lispworks.com] On Behalf Of Jeff Massung
Sent: 17. februar 2013 15:14
To: Lisp Hug Lispworks
Subject: Contextual reader macros
This is a CL question - not specific to LW - but, I find this group much better to interface with than c.l.l (although I know it is a subset of c.l.l), so I hope no one minds...
I'm wondering if it's possible to have a contextual reader macro?
Here's my specific use-case.
Over time, I've been adding more features to my LEXER package for LW (https://github.com/massung/lexer), and I have a code block I'd like to improve (if possible)... specifically the WITH-RE-MATCH macro found here: https://github.com/massung/lexer/blob/master/lexer.lisp#L182.
In particular, the macro assumes a finite number of sub-captures in the match. And while this is fine for most cases, what I'd prefer is a macro where the user could use any symbol like $24 if they wanted.
The only way I can think to do this is with a reader macro for #\$ that turns into the appropriate AREF call (note: currently the captures are in list form for destructuring-bind, but could easily be a vector if I can get this to work).
However, I would only want this reader macro to within the context of the WITH-RE-MATCH macro. But, I can't see that as being possible since the reader has already done its work before calling the macro...
...or is there a trick I'm missing?
Or perhaps there's a better way for me to do what I want that someone can shed some light on?
Thanks for any insights!
Jeff M.