Skip to main content



      Home
Home » Modeling » TMF (Xtext) » cross-reference scoping from 2 different grammar/models(Is this possible via getScope()?)
cross-reference scoping from 2 different grammar/models [message #1797392] Tue, 30 October 2018 10:27 Go to next message
Eclipse UserFriend
Hi,

I am looking for a way for one xtext model to refer from another model without any explicit import features within the grammar.

Similiar to https://stackoverflow.com/questions/41967361/reference-a-dsl-from-another-dsl-and-its-model but without 'import'

Here is simplified scenario of what I try to achieve.


    I have 2 xtext grammars (MyDsl1 & MyDsl2).


    MyDsl1 contains datatypes list
    grammar org.xtext.example.mydsl.MyDsl1 with org.eclipse.xtext.common.Terminals
    
    generate myDsl1 "http://www.xtext.org/example/mydsl/MyDsl1"
    
    Domainmodel1 :
        (elements+=Type)*;
    
    Type:
        'datatype' name=ID;
    



    MyDsl2 contains feature based on MyDsl1 's dataype
    grammar org.xtext.example.mydsl.MyDsl2 with org.eclipse.xtext.common.Terminals
    
    generate myDsl2 "http://www.xtext.org/example/mydsl/MyDsl2"
    import "http://www.xtext.org/example/mydsl/MyDsl1" as mydsl1
    
    Domainmodel2 :
        (features+=Feature)*;
      
    Feature:
        name=ID ':' type=[mydsl1::Type];
    


    MWE:
    module org.xtext.example.mydsl.GenerateMyDsl2
    
    import org.eclipse.xtext.xtext.generator.*
    import org.eclipse.xtext.xtext.generator.model.project.*
    
    var rootPath = ".."
    
    Workflow {
    	bean = org.eclipse.emf.mwe.utils.StandaloneSetup {
    		platformUri = "../.."
    		scanClassPath = true
    		registerGeneratedEPackage = "org.xtext.example.mydsl.myDsl1.MyDsl1Package"
    		registerGenModelFile = "platform:/resource/org.xtext.example.mydsl1/model/generated/MyDsl1.genmodel"
    	}
    
    	component = XtextGenerator {
    		configuration = {
    			project = StandardProjectConfig {
    				baseName = "org.xtext.example.mydsl2"
    				rootPath = rootPath
    				runtimeTest = {
    					enabled = true
    				}
    				eclipsePlugin = {
    					enabled = true
    				}
    				eclipsePluginTest = {
    					enabled = true
    				}
    				createEclipseMetaData = true
    			}
    			code = {
    				encoding = "UTF-8"
    				lineDelimiter = "\n"
    				fileHeader = "/*\n * generated by Xtext \${version}\n */"
    			}
    		}
    		language = StandardLanguage {
    			name = "org.xtext.example.mydsl.MyDsl2"
    			fileExtensions = "mydsl2"// referencedResource = "platform:/resource/org.xtext.example.mydsl1/model/generated/MyDsl1.genmodel"
    			fragment = scoping.ImportNamespacesScopingFragment2 auto-inject {}
    			serializer = {
    				generateStub = false
    			}
    			validator = {
    			// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
    			// Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage
    				generateDeprecationValidation = true
    			}
    			junitSupport = {
    				junitVersion = "5"
    			}
    		}
    
    	}
    }
    



    Once I launch eclipse application, myDsl2 does not able to recognize datatype from myDsl1.
    $ cat types.myDsl1
    datatype string
    datatype integer
    
    $ cat features.myDsl2
    name : string
    



    I was expecting to able get access to MyDsl1 root Eobject from getScope
    class MyDsl2ScopeProvider extends AbstractMyDsl2ScopeProvider {
    	override getScope(EObject context, EReference reference) {
    		if (context instanceof Feature) {
    			if (reference == MyDsl2Package.Literals.FEATURE__TYPE) {
    				val rootElement = EcoreUtil2....
    				...
    			}
    		}
    		super.getScope(context, reference)
    	}
    }
    


    I not able to see such api from EcoreUtil2.


    Perhaps the solution doesn't involve getScope() at all. But appreciate if can point the best way to deal with this.


Thanks.

[Updated on: Tue, 30 October 2018 10:30] by Moderator

Re: cross-reference scoping from 2 different grammar/models [message #1797401 is a reply to message #1797392] Tue, 30 October 2018 11:49 Go to previous messageGo to next message
Eclipse UserFriend
you should use referencedResource="platform:/resource/org.xtext.example.mydsl1/model/generated/MyDsl1.genmodel in the language section of the mydsl2 workflow instead of the standalonesetup.
besides that it should work out of the box with no customization to scoping.
how exaclty do you test this?
Re: cross-reference scoping from 2 different grammar/models [message #1797480 is a reply to message #1797401] Wed, 31 October 2018 09:54 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian for the pointer. I able to get it to work now.

Once I have reverted it to referencedResource, had to fix few plugin dependencies and then it worked.

> how exaclty do you test this?
Currently I am just launching this from Eclipse as Eclipse Application.

Since dealing with lots of plugins dependencies, I would like to get your opinion on my project/plugins structures.
Following what I have
- base xcore model (xcore1)
- xtext1 dsl for xcore1
- xcore2 uses xcore1
- xtext 2 dsl for xcore2

Eclipse Project/Plugins that I have created so far:
- acme.ide.xcore1 (xcore project to just contain xcore model)
- acme.ide.xcore1.model (auto generated)
- acme.ide.xcore1.edit (auto generated)
- acme.ide.xcore1.editor (auto generated)
- acme.ide.xcore1.tests (auto generated)
- acme.ide.xtext1 (xtext project, contains DSL grammar and mwe)
- acme.ide.xtext1.ide (xtext project)
- acme.ide.xtext1.tests (xtext project)
- acme.ide.xtext1.ui (xtext project)
- acme.ide.xtext1.ui.tests (xtext project)

- acme.ide.xcore2 (xcore project to just contain xcore model)
- acme.ide.xcore2.model (auto generated)
- acme.ide.xcore2.edit (auto generated)
- acme.ide.xcore2.editor (auto generated)
- acme.ide.xcore2.tests (auto generated)
- acme.ide.xtext2 (xtext project, contains DSL grammar and mwe)
- acme.ide.xtext2.ide (xtext project)
- acme.ide.xtext2.tests (xtext project)
- acme.ide.xtext2.ui (xtext project)
- acme.ide.xtext2.ui.tests (xtext project)

The problem I see here is, I had to manually add plugin dependencies for each to one or more other plugins (quite a bit of work).

Any way to let mwe to handle this?

ps1: Currently this is just a PoC work - eventually I plan to try bundle these as LSP as well.
ps2: I think I should able to combine acme.ide.xcore1/acme.ide.xcore1.model and acme.ide.xcore2/acme.ide.xcore2.model.

Thanks.
Re: cross-reference scoping from 2 different grammar/models [message #1797488 is a reply to message #1797480] Wed, 31 October 2018 11:16 Go to previous message
Eclipse UserFriend
there are some examples out there using xcore and maven/gradle + mwe
but it might be tricky to get this running in more complicated scenarios
Previous Topic:ignore the "No EObjectDescription could be found in Scope" error
Next Topic:Confused: Cyclic resolution of lazy links
Goto Forum:
  


Current Time: Sun Jun 15 15:35:08 EDT 2025

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

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

Back to the top