[IronPython] Dear Lazy Web - IronPython 2 Parser
dinov at exchange.microsoft.com
Mon Aug 13 17:41:41 CEST 2007
I don't know if you figured this out yet but here goes...
Our Parser class is still public (I'm not sure if this will change or not) but you can do (IronPython.Compiler.)Parser.CreateParser. That takes a CompilerContext class which is going to point the parser at a SourceUnit that we are currently parsing.
>From there you can call ParseFileInput and it'll parse the file and return you the IronPython AST. The interesting part might be if you actually want to compile that code later on :). In that case you might want to look at PythonScriptCompiler to see the rest of the process - it's really just one call to PythonScriptCompiler.BindAndTransform which also seems to be public (again, I'm not sure if that'll change or not).
Alternately if you just want a way to paramterize some user code you might want to look at ScriptCompiler.ParseCodeDom. This allows you to provide a limited CodeDom tree (we support CodeMemberMethod, and snippet statement / expressions and that's it) which you could create from some user input. The nice thing about that is it won't be Python specific (although I'm guessing that's not a problem for you :) ).
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Wednesday, August 08, 2007 3:50 PM
To: Discussion of IronPython
Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser
Sorry for being lazy, but...
What is the easiest way of building an AST from IronPython 2 code? I
would like an AST that I can modify and then flatten again in
Silverlight.... It needn't be a Python AST, an IronPython one is fine. I
only need access to 'name' nodes... I wish to change some of the names
and turn the AST back into code before exec'ing.
Users mailing list
Users at lists.ironpython.com
More information about the Ironpython-users