What is the recommended way to access the AST? #394
-
I need to do a model-to-model transformation from my language's AST to a foreign model (FWIW, the foreign model has no DSL; its implementation is produced from a protobuf file, so I'm just manually translating my AST objects into instances of the foreign model). In my transformation function, I need to obtain the root node of my AST, assuming that there are no validation errors that resulted from the last parse/validate run, and use that node as the basis of transformation. My question is: should I get the current document from the editor, re-initiate parsing, and then obtain the root node from the parseResult, or is getting it from the index service a better way to go? If there are code examples for what's recommended, that would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@ballcoach12 The easies way would probably to simply ask the |
Beta Was this translation helpful? Give feedback.
@ballcoach12 The easies way would probably to simply ask the
LangiumDocuments
service. EachLangiumDocument
contains aParseResult
, where theParseResult#value
property is your AST root node. No reparsing necessary :)