Cross reference, Qualified name and scoping [message #1349676] |
Mon, 12 May 2014 05:45  |
Eclipse User |
|
|
|
I want to make cross reference using qualified name but i had some problem with it.
I want to be able to parse
Probe P1 {
11 22 33 //the content of Probe is not important
}
Condition C1 {
P1.value = 1
}
Here is an extract of the grammar
Probe :
'Probe' name=ID '{'
descr+=INT+
'}'
Condition :
'Condition' name=ID '{'
probe=[Probe] '.' met=ID '=' val=INT
'}'
Using this grammar, I can only parse 'P1 . value' and not 'P1.value' . It parse 'P1.value' as a single token. Note that the 'value' field is not defined in the language anywhere.
I tried a workaround :
Condition :
'Condition' name=ID '{'
probe=QualifiedName '=' val=INT
'}'
I don't use the cross reference directly but a qualified name. I bind it with to correct probe in the MyDslGenerator (in my generated code), check that the used probe is defined in the MyDslValidator, and add the correct auto-completion in the MyDslProposalProvider.
Is there a less hacky way to do it ?
Thanks
|
|
|
|
|
|
|
Re: Cross reference, Qualified name and scoping [message #1783666 is a reply to message #1349676] |
Thu, 15 March 2018 06:42   |
Eclipse User |
|
|
|
Hi
I have the following rule for qualified names:
QualifiedName:
((catalogName=ID '.')? schemaName=ID '.')? identifier=ID;
And I can't use it for cross-references because it's not a data rule returning EString.
Also in my language the following idnetifiers are the same: dbo.person, "dbo".person, dbo.PERSON
I think I need to transform them into a canonicial form before comparision or implement a custom comparision.
Could you suggest how to implement it?
For now I have the following scope provider:
class SQLScopeProvider implements IScopeProvider {
override getScope(EObject context, EReference reference) {
if (context instanceof ReferencesColumnConstraint) {
if (reference == SqlPackage.eINSTANCE.referencesColumnConstraint_ReferredTableName) {
val rootElement = EcoreUtil2.getRootContainer(context)
val candidates = EcoreUtil2.getAllContentsOfType(rootElement, TableDefinition)
return new SimpleScope(candidates.map[EObjectDescription.create(it.tableName.fullyQualifiedName, it)])
}
else if (reference == SqlPackage.eINSTANCE.referencesColumnConstraint_ReferredColumnNames) {
if (context.referredTableName !== null) {
val rootElement = context.referredTableName
val candidates = EcoreUtil2.getAllContentsOfType(rootElement, ColumnDefinition)
return new SimpleScope(candidates.map[EObjectDescription.create(it.name, it)])
}
}
}
}
def QualifiedName getFullyQualifiedName(TableName obj) {
if (obj.schemaName === null) {
QualifiedName.create(obj.identifier)
}
else if (obj.catalogName === null) {
QualifiedName.create(obj.schemaName, obj.identifier)
}
else {
QualifiedName.create(obj.catalogName, obj.schemaName, obj.identifier)
}
}
}
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03675 seconds