|
|
|
|
Re: Inheritance in XText [message #677100 is a reply to message #676873] |
Tue, 07 June 2011 15:14 |
Simon Stratmann Messages: 27 Registered: February 2011 |
Junior Member |
|
|
Christian,
thanks for your help! I realize not posting the grammar might make the problem somewhat abstract, but having a pretty complex grammar with more than 1200 lines I thought posting it or even parts of it might confuse more than help. The real grammar is pretty much what you deducted from my example, but I refer to the variable by a FQN. SO I tried your approach with something like this:
Signal:
"signal" name=IDENTIFIER;
QualifiedName:
IDENTIFIER("."IDENTIFIER);
Usage: "use" signal=[Signal|QualifiedName] ("." attr=[Attribute|IDENTIFIER])? ";";
At the same place there can either be a referrance like "use work.a" or "a" (with an ImportScope) but also like "work.a.attribute1".
Because of the QualifiedName-Rule when looking for candidates for the Usage target it will look for something with the QualifiedName "work.a.attribute1" instead of "work.a" and then something with the simple name "attribute1".
Part of my grammar:
refToSimpleName:
refersTo=[Referrable|QualifiedName]("." rt=record_type)?;
QualifiedName:
IDENTIFIER ("." IDENTIFIER)*;
record_type:
name=IDENTIFIER;
record_type_definition:
"record" ED+=record_type_list+ "end" "record" (ends_record=refToSimpleName)?;
record_type_list :
records+=record_type ("," records+=record_type)* ":" ESD=element_subtype_definition ";";
variable_declaration:
("shared")? "variable" variables+=variable_name ("," variables+=variable_name)* ":"
variable_subtype=subtype_indication (":=" E=expression)? ";";
variable_name:
name=IDENTIFIER;
Referrable:
variable_name;
[Updated on: Tue, 07 June 2011 15:16] Report message to a moderator
|
|
|
|
|
Re: Inheritance in XText [message #677156 is a reply to message #677135] |
Tue, 07 June 2011 18:12 |
|
Hi,
what i mean is that the grammar (modified to Usage: "use" signal=[Signal|FQN] ("." attr=[Attribute])? ";"; is ambigous. so what you have here is i want to refernce to a signal or to an attribute (qualified by the signal)
so my grammar works when changed to (similar as your refferable)
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
typs+=Type*
signals+=Signal*
usages+=Usage*
;
FQN: ID ("." ID)*;
enum Datatype : string | integer | boolean;
Type:
"type" name=ID "is"
attributes+=Attribute*
"end" "type" ";";
Attribute: id=ID ":" type=Datatype ";";
Signal: "signal" name=FQN ":" type=[Type] ";";
SignalOrAttribute : Signal | Attribute;
Usage: "use" {Usage} ref=[SignalOrAttribute|FQN] ";";
and fixing the local scoping
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
@Inject
IQualifiedNameProvider nameProvider;
public IScope scope_Usage_ref(Usage u, EReference r) {
List<IEObjectDescription> objects = new ArrayList<IEObjectDescription>();
Model m = EcoreUtil2.getContainerOfType(u, Model.class);
for (Signal s : m.getSignals()) {
objects.add(EObjectDescription.create(nameProvider.getQualifiedName(s), s));
for (Attribute a : s.getType().getAttributes()) {
objects.add(EObjectDescription.create(nameProvider.getQualifiedName(s) + "." + a.getId(), a));
}
}
return new SimpleScope(IScope.NULLSCOPE, objects);
}
}
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.04610 seconds