Parsing csh scripts with python

Steve Juranich sjuranic at gmail.com
Wed Mar 29 09:45:24 EST 2006


David Hirschfield wrote:

> Is there a module out there that would be able to parse a csh script and
> give me back a parse tree?
> 
> I need to be able to parse the script, modify some variable settings and
> then write the script back out so that the only changes are the
> variables I've modified (comments, ordering of statements, etc. must
> remain the same).
> 
> I looked at shlex, but I don't think it will do what I need.
> Any suggestions would be appreciated,
> -Dave

There are a number of lexical scanners available for Python, but given your
problem description, that's probably not what you want.

I'd just process the each line, either making modifications or not, then put
the processed line on an "out" buffer (list of strings), then write that
list to a file.  If you do it right, all the comments and things will
remain in place.

-- 
Steve Juranich
Tucson, AZ
USA




More information about the Python-list mailing list