Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Import Ecore Elements in Xtext DSL
Import Ecore Elements in Xtext DSL [message #1244111] Tue, 11 February 2014 23:14 Go to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Hi all,

I've started with XText few days ago and I have a simple example which I went to test before implementing a bigger project.

I have a simple Ecore Meta-Model which models a library that contains books. Both, library and books are characterized by a name.

I want to write a DSL that allows me to do something like this:

SelectedBook BookA
SelectedBook BookB


Where BookA and BookB are books defined in an instance of the ecore meta-model.

I followed this tutorial. However I'm not able to import the books.

When I try to use the autocomplete the service is started (I tried to print out something) but I don't see any autocomplete suggesting the books. Also, if I try to write the name of the book manually it returns an error.

Below you can find grammar and MWE2. If needed here there is the entire workspace.

grammar org.library.xtext.dsl.LibraryDSL with org.eclipse.xtext.common.Terminals

generate libraryDSL "http://www.LibraryDSL"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.library.org/model" as lib

Model:
	selectedBooks+=SelectedBooks*
;
	
SelectedBooks:
	'SelectedBook' book=[lib::Book]
;


module LibraryDSL.GenerateLibraryDSL

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/LibraryDSL/LibraryDSL.xtext"
var fileExtensions = "librarydsl"
var projectName = "org.library.xtext.dsl"
var runtimeProject = "../${projectName}"
var generateXtendStub = true
var encoding = "UTF-8"

Workflow {
    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = "${runtimeProject}/.."
    	// The following two lines can be removed, if Xbase is not used.
    	registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
    	registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    	registerGeneratedEPackage = "library.LibraryPackage"
    	registerEcoreFile = "platform:/resource/org.library.model/model/Library.ecore"
    	registerGenModelFile = "platform:/resource/org.library.model/model/Library.genmodel"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}/model"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}.ui/src-gen"
    }
    
    component = DirectoryCleaner {
    	directory = "${runtimeProject}.tests/src-gen"
    }
    
    component = Generator {
    	pathRtProject = runtimeProject
    	pathUiProject = "${runtimeProject}.ui"
    	pathTestProject = "${runtimeProject}.tests"
    	projectNameRt = projectName
    	projectNameUi = "${projectName}.ui"
    	encoding = encoding
    	language = auto-inject {
    		uri = grammarURI
    
    		// Java API to access grammar elements (required by several other fragments)
    		fragment = grammarAccess.GrammarAccessFragment auto-inject {}
    
    		// generates Java API for the generated EPackages
    		fragment = ecore.EMFGeneratorFragment auto-inject {}
    
    		// the old serialization component
    		// fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}    
    
    		// serializer 2.0
    		fragment = serializer.SerializerFragment auto-inject {
    			generateStub = false
    		}
    
    		// a custom ResourceFactory for use with EMF
    		fragment = resourceFactory.ResourceFactoryFragment auto-inject {}
    
    		// The antlr parser generator fragment.
    		fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
    		//  options = {
    		//      backtrack = true
    		//  }
    		}
    
    		// Xtend-based API for validation
    		fragment = validation.ValidatorFragment auto-inject {
    		//    composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
    		//    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
    		}
    
    		// old scoping and exporting API
    		// fragment = scoping.ImportURIScopingFragment auto-inject {}
    		// fragment = exporting.SimpleNamesFragment auto-inject {}
    
    		// scoping and exporting API
    		fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
    		fragment = exporting.QualifiedNamesFragment auto-inject {}
    		fragment = builder.BuilderIntegrationFragment auto-inject {}
    
    		// generator API
    		fragment = generator.GeneratorFragment auto-inject {}
    
    		// formatter API
    		fragment = formatting.FormatterFragment auto-inject {}
    
    		// labeling API
    		fragment = labeling.LabelProviderFragment auto-inject {}
    
    		// outline API
    		fragment = outline.OutlineTreeProviderFragment auto-inject {}
    		fragment = outline.QuickOutlineFragment auto-inject {}
    
    		// quickfix API
    		fragment = quickfix.QuickfixProviderFragment auto-inject {}
    
    		// content assist API
    		fragment = contentAssist.ContentAssistFragment auto-inject {}
    
    		// generates a more lightweight Antlr parser and lexer tailored for content assist
    		fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {}
    
    		// generates junit test support classes into Generator#pathTestProject
    		fragment = junit.Junit4Fragment auto-inject {}
    
    		// rename refactoring
    		fragment = refactoring.RefactorElementNameFragment auto-inject {}
    
    		// provides the necessary bindings for java types integration
    		fragment = types.TypesGeneratorFragment auto-inject {}
    
    		// generates the required bindings only if the grammar inherits from Xbase
    		fragment = xbase.XbaseGeneratorFragment auto-inject {}
    
    		// provides a preference page for template proposals
    		fragment = templates.CodetemplatesGeneratorFragment auto-inject {}
    
    		// provides a compare view
    		fragment = compare.CompareFragment auto-inject {}
    	}
    }
}
Re: Import Ecore Elements in Xtext DSL [message #1244145 is a reply to message #1244111] Wed, 12 February 2014 00:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is a common error that has nothing todo with using a reourceserviceprovider
the books names are <LibName>.<BookName>
the grammar is book=[lib::Book] which is short for book=[lib::Book|ID] - and an ID does not allow a .

=> change the nameprovider of the resourceserviceprovider
=> or the grammar to

SelectedBooks:
	'SelectedBook' book=[lib::Book|FQN]
;

FQN: ID ("." ID)*;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import Ecore Elements in Xtext DSL [message #1244758 is a reply to message #1244145] Wed, 12 February 2014 21:18 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Thanks Christian,

now it works.

Just a clarification. Is XText assuming that Library and Book have an EString field called 'name'?

Second question: is the text written with the DSL also storable/convertable to an ECore compliant file (like the one in which I store the library)?

Thanks again!
Re: Import Ecore Elements in Xtext DSL [message #1244770 is a reply to message #1244758] Wed, 12 February 2014 21:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes you can read the xtext resource, add it contents to an xmi resource and then save it. (there should be topics on that)
is there a reason you need an xmi?



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import Ecore Elements in Xtext DSL [message #1244799 is a reply to message #1244770] Wed, 12 February 2014 22:38 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Thanks. No explicit reasons, it was just a curiosity.

Thanks!

[Updated on: Thu, 13 February 2014 00:00]

Report message to a moderator

Re: Import Ecore Elements in Xtext DSL [message #1244998 is a reply to message #1244799] Thu, 13 February 2014 06:25 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi this is strange. Is this an error in eclipse or when running the
workflow

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Solved] DocumentTokenSource Injection
Next Topic:org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type org.eclipse.xtext.gener
Goto Forum:
  


Current Time: Wed Apr 24 19:40:13 GMT 2024

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

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

Back to the top