Another possibility is to use the ast module of python: http://docs.python.org/library/ast.html
The only problem with that module, is that everything you parse must be correct, otherwise it throws an exception, I don't know if that's a problem for your project? -----Original message----- From:Eric S. Johansson <e...@harvee.org> Sent:Mon 30-07-2012 12:00 Subject:Re: simplified Python parsing question To:python-list@python.org; On 7/30/2012 5:25 AM, Laszlo Nagy wrote: > > Did you try to use pygments? > > http://pygments.org/docs/api/ > thanks, I'll take a look. > > I would first tokenize the code, then divide it by statement keywords. > Finally, you just need to find expression/assignment statements in the > remaining sections. (Maybe there is a better way to do it.) > > > yeah the problem is also little more complicated than simple parsing of Python code. For example, one example (from the white paper) *meat space blowback = Friends and family [well-meaning attempt] *could that be parsed by the tools you mention? I suspect not but this is what I need to generate using speech recognition because it's easily spoken. A more complex example might be something like new base = OS path-base name (old path) or if OS base exists (current path): new base name = OS path base name(current path) What's particularly cute here is that using the translation technique I can actually describe the full object method path with a minimum of speaking overhead. Python is great. :-) But the questions remain, will these tools are stuff like this? -- http://mail.python.org/mailman/listinfo/python-list
-- http://mail.python.org/mailman/listinfo/python-list