0

In my grammar i have an include rule as follow :

Script:
    includes+=(Include)* assignments+=(Assignment)* clock=Clock? tests+=Test*
;

Include:
    'INCLUDE' importURI=STRING
;

what I want to do is to include files same as the "main" file.

I'm working with an interpreter that handels the .mydsl file.

/* Main exec methode  */

def dispatch void exec(Script s) {

    s.includes.forEach[ i | i.exec]  
    s.assignments.forEach[a | a.exec]
    s.clock.exec
    s.tests.forEach[t|t.exec]
}

/* include methode */
def dispatch void exec(Include i) {

    System.out.println( i.importURI + " included")

}
BR.Hamza
  • 99
  • 14

1 Answers1

0

Xtext imports are not includes. Xtext does not support includes at all. All that Xtext supports are Cross References. You can use namespace based or import uri based global scoping to determine how elements from other files can be found. assume you really want to follow the includes files in your interpreter

Script:
    includes+=(Include)*
;

Include:
    'INCLUDE' includedScript=[Script|STRING]
;

And Name Provider

public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {

    QualifiedName qualifiedName(Script script) {
        return QualifiedName.create(script.eResource().getURI().trimFileExtension().lastSegment(), script.eResource().getURI().fileExtension());
    }

}

then you can follow the reference in your interpreter

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {

    override bindIQualifiedNameProvider() {
        MyDslQNP
    }

}
Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • excuse me, but how do I "follow" the reference in my interpreter. I created the MyDslQnp class in the package where I have the interpreter, is that right? – BR.Hamza Dec 28 '16 at 16:43
  • noooooo. you simply bind the nameprovider in runtime module.and create it somewhere around it. in your intepreter simply call myInclude.getIncludedScript()` – Christian Dietrich Dec 28 '16 at 16:45
  • I will do something like this class MyDslRuntimeModule extends AbstractMyDslRuntimeModule { override bindIValueConverterService() { return MyDslValueConverters } @Override public Class extends IQualifiedNameProvider> bindIQualifiedNameProvider() { return MyDslQNP.class } } but the runtime is in xtend and this code in java. I have errors that I can't correct, any ideas ? – BR.Hamza Dec 28 '16 at 16:58
  • i asssumed it would be no problem for you to switch between java and xtend and do the binding. i updated the answer – Christian Dietrich Dec 28 '16 at 17:07
  • I still have a probleme. the script to be included has some declaration on it. but I'm note able to access them – BR.Hamza Dec 28 '16 at 17:20
  • well yes so you need includes and imports?!? Then you need to implement this. since i dont know what you implemented regarding global scoping it is hard to tell. can you please elaborate? – Christian Dietrich Dec 28 '16 at 17:21
  • not need to, I was missing something in my own code. it's working now. Answer accepted – BR.Hamza Dec 28 '16 at 17:31