<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>I have been playing with an implementation of a simple GUI console
for IronPython (similar to IDLE, without it&#8217;s text-editor IDE).&nbsp; I&#8217;ve
mostly brought it up to rough feature parity with IDLE, but I&#8217;d like to
add a rudimentary itellisense such that when you type something on the order of
&#8220;foo.&#8221;, the interpreter can pop up a menu containing the contents
of foo (assuming it&#8217;s something already defined in the local scope).&nbsp;
However, I&#8217;d really rather not get in the business of parsing Python
code.&nbsp; (That&#8217;s what the DLR is for!)<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Is there any way I can use DLR to give me the AST up to the
point at which it failed to parse so that I can walk that and see if we are in
a valid place to look up the fields of an object?&nbsp; I looked at using the
ErrorListener class with ScriptSource.Compile, but it only gives me &#8220;unexpected
&lt;eof&gt; found&#8221; at the point where the &#8220;.&#8221; is&#8230;which
I already knew.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Basically, whenever the user presses the &#8220;.&#8221; key
in the console what I would like to do is roughly this code:<o:p></o:p></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:8.0pt;
font-family:Consolas'>&nbsp;&nbsp;&nbsp; <span style='color:#2B91AF'>ScriptEngine</span>
engine = <span style='color:#2B91AF'>Python</span>.CreateEngine();<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:8.0pt;
font-family:Consolas'>&nbsp;&nbsp;&nbsp; <span style='color:#2B91AF'>ScriptScope</span>
scope = engine.CreateScope();<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:8.0pt;
font-family:Consolas'>&nbsp;&nbsp;&nbsp; <span style='color:#2B91AF'>ScriptSource</span>
source = engine.CreateScriptSourceFromString(<span style='color:#A31515'>&quot;if
foo.&quot;</span>, Microsoft.Scripting.<span style='color:#2B91AF'>SourceCodeKind</span>.InteractiveCode);<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:8.0pt;
font-family:Consolas'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:8.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;
source.Compile();&nbsp; <span style='color:green'>// &lt;-- This *should*
fail.&nbsp; I want the AST when it does.</span></span><span style='font-size:
8.0pt;font-family:Consolas'><o:p></o:p></span></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Primarily, I&#8217;m trying to find chains of identifiers to
walk so that I can display the Nth identifier&#8217;s fields:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; identifier1
. identifier2 . identifier3 .&nbsp;&nbsp; &#8230;<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I need to distinguish this from things like this, because
there&#8217;s nothing you can reasonably do to have intellisense in this case:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Function(args)
. identifier1 . identifier2<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>(Yes, I realize that walking this chain can execute code and
have side effects, I&#8217;m willing to live with that for my purposes.)&nbsp;
Is there any mechanism through which I can have the DLR parse this for me and
give me the resulting AST that I can walk so I can see if we can pop up an
intellisense-like view?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Can anyone recommend a better way to do this outside of
simply writing my own mini-parser?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks,<o:p></o:p></p>

<p class=MsoNormal>-Lee Culver<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>