create new statement?

Bruce Edge bedge at troikanetworks.com
Mon Mar 5 10:38:44 EST 2001


Ken Seehof wrote:
> 
> Instead of messing with the python interpreter, maybe you could make a very
> simple command translator that converts a command line into python syntax.
> Since you want to mix this with python syntax, you could have rules to
> determine which lines to apply the translator.
> 
> The translator would leave the line alone unless it meets the following
> conditions:
> - The line starts with one of your commands.
> - The line doesn't contain punctuation that is incompatible with the command
> syntax.
> 
> Example:
> chew spam 2
> 
> translates to:
> chew('spam', 2)

OK, perfect. Now, where does one hook the translator in? I'm using
readline and a derived ldcompleter to handle cmd line editing. I suppose
I could wedge it in with the completer, but I can't help wondering if
there's a better place.

Thanks, Bruce.

> 
> In this example, you would support space delimited integers, floats, and
> unquoted strings in your command syntax. Strings would be anything without
> whitespace that does not parse as integer or float; or if that's not
> acceptable, use quoted strings and delimit with comments.  The details
> depend on what you want the command syntax to look like.
> 
> I've done exactly the opposite of that for a company I used to work for.  I
> wrapped an existed command interpreter in python by generating python
> callable objects that generate the command syntax and invoke the existing
> command interpreter.
> 
> ----- Original Message -----
> From: "Bruce Edge" <bedge at troikanetworks.com>
> Newsgroups: comp.lang.python
> To: "Ken Seehof" <kens at sightreader.com>
> Sent: Friday, March 02, 2001 11:32 AM
> Subject: Re: create new statement?
> 
> > Ken Seehof wrote:
> > >
> > > Sorry, not without rebuilding python.
> > >
> > > What is the actual problem that you are trying to solve?  Maybe there's
> > > another approach.
> >
> > I'm creating a command line interface to a product.
> > I want to have access to python as a scripting tool, and be able to
> > access my own commands.
> > Ideally, this could be used by the end user. So, I'd like to not require
> > the my_func(args) syntax,
> > as that may look a bit kludgey/unfinished from a users standpoint. I'd
> > like to be able to use "my_command args" from the python cmd line.
> > Everything else I need is already there, readline line editing,
> > customizable tab-completer, python language support.
> >
> > My expertise is in Tcl, where this is trivial. I'm trying out python as
> > there are others here that already use it, and it's well, somewhat
> > syntactically cleaner.
> >
> >
> > -Bruce.
> >
> >
> > >
> > > ----- Original Message -----
> > > From: "Bruce Edge" <bedge at troikanetworks.com>
> > > Newsgroups: comp.lang.python
> > > To: <python-list at python.org>
> > > Sent: Friday, March 02, 2001 10:34 AM
> > > Subject: create new statement?
> > >
> > > > Can you add a new statement to python?
> > > > AFAICT the only type of commands that don't require () or . after them
> > > > are statements.
> > > >
> > > > I want to add my own command to the interp, but not have to use object
> > > > calling syntax
> > > > eg:
> > > >     create obj opt
> > > > not
> > > >     create(obj, opt)
> > > >
> > > > How do I define new statements, or, a way of calling functions using
> the
> > > > former syntax?
> > > >
> > > > Thanks, Bruce.
> > > > --
> > > > http://mail.python.org/mailman/listinfo/python-list
> > > >
> >



More information about the Python-list mailing list