Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Xtext/FAQ"

Line 1: Line 1:
 
= General  =
 
= General  =
 +
 +
== How do I load my model in a standalone Java application ? ==
 +
 +
<source lang="java">
 +
Injector injector = FooStandaloneSetup.createInjectorAndDoEMFRegistration();
 +
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
 +
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
 +
Resource resource = resourceSet.getResource(URI.createURI("platform:/resource/myproject/my.foo"), true);
 +
Foo = (Foo) resource.getContents().get(0);
 +
</source>
  
 
= Workflow / Generator  =
 
= Workflow / Generator  =
  
== Why do I get warnings like "warning(200): InternalFoo.g:42:3: Decision can match ..." when running the generator&nbsp;?  ==
+
== Why do I get warnings like "warning(200): InternalFoo.g:42:3: Decision can match ..." when running the generator ?  ==
  
 
Here's an example of the full error message:  
 
Here's an example of the full error message:  
Line 14: Line 24:
 
These warnings are generated by the ANTLR code generator. Based on the rules in your grammar the ANTLR generated parser cannot disambiguate what rules to apply for a given input. You should try to refactor your grammar (see [http://www.antlr.org/pipermail/antlr-interest/2008-November/031697.html example]) or you can enable backtracking for your parser (see next question).  
 
These warnings are generated by the ANTLR code generator. Based on the rules in your grammar the ANTLR generated parser cannot disambiguate what rules to apply for a given input. You should try to refactor your grammar (see [http://www.antlr.org/pipermail/antlr-interest/2008-November/031697.html example]) or you can enable backtracking for your parser (see next question).  
  
== OK, but I didn't get these warnings in oAW Xtext&nbsp;!  ==
+
== OK, but I didn't get these warnings in oAW Xtext !  ==
  
 
Unlike in oAW Xtext the ANTLR grammar generated by TMF Xtext doesn't have [http://www.antlr.org/wiki/display/ANTLR3/Grammar+options backtracking] enabled by default. To enable backtracking you have to add a nested element &lt;options backtrack="true"/&gt; to the ANTLR generator fragments in your Xtext project's MWE workflow. For example:  
 
Unlike in oAW Xtext the ANTLR grammar generated by TMF Xtext doesn't have [http://www.antlr.org/wiki/display/ANTLR3/Grammar+options backtracking] enabled by default. To enable backtracking you have to add a nested element &lt;options backtrack="true"/&gt; to the ANTLR generator fragments in your Xtext project's MWE workflow. For example:  
Line 25: Line 35:
 
</source>  
 
</source>  
  
== Why are generated packages from an imported grammar A duplicated in dependent grammar B&nbsp;?  ==
+
== Why are generated packages from an imported grammar A duplicated in dependent grammar B ?  ==
  
 
In addition to the import statement in B.xtext you must also configure your GenerateB.mwe workflow to let it know about the corresponding GenModels of grammar A. You do this by [http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html#UsingresourceURIstoimportexistingEPackages setting the genModels attribute] of the EcoreGeneratorFragment:  
 
In addition to the import statement in B.xtext you must also configure your GenerateB.mwe workflow to let it know about the corresponding GenModels of grammar A. You do this by [http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html#UsingresourceURIstoimportexistingEPackages setting the genModels attribute] of the EcoreGeneratorFragment:  

Revision as of 03:51, 17 July 2009

General

How do I load my model in a standalone Java application ?

Injector injector = FooStandaloneSetup.createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(URI.createURI("platform:/resource/myproject/my.foo"), true);
Foo = (Foo) resource.getContents().get(0);

Workflow / Generator

Why do I get warnings like "warning(200): InternalFoo.g:42:3: Decision can match ..." when running the generator ?

Here's an example of the full error message:

warning(200): InternalFoo.g:42:3: Decision can match input such as "FOO" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

These warnings are generated by the ANTLR code generator. Based on the rules in your grammar the ANTLR generated parser cannot disambiguate what rules to apply for a given input. You should try to refactor your grammar (see example) or you can enable backtracking for your parser (see next question).

OK, but I didn't get these warnings in oAW Xtext !

Unlike in oAW Xtext the ANTLR grammar generated by TMF Xtext doesn't have backtracking enabled by default. To enable backtracking you have to add a nested element <options backtrack="true"/> to the ANTLR generator fragments in your Xtext project's MWE workflow. For example:

  <!-- Antlr Generator fragment -->
  <fragment class="org.eclipse.xtext.generator.AntlrDelegatingFragment">
      <options backtrack="true"/>
   </fragment>

Why are generated packages from an imported grammar A duplicated in dependent grammar B ?

In addition to the import statement in B.xtext you must also configure your GenerateB.mwe workflow to let it know about the corresponding GenModels of grammar A. You do this by setting the genModels attribute of the EcoreGeneratorFragment:

   <fragment class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment"
      genModels="platform:/resource/project/src/my/pack/SecretCompartments.genmodel"/>

Back to the top