Re: Translating parse result into instances



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

.



Relevant Pages

  • Shell functions to manipulate the PATH
    ... Yes, quite often when the newbies want to change the PATH it is misguided, ... because they are trying to run a /sbin command as ordinary users. ... Then the script is less ... # `path --append args' appends args, ...
    (comp.os.linux.setup)
  • RE: FW: Passing large number of arguments to a program
    ... The program is called from inside the DCL jacket as a "foreign command". ... $ prog 'args' ...
    (comp.os.vms)
  • Re: Command line arguments question (Windows XP)
    ... What the fuck is going on? ... I've been using command line parameters for years. ... are concatenated into a single string. ...
    (comp.lang.python)
  • Re: Translating parse result into instances
    ... where COMMAND is the initial string, and ARGS are everything else. ... This macro implements one part of the parser. ...
    (comp.lang.lisp)
  • Re: Cant connect to the Internet
    ... If nslookup can't find the site it will show you the DNS ... If you don't have a shortcut for Command Prompt in your Accessories ... I signed up for a new DSL service. ... > service provider said their is a problem with my DSN lookup, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)