moonsharp-devs / moonsharp

An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
http://www.moonsharp.org
Other
1.42k stars 214 forks source link

Expression Tree With Line Numbers #152

Closed RobertBColton closed 8 years ago

RobertBColton commented 8 years ago

So for a special project I am doing I would like to be able to parse a Lua and then walk the AST and get the line numbers and ranges of each node. I am wanting to do this so that I can create an interactive code editor with drag and drop for Lua (it's just an experiment). It will be similar to say a class hierarchy in Visual Studio or Eclipse.

Is this at all possible with MoonSharp to get line numbers of the AST nodes and is the functionality considered "stable"? If it is not is there perhaps a simpler NuGet package that can do this for me?

xanathar commented 8 years ago

It's quite easy but not exposed to the outside. Just check Loader_Fast.LoadChunk to udnerstand how to trigger parsing and get an AST.

That uses a lot of internal classes - just import the sources instead of the DLLs and you are basically done. Every node in the AST has the references to the source code.