Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[xtext-dev] how to resolve import files when using in standalone mode

hi,
 I am new to XText. I try to use the parser in standalone mode, however, it do not resole imported files automatically, how to make the parser to parser the imported files?
using the Xtext entity demo as an example:
// grammar
Model :
 (imports+=Import)*
 (elements+=Type)*;
 
Import :
 'import' importURI=STRING;
 
Type:
 SimpleType | Entity;
 
SimpleType:
 'type' name=ID;
 
Entity :
 'entity' name=ID ('extends' extends=[Entity])? '{'
  properties+=Property*
 '}';
......
 
 
DSL files:
 
// file a.dsl
entity A{}....
 
// file b.dsl
import "a.dsl"
 
entity B extends A{}
 
// standalone code
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(
    URI.createURI("b.dsl"), true);
Model model = (Model) resource.getContents().get(0);
// it do not resolve a.dsl here and get null pointer error.
 
 

Back to the top