Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Default Cross-References(Allowing a list to contain both cross-references to created objects and keywords)
Default Cross-References [message #1847077] Wed, 13 October 2021 23:24 Go to next message
Camden Blake is currently offline Camden BlakeFriend
Messages: 2
Registered: September 2021
Junior Member
Hello, I am trying to create a DSL for text based input files into a computational code. In these input files, there are sections where references to created materials are passed in a list. The trouble comes when there is a default 'void' material that does not have to be explicitly defined in the input file.
One way I thought to possibly overcome this is to create a Void material rule that only contains the keyword 'void' and returns a material as shown below.
Void_mat returns Material:
	{Material} 'void'
;
Pin_Card:
	{Pin} 'pin' name=Universe (material+=([Material] | Void_mat) radius+=Double)* (material+=([Material] | Void_mat))
;


However, when I go to build this grammar, I receive the following error message.
Quote:

error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11136:25: reference to undefined rule: not
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11136:25: reference to undefined rule: not
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11136:29: reference to undefined rule: matched
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11157:29: reference to undefined rule: matched
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11157:29: reference to undefined rule: matched
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11157:25: reference to undefined rule: not
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11157:25: reference to undefined rule: not
error(106): ../serpent/ide/contentassist/antlr/internal/InternalSerpentParser.g:11136:29: reference to undefined rule: matched


I am not sure what is causing this error, as it is not something I have run into before and is located in files that I do not edit or view.

Is there another way to create a default reference in xtext? Or is this even possible given the current capabilities?
Any help or insight is greatly appreciated!


For reference, the following is a snippet from an input file that is causing this to be necessary.
Quote:

pin 1
fuel1 4.33500E-01
void 4.42000E-01
clad 5.02500E-01
cool

Where fuel1, clad, and cool are all defined materials in the input file.
Re: Default Cross-References [message #1847078 is a reply to message #1847077] Thu, 14 October 2021 04:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14101
Registered: July 2009
Senior Member
emf does not support mixing default and containment list.
thus you either have to
- have two lists (material+=([Material] | material2+=Void_mat)
- move the reference to a own type

material+=MaterialKind

MaterialKind: PredefMaterial | MaterialReference;
PredefMaterial: decl=VoidMaterial;
MaterialReference: x=[Material]

- Dont declare the default materials in grammar-
- add a lib file with prefinded decls to classpath/project
- add additonal predefined decls to resource/scoping in IDerivedStateComputer/Scoping, ....


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Default Cross-References [message #1847083 is a reply to message #1847078] Thu, 14 October 2021 07:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7334
Registered: July 2009
Senior Member
Hi

The contained and not-contained problem is common in non-trivial models.

In UML you can see the double reference solution twice in TemplateParameter as default/ownedDefault and parameteredElement/ownedParameteredElement. It's a simple solution for the model definer, clumy for the Xtext grammar. It just kicks the ambiguity downstream as an inconvenient irregularity for every model user.

EMF acquired a similar solution when generic types where supported, necessitating the contained EGenericType rag bag when a rich type declaration is required rather the reference for a legacy simple type. The approach has impressive backward compatibility but is a bit of a mess.

The include file/library approach can be good for built-ins but fails for anonymous/on-the-fly locals.

IMHO a better solution is to only model the not-contained reference and have some flexibility over the definition; a normal internal primary declaration, an included primary declaration , or a secondary dustbin. In Eclipse OCL, the problem with hosting synthetic types such as Set<String> is solved by an Orphanage; a hidden shared Package that can own the potentially shared copy of whatever on-the-fly types (and ...) are required.

In Xtext, the dual contained / not-contained lists creates an additional interleaving problem for the serializer if the ordering matters.

Regards

Ed Willink
Re: Default Cross-References [message #1847105 is a reply to message #1847083] Thu, 14 October 2021 19:22 Go to previous message
Camden Blake is currently offline Camden BlakeFriend
Messages: 2
Registered: September 2021
Junior Member
Thank you for your responses, Christian and Ed.
I currently implemented the first method that Christian mentioned

material+=MaterialKind

MaterialKind: PredefMaterial | MaterialReference;
PredefMaterial: decl=VoidMaterial;
MaterialReference: x=[Material];

and this seems to be working. The language server that is generated now accepts the void material in the lists.
I do not know if this has any down stream ramifications with the serialization of the files, as I have not gotten that far with my work.
If there is a problem later, I will revisit this topic and post what happened and what I did to alter the grammar files/project.

Once again, thank you very much for your help!
Previous Topic:User defined functions with builtin functions
Next Topic:Scoping Performance
Goto Forum:
  


Current Time: Wed Dec 01 13:45:21 GMT 2021

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

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

Back to the top