Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 21:39 Go to next message
eyrieowl is currently offline eyrieowlFriend
Messages: 6
Registered: May 2010
Junior Member
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 05:54 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
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 17:51 Go to previous message
eyrieowl is currently offline eyrieowlFriend
Messages: 6
Registered: May 2010
Junior Member
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: Thu Sep 19 13:06:17 GMT 2024

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

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

Back to the top