0
votes

I want to call variables declared in another file. The include of the file is done using cross referencing. and the call of the declared too. this is the grammar:

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

Assignment:
    Config |Cosem ;

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

Cosem:
name=ID '=' 'COSEM' '(' classid=INT ',' version=INT ','  obis=STRING ')' ;

AttributeRef:
     name=[Cosem] "." attributeRef =IDValue

;

the declaration is the Cosem rule.

from the documentation I understand that I must do something in the IResourceDescription but I don't know what exactly

EDIT

public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {

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

}
1
Which is not working? The attribute ref? If yes scoping is what you are looking for - Christian Dietrich
the include rule includes files which contain Cosem declaration. However, those declarations are not accessible from the "main" file - BR.Hamza
Is this your complete grammar ? If yes how does your name provider look like - Christian Dietrich
I edited the quesstion - BR.Hamza

1 Answers

3
votes

what you are looking for is called "scoping" xtext. it is implemented in YourDslScopeProvider

this could look like

class MyDslScopeProvider extends AbstractMyDslScopeProvider {

    override getScope(EObject context, EReference reference) {
        if (reference === MyDslPackage.Literals.ATTRIBUTE_REF__NAME) {
            // we are scoping the AttributeRef.name cross reference
            val script = EcoreUtil2.getContainerOfType(context, Script)
            if (script !== null) {
                val allImportedCosems = script.includes.map[includedScript.assignments.filter(Cosem)].flatten
                // put the imported cosems into scope
                return Scopes.scopeFor(allImportedCosems)
            }
        }
        super.getScope(context, reference)
    }

}