Auto-Completion cross-reference from a non-xtext model [message #1809571] |
Thu, 18 July 2019 10:40 |
Martin BREUNEVAL 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
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 #1809734 is a reply to message #1809732] |
Mon, 22 July 2019 08:33 |
Martin BREUNEVAL 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
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 #1809742 is a reply to message #1809740] |
Mon, 22 July 2019 09:17 |
Martin BREUNEVAL 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 |
Martin BREUNEVAL 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 #1809801 is a reply to message #1809796] |
Tue, 23 July 2019 14:29 |
Martin BREUNEVAL 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 #1809830 is a reply to message #1809829] |
Wed, 24 July 2019 07:54 |
|
> 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04722 seconds