Case insensitive scope resolution [message #722765] |
Tue, 06 September 2011 16:33 |
amey.par Messages: 17 Registered: July 2011 |
Junior Member |
|
|
I'm writing an Xtext 2 grammar for a case-insensitive language. As such, in my MWE2 workflow, I have the following fragments:
// The antlr parser generator fragment.
fragment = parser.antlr.ex.rt.AntlrGeneratorFragment {
options = {
backtrack = true
ignoreCase = true
}
}
fragment = parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {
options = {
ignoreCase = true
}
}
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment {
ignoreCase = true
}
and I have a grammar that looks like:
VarDeclaration:
'var'
(type=[VarType]|basicType=BasicType)
varNames+=VarName ( ',' varNames+=VarName )*;
VarName:
name=ID;
VarType:
EnumDeclaration | StructDeclaration | ClassDeclaration;
References to DeclaredVariable are specified in the grammar as follows:
QualifiedIdentifier:
( ( 'class' SQUOTE parent=[ClassDecl] SQUOTE
( {Selection.receiver=current} DOT child=[DeclaredVariable] )*
) |
( parent=[DeclaredVariable]
( {Selection.receiver=current} DOT child=[DeclaredVariable] )*
)
);
I have a scope provider that extends AbstractDeclarativeScopeProvider with code that looks like:
public List<VarName> getFields(VarType varType)
{
List<VarName> fields = new LinkedList<VarName>();
if (varType instanceof StructDeclaration)
{
List<StructVarDeclaration> svDeclarations = ((StructDeclaration)varType).getStructVarDeclarations();
for (StructVarDeclaration dv: svDeclarations)
{
fields.addAll(getFields(dv));
}
}
else if (varType instanceof ClassDecl)
{
Model m = (Model)(((ClassDecl)varType).eContainer());
if (m != null)
{
List<Declaration> declarations = m.getDeclarations();
for (Declaration d: declarations)
{
fields.addAll(getFields(d));
}
}
}
else if (varType instanceof EnumDeclaration)
{
fields.addAll(((EnumDeclaration)varType).getEnumOptions());
}
return fields;
}
Also, in my runtime module I've bound:
public void configureIgnoreCaseLinking(com.google.inject.Binder binder)
{
binder.bindConstant().annotatedWith(org.eclipse.xtext.scoping.IgnoreCaseLinking.class).to(true);
}
public ICaseInsensitivityHelper bindCaseInsensitivityHelper() {
return new ICaseInsensitivityHelper() {
public boolean isIgnoreCase(EReference reference) {
return true;
}
};
}
The issue I'm having is that variables with direct cross-references (i.e. no custom scope resolution defined, for examples variables declared in the same scope) can be accessed case-insensitive-ly, so e.g.
struct Vector
{
int X, Y;
}
var Vector Vec1;
Vec1 = (0,0); //works
vec1 = (0,0); //works
works, but if I try to access variables declared in a different scope, the resolution becomes case-sensitive.
vec1.X = 0; // works
vec1.x = 0; // doesn't work
Could someone please tell me what I'm doing wrong?
Thanks,
~Amey
[Updated on: Tue, 06 September 2011 16:38] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25782 seconds