I am currently building an IDE for ATS (www.ats-lang.org). I got into some problems dealing with scope. The documentation is a little bit too advanced for me to understand this topic. The following is some of my guess. Please correct me if I am wrong. For clarity, I use the following sample grammar for language "Myscope".
=========================
grammar org.xtext.example.mydsl.MyScope with org.eclipse.xtext.common.Terminals
generate myScope "http://www.xtext.org/example/mydsl/MyScope"
Program:
body
;
body: {body}
(mscope+=scope
| mdef+=def
)*
;
scope: {scope}'scope' mbody=body 'end';
def: name=ID '=' (mint=INT | mval=[def | ID]);
==========================
The corresponding source code would be something like this
===========================
x = 3
scope
x = 4
end
z = x
============================
The "x" in "z = x" refers to the "x" in "x = 4" which is actually within the scope and this is not what I want.
Once I modify the grammar into the following (simply by add name to scope)
==============================
grammar org.xtext.example.mydsl.MyScope with org.eclipse.xtext.common.Terminals
generate myScope "http://www.xtext.org/example/mydsl/MyScope"
Program:
body
;
body: {body}
(mscope+=scope
| mdef+=def
)*
;
scope: {scope}'scope' name=ID mbody=body 'end';
def: name=ID '=' (mint=INT | mval=[def | ID]);
================================
The cross-reference works correctly. So I think the problem is related to the concept "qualified name". The solution coming up in my mind is to create my own QualifiedNameProvider which extends DefaultDeclarativeQualifiedNameProvider so that element inside scope can have a longer qualified name. Am I on the right track?
Continue on this idea, since the "scope" in my language really doesn't have a name, what's the best solution for assignning names to element inside the scope? Any suggestion is highly appreciated. Thanks a lot.