Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Determining DSL location from AST(is location information maintained in AST?)
Determining DSL location from AST [message #554281] Fri, 20 August 2010 17:39 Go to next message
Eclipse UserFriend
I was wondering if there is any way to determine where an Abstract Syntax Tree node came from? I know that when it's parsing, Antlr is able to spit out the line number and character offset where an error occurs, but I was wondering if it captured that information when constructing the syntax tree? I've tried inspecting the nodes in the debugger, and I'd imagine that if the information exists, it would probably be somewhere accessible from the methods on MinimalEObjectImpl.Container (that being the base class for the code generated nodes), but...I got to where it was difficult to tell what the information meant (i.e., there's no convenient "lineNumber" field or anything); and I also kept ending up in reference cycles. So...to save my sanity, is there anyone who can tell me if the information exists and what I need to do to get at it? It's great for the parser to tell people where they are lexically wrong, but I'd like to be able to post-process and let them know where errors occur processing their dsl. I.e., if I get a NPE processing a node they described in the DSL (because, say, it's referencing some other system component which throws an error), I'd like to be able to refer them back to where in the DSL that happened, not just where in the processing code I was at. Thanks!
Re: Determining DSL location from AST [message #554303 is a reply to message #554281] Sat, 21 August 2010 01:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

if I understand you correctly, the class NodeUtil with its static methods is your friend. Using that, you can navigate from the model (AST) to the parse tree, which contains all the syntactic information about your model. See also the documentation 2.2.3 Working with the Parse Tree.

Alex
Re: Determining DSL location from AST [message #554622 is a reply to message #554303] Mon, 23 August 2010 13:51 Go to previous message
Eclipse UserFriend
Yes, that's perfect. Thanks!
Previous Topic:Loading a model where some values (used in this model) are defined by the another model
Next Topic:"hidden assignments" in parser rules
Goto Forum:
  


Current Time: Sun Jul 13 14:29:03 EDT 2025

Powered by FUDForum. Page generated in 0.03289 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top