Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » scope and qualified name(How to implement local scope?)
scope and qualified name [message #704360] Thu, 28 July 2011 14:34 Go to next message
alex.ren2006 is currently offline alex.ren2006Friend
Messages: 46
Registered: June 2011
Member
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.
Re: scope and qualified name [message #704380 is a reply to message #704360] Thu, 28 July 2011 14:52 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6495
Registered: July 2009
Senior Member
Hi,

this is what a QualifiedNameProvider is for

~Christian
Previous Topic:Scoping & "Cyclic resolution of lazy links" error
Next Topic:Invalid XML character (Unicode: 0x0) exception with xmlVersion 1.1 in Xtext2
Goto Forum:
  


Current Time: Wed Nov 26 13:25:30 GMT 2014

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

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