I'm using xtext to generate an editor for a particular language. When using the editor for my new language, it has all the lovely xtext features like code-completation and coloring and so on. What I'd like to be able to do is visualise the structure of the text in my editor.
I know that xtext has an internal AST and a parse tree ( I understand that they call it a `node model') - is there any way of visualising this tree?
A simple solution in xtend (based on the introspection done by default by EObject.toString()):
def static String dump(EObject mod_, String indent) {
var res = indent + mod_.toString.replaceFirst ('.*[.]impl[.](.*)Impl[^(]*', '$1 ')
for (a :mod_.eCrossReferences)
res += ' ->' + a.toString().replaceFirst ('.*[.]impl[.](.*)Impl[^(]*', '$1 ')
res += "\n"
for (f :mod_.eContents) {
res += f.dump (indent+" ")
}
return res
}
Output from a call such as dump(someEObject, '') will return:
ExpressionModel
Variable (name: i)
Plus
IntConst (value: 1)
Plus
IntConst (value: 2)
Plus
IntConst (value: 3)
Variable (name: j)
Plus
VarRef ->Variable (name: i)
Plus
IntConst (value: 4)
Plus
IntConst (value: 5)
This might help you: https://github.com/OLibutzki/xtext.tools
It offers an outline for the node model and for the semantic model (AST).
You should check the content outline. I have customized mine but I think that the default one reflects the structure of the model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With