Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Output the parse trace of standalone Xtext parse(How can I output the parse trace?)
Output the parse trace of standalone Xtext parse [message #1744864] Fri, 30 September 2016 21:06 Go to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
This question has probably been answered before but I have searched the forum messages and I cannot find some simple code for outputting the trace of a standalone Xtext parse execution. I found some code to do the standalone parse, but I can't find any outputting code. Here is the code I am using to do the parse:

Injector injector = new DomainStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance( XtextResourceSet.class );
resourceSet.addLoadOption( XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE );
Resource resource = resourceSet.getResource( URI.createFileURI( new File( "test5.f" ).toString()), true );
EList<Diagnostic> errs = resource.getErrors();

When I look at errs, I can see in the Eclipse debugger the expected parse error in test5.f that was produced. For this case and for other cases that there are no errors I would like to print out the parse trace of execution. I can't use AntlrWorks with my grammar because I have built it with backtrackLexer=true which doesn't work with Antlr. Any help that you can give me to output the parse would be greatly appreciated.

Thanks,
Larry
Re: Output the parse trace of standalone Xtext parse [message #1744873 is a reply to message #1744864] Sat, 01 October 2016 07:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The node model contains the information which grammar elements where used

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Output the parse trace of standalone Xtext parse [message #1745423 is a reply to message #1744873] Mon, 10 October 2016 14:35 Go to previous messageGo to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
I am extremely novice with Xtext. Could you please point me towards code or documentation that could help me "walk" the node model?
Re: Output the parse trace of standalone Xtext parse [message #1745429 is a reply to message #1745423] Mon, 10 October 2016 14:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you be more specific which exact information you need/expect in error case?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Output the parse trace of standalone Xtext parse [message #1745435 is a reply to message #1745429] Mon, 10 October 2016 15:55 Go to previous messageGo to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
Thanks for your reply. I have a grammar that should parse the following input:

c->priority := VERY_HIGH_PRIORITY;

but it is showing an error with the ":=" when I run it in GUI mode with the Eclipse plug-in. Since I can't run my grammar with AntlrWorks, I would like to see exactly the parse tree that it is going through relative to my grammar and see where the error is being detected by Xtext (or Antlr).

I have run this code:

Injector injector = new DomainStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance( XtextResourceSet.class );
resourceSet.addLoadOption( XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE );
Resource resource = resourceSet.getResource( URI.createFileURI( new File( "test5.f" ).toString()), true );
domainStart model = (domainStart) resource.getContents().get(0);

but I don't know what code I need to walk "model" so I can see what productions were taken and where the error actually occurs.

Any suggestions?

Thanks,
Larry
Re: Output the parse trace of standalone Xtext parse [message #1745437 is a reply to message #1745435] Mon, 10 October 2016 16:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Your resource may be an instance of xtextresorce which gives you access to a parseresult which gives you access to a rootnode which has. Method that gives you an iterator.
Having a look at inode class will give you access e.g. To a grammarelemt


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Output the parse trace of standalone Xtext parse [message #1745447 is a reply to message #1745437] Mon, 10 October 2016 19:54 Go to previous messageGo to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
I noticed some references to the Xtext Tools (https://github.com/OLibutzki/xtext.tools) where one can drill down into the node model and semantic models of Xtext models. Could this tool help me to see the parse tree for my Xtext model? Also, will it work with Xtext 2.10 that I am using? I was trying to do this with the code I showed before, but perhaps a tool will do it for me?
Re: Output the parse trace of standalone Xtext parse [message #1745451 is a reply to message #1745437] Mon, 10 October 2016 21:37 Go to previous message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
Thank-you! Your suggestion worked. I added the following to my previous code and now I think I can walk the parse tree.

Injector injector = new DomainStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance( XtextResourceSet.class );
resourceSet.addLoadOption( XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE );
Resource resource = resourceSet.getResource( URI.createFileURI( new File( "test5.f" ).toString()), true );

ADDED:

XtextResource xtresource = (XtextResource) resource;
if ( xtresource != null ) {
IParseResult parseResult = xtresource.getParseResult();
if ( parseResult != null ) {
ICompositeNode rootNode = parseResult.getRootNode();
for ( INode abstractNode : rootNode.getAsTreeIterable() ) {
System.out.println( abstractNode );
}}}
Previous Topic:Understanding Xtext syntax
Next Topic:[SOLVED] Do not work code generation on CDT
Goto Forum:
  


Current Time: Thu Apr 25 19:03:44 GMT 2024

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

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

Back to the top