Re: Translating parse result into instances
- From: Pillsy <pillsbury@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 07:23:30 -0700
On Aug 30, 3:53 pm, Frank Goenninger DG1SBG <dont-email...@xxxxxxxxxx>
wrote:
I have a - hm, what? - a "stream" of data as follows:
I went a bit crazy with this, and for some reason coded up a complete
solution. Since you don't actually want a complete solution, I'll just
say that one way to things like this is to destructure each like this:
(COMMAND . ARGS)
where COMMAND is the initial string, and ARGS are everything else.
Then use command as a key to some data structure which contains a
bunch of closures which you then I used an EQUALP hashtable, but list
structures could work as well. Each closure then destructures ARGS in
the right way, and does what you need to do in terms of making
instances.
I've found this technique is also good for parsing DSLs when you're
doing macrology (and in a way, it defines a DSL here, too), and with a
few tastefully chosen macros and functions, you can make a DSL for
expressing simple parsers that's concise and easy to modify.
This macro implements one part of the parser. You ought to be able to
extrapolate the rest of the implementation from it:
(defmacro define-parser (command (&rest lambda-list) &body body)
(check-type command string)
(let ((args (gensym)))
`(progn
(register-parser ,command
#'(lambda (&rest ,args)
(destructuring-bind ,lambda-list
,args
,@body))))))
Cheers,
Pillsy
.
- References:
- Translating parse result into instances
- From: Frank Goenninger DG1SBG
- Translating parse result into instances
- Prev by Date: How to use Lisp in C/C++
- Next by Date: Re: How to use Lisp in C/C++
- Previous by thread: Re: Translating parse result into instances
- Next by thread: libraries
- Index(es):
Relevant Pages
|