Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing Enum from imported ECore model
Accessing Enum from imported ECore model [message #1860231] Mon, 24 July 2023 17:16 Go to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
Hello,

I have an imported ECore model into my xtext grammar. I'm trying to maintain one list of Enum types for both my ECore model and my Xtext grammar. What I'm currently struggling with is how to create rules using my Enum types from my ECore model.
grammar org.mcmaster.pfcsm.operation.actiondsl.Actiondsl with org.eclipse.xtext.common.Terminals

generate actiondsl "http://www.mcmaster.org/pfcsm/operation/actiondsl/Actiondsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.example.org/pfcsm" as pfcsm

Domainmodel:
    (elements+=AbstractElement)*;
 
AbstractElement:
    PackageDeclaration | Type;

PackageDeclaration:
    'package' name=QualifiedName '{'
        (elements+=AbstractElement)*
    '}';
   
QualifiedName:
    ID ('.' ID)*;
    
Type:
	DataType | Value | Variable
;

DataType:
	type = [pfcsm|PrimitiveType]
;

Value:
	STRING | INT
;

Variable:
	'var' name=ID ' ' type=[DataType] '=' Value
;


Any instructions on how to reach the enum 'PrimitiveType' would be appreciated.
Re: Accessing Enum from imported ECore model [message #1860233 is a reply to message #1860231] Mon, 24 July 2023 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
I can't follow you.
Enums are not cross refs
So you need to define and use a enum

DataType: type= PrimitiveType

enum PrimitiveType returns pfcsm::PrimitiveType: ..


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 24 July 2023 17:48]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860236 is a reply to message #1860233] Mon, 24 July 2023 18:03 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
This is the enum from ECore:
index.php/fa/43345/0/

So I'm essentially building a local copy of it in my xtext grammar.

enum PrimitiveType returns pfcsm::PrimitiveType:
	String | Int | Double | Boolean
;


I'm assuming since they aren't cross refs this is the only way to maintain the 'same' enums in both abstract syntaxes?
Re: Accessing Enum from imported ECore model [message #1860237 is a reply to message #1860236] Mon, 24 July 2023 18:11 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
I've also run into this error trying to generate the xtext artifacts:
445  [main] ERROR xt.generator.XtextGeneratorLanguage  - [XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'., XtextLinkingDiagnostic: null:29 Couldn't resolve reference to EClassifier 'PrimitiveType'., TransformationDiagnostic: null:29 Cannot create type without declared package. (ErrorCode: UnknownMetaModelAlias)]
446  [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow org.mcmaster.pfcsm.operation.actiondsl.GenerateActiondsl: Problem parsing 'file:/C:/Users/sirch/eclipse-workspace/org.mcmaster.pfcsm.operation.actiondsl/../org.mcmaster.pfcsm.operation.actiondsl/src/org/mcmaster/pfcsm/operation/actiondsl/Actiondsl.xtext':
XtextLinkingDiagnostic: null:5 Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'.
XtextLinkingDiagnostic: null:29 Couldn't resolve reference to EClassifier 'PrimitiveType'.
TransformationDiagnostic: null:29 Cannot create type without declared package. (ErrorCode: UnknownMetaModelAlias)


How do I add my ECore model to path?

[Updated on: Mon, 24 July 2023 18:13]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860238 is a reply to message #1860237] Mon, 24 July 2023 18:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
yes you need to replicate in grammar. synatax could be different from ecore.
referencedResource in the workflow file to genmodel should solve this


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 24 July 2023 18:25]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860239 is a reply to message #1860238] Mon, 24 July 2023 18:29 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
Does that mean I add the ecore model here?
index.php/fa/43346/0/

Not really sure how to do this "referencedResource in the workflow file to genmodel should solve this"
Re: Accessing Enum from imported ECore model [message #1860240 is a reply to message #1860239] Mon, 24 July 2023 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
no, the workflow file.
and the manifest.mf

(dont know where your ecores are)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing Enum from imported ECore model [message #1860241 is a reply to message #1860240] Mon, 24 July 2023 18:35 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
Currently my ecores and my xtext are all in my current workspace.

In my xtext manifest I've added my main ecore folder (not the generated ones) to my dependencies as required plug-ins and imported packages. And then in runtime I've also added the same main ecore project to class path, shown in the image above.

Is the workflow file the MWE2 file? Do I add something like:

module org.mcmaster.pfcsm.operation.actiondsl.GenerateActiondsl

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

import org.mcmaster.pfcsm
Re: Accessing Enum from imported ECore model [message #1860242 is a reply to message #1860241] Mon, 24 July 2023 18:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
isnt there a referencedResource already in this file?

also: dont mess with classpaths folders etc.

go to manifest
go to dependencies
add plugin that contains ecore to the required bundles


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 24 July 2023 18:43]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860243 is a reply to message #1860242] Mon, 24 July 2023 18:56 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
I just added the reference but I'm still getting the same error.

I've removed the ecore model from the classpath, but left it in the dependencies as you said:
index.php/fa/43347/0/

Still getting the
Couldn't resolve reference to EPackage 'http://www.example.org/pfcsm'.
error. Is the MWE2 file the correct file to be editing or is there another one that I should be looking for?

[Updated on: Mon, 24 July 2023 19:15]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860244 is a reply to message #1860243] Mon, 24 July 2023 18:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
can you please share your project layouts, where the ecore and genmodels are etc, the workflow file etc.
there are 100000 possible combinations i cannot guess

e.g.

add

referencedResource="platform:/resource/org.mcmaster.pfcsm/model/whatever.genmodel"
to the language section of the workflow


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 24 July 2023 19:01]

Report message to a moderator

Re: Accessing Enum from imported ECore model [message #1860245 is a reply to message #1860244] Mon, 24 July 2023 19:08 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
Here is an image of the project explorer
index.php/fa/43348/0/

I've also zipped up the projects together if it helps.
Re: Accessing Enum from imported ECore model [message #1860246 is a reply to message #1860245] Mon, 24 July 2023 19:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
adjusting workflow to

language = StandardLanguage {
referencedResource="platform:/resource/org.mcmaster.pfcsm/model/pfcsm.genmodel"


works perfectly fine for me


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing Enum from imported ECore model [message #1860247 is a reply to message #1860246] Mon, 24 July 2023 19:17 Go to previous message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 103
Registered: March 2020
Senior Member
Ok I didn't understand that it wasn't in the import section of the MWE2 file that needed to be changed. I've added that to the same spot and it works now too for me.

Thanks for the help and sorry for the confusion.

Also for anyone else reading this later workflow file is the MWE2 file for the dsl.
Previous Topic:Vscode plugin issue (OutPutStream issue)
Next Topic:Arithmetic defined in xtext
Goto Forum:
  


Current Time: Sat Jul 27 11:19:34 GMT 2024

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

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

Back to the top