Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Auto-Completion cross-reference from a non-xtext model
Auto-Completion cross-reference from a non-xtext model [message #1809571] Thu, 18 July 2019 10:40 Go to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Hello everybody, first i need to say i'm a bit of a newbie in DSLs and especially in Xtext.

So here's the problem:
I have a working xtext model for a type of file *.it. What i need to deal with is these statement of the whole grammar:
AddStatement: 'add' addName=package 'for' fields=FieldList;
.

or
data: package '.' field

It is used to handle these .it files for the statements like this one :

add  Package for
fieldName1= 'something',
fieldName2= 'otherValue',
;





Now, i have a file in the same project a uniaue file of *.data which is "similar" to a CSV file:



XX
{
1, someFieldDescription, xxx
+
2, someFieldDescription, yyy
+
}


YY
{
1, someFieldDescription, aaa
+
2, someFieldDescription, zzz
+
}

.....



So the thing is that i would like to have an auto-completion that lists as an autocompletion all the packages of .data file (ex : XX and YY) and also the inner fields of each packages (ex: xxx and yyy for XX).

if "data" is parsed it could also show the packages of the file then " . " and after the corresponding fields.

Do you have any idea how i could achieve this ?
Re: Auto-Completion cross-reference from a non-xtext model [message #1809643 is a reply to message #1809571] Fri, 19 July 2019 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi, why not having another dsl for the data files? then it would work ootb with cross references.
https://www.dietrich-it.de/xtext/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl.html


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809729 is a reply to message #1809643] Mon, 22 July 2019 07:52 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
I did follow your tutorial for this, i tried using another dsl for this file, but, i can't figure out how to link my unique .data file so that it is "stored" by default when using my .it file. Maybe i don't understabd how it really works behind but i get lots of : "Couldn't resolve reference to Package 'XXX' "
Re: Auto-Completion cross-reference from a non-xtext model [message #1809732 is a reply to message #1809729] Mon, 22 July 2019 07:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
please give more context of what you did

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809734 is a reply to message #1809732] Mon, 22 July 2019 08:33 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
I have another DSL of this kind right now :

grammar org.xtext.data.Data with org.eclipse.xtext.common.Terminals

generate data "http://www.xtext.org/data/Data"


data:
packages+=Package+;



Package:
	name=packageName  '{'
	field+=[Fields]+
	'}'
	
;



Fields:
	{Fields} numField , description,  name=field
	'+'?
;




field:CAPSID;


description:ID+;

numField:INT;

packageName: CAPSID;


The thing is that this DSL would only parse one exact file.

I added dependencies like you shew in the tutorial.

The thing is that i want to access to the rule "packageName" for my original "Package" rule and its corresponding fields.

Now i get the error : "Couldn't resolver reference to Package 'XXX' " for something like

add XXX



On the other hand, when i refrence like pack=[data::Package] in the main DSL, it references to a RULE_ID whereas it is a RULE_CAPSID in my data language. It gives me then some errrors like it is expecting a rule_ID sometime


Tell me if that was enough for you to understand the context

[Updated on: Mon, 22 July 2019 08:56]

Report message to a moderator

Re: Auto-Completion cross-reference from a non-xtext model [message #1809740 is a reply to message #1809734] Mon, 22 July 2019 09:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i still dont get the point.

are you talking about the data dsl oder the add/main dsl.

pack=[data::Package] is short for pack=[data::Package|ID] so maybe you want pack=[data::Package|SomeOtherRule] or pack=[data::Package|CAPSID] (dont now all in your dsl)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809742 is a reply to message #1809740] Mon, 22 July 2019 09:17 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
In my main DSL that deals yith .IT files, i want to use the addStatement by typing 'add <package>' in my parsed file (with package as the name attribute of the [data::Package] rule, the latter, needs to check and provide a list of all the packages in my unique .data file that is parsed by the Data DSL).


To be more precise, i'd like to know how can i make my secondary ("data") parser work dynamically with my database file.
So that, when i need to use a Package name in my main xtext project runtime, it parses and content assists thanks to the name attribute of the Package rule of my secondary xtext DSL of one of the packages written in a unique data file

Sorry i might be a bit unclear since i don't have much knowledge in DSLs and my english level is not perfect


For the moment i get lots of "Couldn't resolve reference to Package 'XXX' " when parsing .it (main DSL).

EDIT: Your explaination for the CAPSID is working thank you

[Updated on: Tue, 23 July 2019 10:55]

Report message to a moderator

Re: Auto-Completion cross-reference from a non-xtext model [message #1809784 is a reply to message #1809742] Tue, 23 July 2019 12:01 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Actually i think that my problem could be fixed with this answer : https://www.eclipse.org/forums/index.php?t=msg&th=209411&goto=671493&#msg_671493Quote:
Hi Ulli,

Welcome to the Xtext community!

See answers inline.

On 5/17/11 2:02 PM, Ulli Hafner wrote:
> Hi,
>
> I'm trying to write a xtext grammar that uses some predefined instances that
> are computed dynamically. Where is the best way to load these instances so
> that these instances are available when pressing CTRL-SPACE?
>
> My grammar is quite simple:
> ----------------
> grammar de.faktorlogik.ips.dsl.Rules with org.eclipse.xtext.common.Terminals
>
> generate rules "http://www.faktorlogik.de/ips/dsl/Rules"
>
> Model:
> rule=Rule;
>
> Concept:
> 'concept' name=ID;
>
> Property:
> 'property' name=ID;
>
> Rule:
> concept=[Concept] 'and' restriction=Restriction;
>
> Restriction:
> '(' property=[Property] 'some' concept=[Concept] ')';
> ----------------------
>
> Concept and Property instances are actually not defined using the editor, they
> are created dynamically. I only defined them in the grammar in order to use
> them as references in the Rule definition.
>

I would consider maintaining the Ecore model by hand as the parser rules for
Concept and Property are not used and thus rather confusing.

> My Editor should basically parse the following input:
> ----------------------
> concept1 and (property1 some concept2)
> ----------------------
>
> The elements concept1, property1, and concept2 are dynamically computed.
>
> Currently I've extended from AbstractDeclarativeScopeProvider and instantiate
> the objects dynamically from within methods
>
> public IScope scope_Concept(Model model, EReference reference) {
> return new MapBasedScope(computeAvailableConcepts());
> }
>
> public IScope scope_Property(Model model, EReference reference) {
> return new MapBasedScope(computeAvailableProperties())
> }
>
> This approach works for the context assist, however I'm always getting the
> following validation error:
>
> The feature 'property' of
> 'de.faktorlogik.ips.dsl.rules.impl.RestrictionImpl@1fdbab5 {platform:/resource/hello.world/src/rules.flips#//@rule/@res triction}'
> contains a dangling reference
> 'de.faktorlogik.ips.dsl.rules.impl.PropertyImpl@a484c7{#//}' rules.flips
> /hello.world/src line: 1 /hello.world/src/rules.flips Xtext Check (fast)
>
> Am I doing something fundamentally wrong? Or where would be the best place to
> instantiate those predefined instances? (Currently the scope methods are
> invoked on every CTRL-SPACE, maybe a method that would be invoked only once
> would be sufficient?
>

The problem is that your Concept and Property instances are not contained by
any EMF resource. And there is a standard EMF validation checking against
references to such non-contained objects.

I would consider the following approaches (in the given order) to solve the
problem:

1. Presumably the Concept and Property instances are created based on some
other external, persisted data. If possible and feasible it would make sense
to implement an IResourceServiceProvider (see also
GenericResourceServiceProvider) for this external content. That way you could
add the Concept and Property instances to the Xtext index and link against that.

2. On the fly generate an EMF Resource containing the Concepts and Properties
and add it to the ResourceSet which contains your model. You could do this
dynamically in the ScopeProvider or possibly up front in the Linker (using the
afterModelLinked() hook).

3. Add the Concept and Property instances as additional top-level objects to
the XtextResource containing your model. This however makes most sense if
these instances are derived from data in your model. (Xbase based languages
use this approach to store derived Java types.)

4. Disable the EMF validation. You can do this by binding a
@Named(CompositeEValidator.USE_EOBJECT_VALIDATOR) Boolean to "false". You
could also be more specific and bind CompositeEValidator to a custom subclass
where you override initDefaults() to add an EObjectValidator which in
validate_EveryReferenceIsContained() returns "true". But I wouldn't really
recommend this approach if you don't have very good reasons.

Hope that helps,

--knut


But i didn't manage to get how to do it, is it still the good way to do what i need ?

[Updated on: Tue, 23 July 2019 12:02]

Report message to a moderator

Re: Auto-Completion cross-reference from a non-xtext model [message #1809796 is a reply to message #1809784] Tue, 23 July 2019 13:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
sorry i cannot follow you. what is wrong with that you have now?
and yes you can always do some magic in scoping (let objects fall from the sky there)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809801 is a reply to message #1809796] Tue, 23 July 2019 14:29 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Well in the end the problem is that i don't get how to make my database file ( which is almost a CSV file) a "model" for the parsing content assistant of my Packages of the main DSL ( as if it was the list of the packages possible) .

So far i tried to create a new xtext DSL only to parse this file and only ended up with "Couldn't resolve reference to Package 'XXX' " when trying to cross-reference through the new xText Parser for the data file. When i launch Eclipse application, both my .it (main DSL) files and .data file are open in my runtime Eclipse, but it is like my .it files doesn't even find my data file in my opinion and thus don't find any reference.

So the thing is that since i'm not allowed to use the usual importsURI because of external constraints, i need to find a way to make this data file . So, now i don't really know how to make my main parser check that each package present is available in my data file.

[Updated on: Tue, 23 July 2019 14:30]

Report message to a moderator

Re: Auto-Completion cross-reference from a non-xtext model [message #1809802 is a reply to message #1809801] Tue, 23 July 2019 14:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the question is:

why do you get this message. you do something wrong:

- how does the relevant grammar parts look like
- does the Package declaration occurr in the Navigate -> open model element dialog.
- is the file extension for the definition dsl correct?
- do you have build automatically on
- did you define the second dsl in the same project than the first?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809829 is a reply to message #1809802] Wed, 24 July 2019 07:45 Go to previous messageGo to next message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
Thank you very much for your help, i'll show you the real grammar, because it's a profesional project os i didn't want to show to much but nevermind ^^

Quote:
- how does the relevant grammar parts look like


For my main DSL i have :
grammar org.xtext.it.IT with org.eclipse.xtext.common.Terminals

generate iT "http://www.xtext.org/it/IT"

import "http://www.xtext.org/metalist/Metalist" as ML
...
AddStatement: {AddOccStatement} ('ADD') addPack=[ML::Package|MAJID] (('PARENT') parentPack=[ML::Package])?;
...

with a
import "http://www.xtext.org/metalist/Metalist" as ML
and dependencies necessary of the following Metalist (my secondary DSL)

My secondary DSL :
grammar org.xtext.metalist.Metalist with org.eclipse.xtext.common.Terminals

generate metalist "http://www.xtext.org/metalist/Metalist"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


METALIST:
packages+=Package+;



Package:
	'_¡' name=packageName 
	nb=nbField '®'
	(fields+=Fields)+
	'®'
	
;



Fields:
	{Fields} numField '¡' description* '¡' champ1? '¡'champ2? '¡' name=field? '¡' champ3*
	'×'?
;
packageName: MAJID;
field:MAJID;

terminal MAJID: '^'?('\\'|'A'..'Z'|'_')('A'..'Z'|'_'|'0'..'9')*;

@Override
terminal INT returns ecore::EInt:
	('-')?('0'..'9')*;

...


The first one works with all the .it files of my project and the second one should be with this alone file data.metalist (That's the right extension), that looks like this :

_¡PACK0
3®
0¡HGF¡¡0¡¡3
×
1¡fds¡I¡2¡GBCV¡35
×
2¡zou¡I¡8¡GDFS¡

®

_¡PACK1
5®
-3¡fsdf¡I¡2¡RFIELD¡35
×
0¡gdfgdf¡¡0¡¡XFIELD
×
1¡xcv¡S¡2¡HFIELD¡P
×
2¡qwee¡I¡0¡QFIELD¡
×
3¡bvcx¡I¡0¡SIR_NOOE¡

®


Quote:
- does the Package declaration occurr in the Navigate -> open model element dialog.


I do have the Package declaration that leads me to my data.metalist genmodel where it is present.
Quote:
- is the file extension for the definition dsl correct?


Yes it is because if i open my data.metalist file, it is parsed correctly
Quote:
- - do you have build automatically on

Yes it is both activated on my XTEXTs editor and the runtime

Quote:
- did you define the second dsl in the same project than the first?


Yes they are both in the same project whether on the editor or the runtime.


I'd like to clarify that the errors i get are present in the runtime, not while editing the DSLs, there i have 0 errors/warnings.

It's like everything is working well, except that in the runtime, my IT (primary) dsl doesn't want to look into this data.metalist file for the packages




Re: Auto-Completion cross-reference from a non-xtext model [message #1809830 is a reply to message #1809829] Wed, 24 July 2019 07:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
> I do have the Package declaration that leads me to my data.metalist genmodel where it is present.
no: i mean in the runtime eclipse. where your model files are. is there the package in the open model dialog => it should lead to xxxx.mydsl/yourdsl/metalist
> Yes it is because if i open my data.metalist file, it is parsed correctly
the editor is more generous when it comes to casing in file extensions than the builder is


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-Completion cross-reference from a non-xtext model [message #1809832 is a reply to message #1809830] Wed, 24 July 2019 09:09 Go to previous message
Martin BREUNEVAL is currently offline Martin BREUNEVALFriend
Messages: 17
Registered: July 2019
Junior Member
All right, i finally got this working, i'm almost sure there was an issue with my project settings that didn't consider both DSLs as the same project, you got me on the right way, thank you very much!
Previous Topic:Throw error in generator
Next Topic:Indent block of statements
Goto Forum:
  


Current Time: Fri Mar 29 00:55:04 GMT 2024

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

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

Back to the top