Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Case insensitive scope resolution
Case insensitive scope resolution [message #722765] Tue, 06 September 2011 16:33 Go to next message
amey.par is currently offline amey.parFriend
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

Re: Case insensitive scope resolution [message #722772 is a reply to message #722765] Tue, 06 September 2011 16:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the question is: how do you create the local scope for the vars? the place you call getFields
guess you have to do something like

new SimpleScope(Scopes.scopeFor(vars),true)


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Case insensitive scope resolution [message #722774 is a reply to message #722772] Tue, 06 September 2011 17:05 Go to previous messageGo to next message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Hi Christian,

Thanks, that worked! (Well, with a small modification)

new SimpleScope(Scopes.scopedElementsFor(vars, true);


So does case-insensitive scope resolution work only for local/SimpleScope scopes? Or was it returning a fully qualified scope (if that's what it's called) before?

Thanks,
Amey
Re: Case insensitive scope resolution [message #722777 is a reply to message #722774] Tue, 06 September 2011 17:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No,

before you configured global scoping. but if you create a case sensitive (local) scope explicitly e.g. by using Scopes.scopeFor(List<EObject>) it is your fault/will to have a case sensitive scope Wink

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Case insensitive scope resolution [message #722784 is a reply to message #722777] Tue, 06 September 2011 17:29 Go to previous message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Ah, got it, thanks Smile
Previous Topic:Using xText content assist from an proprietary plugin
Next Topic:(no subject)
Goto Forum:
  


Current Time: Fri Apr 19 04:30:22 GMT 2024

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

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

Back to the top