Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to insert non-existing fields into the scope
How to insert non-existing fields into the scope [message #1032571] Wed, 03 April 2013 06:51 Go to next message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Hi all,
I am interested in defining a DSL, whose expressions use existing class' fields, as well as fields that are not declared in any class (yet). The reason for doing so is that those "non-existing" fields are to be declared by generated AspectJ aspects (using Inter Type Declarations, see http://www.eclipse.org/aspectj/doc/next/progguide/language-interType.html).

As an example, consider the following DSL code:

Logger my.MyClass {
  log when (sum > 0 && sum < 1000)
  log when (_sum != sum)
}


The field sum is declared in the class MyClass, and is inserted into the scope in the regular way (ScopeProvider). However, the field _sum (note the leading underscore) is not defined in the class during the parsing of the DSL code, and as a result a compilation error is shown. I would like to remove that error for all identifiers starting with an underscore.

Is there a way to insert such identifiers into the scope although they are not defined anywhere?

Thanks,
Oren
Re: How to insert non-existing fields into the scope [message #1033354 is a reply to message #1032571] Thu, 04 April 2013 06:39 Go to previous messageGo to next message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Perhaps a better title for this question would be "How to insert arbitrary identifiers into the scope?". Hope that would make the question more clear...
Re: How to insert non-existing fields into the scope [message #1033426 is a reply to message #1033354] Thu, 04 April 2013 08:09 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Am 04.04.13 08:39, schrieb Oren Mishali:
> Perhaps a better title for this question would be "How to insert
> arbitrary identifiers into the scope?". Hope that would make the
> question more clear...
>

Provide a custom implemenation of IScope that returns a meaningful
description when asked for something starting with an underscore. It's a
fairly small interface, especially if you inherit from
org.eclipse.xtext.scoping.impl.AbstractScope. You'd only have to return
an empty collection from #getAllLocalElements() and a proper result from
#getLocalElementsByName(QualifiedName)

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Issue generating a DSL grammar
Next Topic:DSLs targetting non-Java languages
Goto Forum:
  


Current Time: Thu Apr 25 10:44:47 GMT 2024

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

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

Back to the top