[Journal - Parse Tree Visualization]

Parse Tree Visualization

Sunday, April 1, 2007

Check out the the FCodeTree form in the Gregor.NetConsole project. The form consists of a tree view and a text box. You can load code into the form, then it's parsed, and whenever you navigate in the tree, the selection in the text box updates to highlight the code that corresponds to that node in the parse tree. Vice versa, if you move the caret in the text box, the corresponding node is selected.

Other Stuff

I have another .NET Console feature: persistence of interpreter code now includes delegates that aren't bound to a target - that is, regular static and open instance delegates. A call to Gregor.Core.DelegateUtil.CreateStaticDelegate() or CreateOpenInstanceDelegate(), respectively, is used as the initialization expression.

By the way, did you know that open instance delegates can be bound to an interface method? Just look:

del = DelegateUtil.CreateOpenInstanceDelegate<Callback<object, ICloneable>>("Clone")
del("Foo")

If you look at the Method property, you'll see that its declaring type is the ICloneable interface. The Target, of course, is null.

This technique allows to bypass the .NET Console limitation of missing casts: if a type implements more that one interface with methods of the same name and signature explicitly, a call to such a member (using just the simple name) results in non-deterministic behaviour (the interpreter just picks the best match). However, with a delegate bound to an interface method, you can disambiguate the call.