Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » uniqueness check restricted to certain (model) resources
uniqueness check restricted to certain (model) resources [message #1110763] Tue, 17 September 2013 09:53 Go to next message
Lars Martin is currently offline Lars MartinFriend
Messages: 24
Registered: July 2009
Junior Member
Here is the relevant portion of my sample dsl.

Variable:
   name=ID '=' expression=Expression;
Expression:
    IntConstant | StringConstant | VariableRef;
IntConstant:
    value=INT;
StringConstant:
    value=STRING;
VariableRef:
    '$' variableRef=[Variable];

I've implemented a customized ImportUriGlobalScopeProvider that overwrites getImportedUris() to add builtin variables separated into two models 'default.mydsl' and 'readonly.mydsl'. The given grammar doesn't prevent the user to overwrite variables defined in 'readonly.mydsl' (same here for 'default.mydsl'). So how can I ensure that variables defined in 'readonly.mydsl' are not allowed to be overwritten:

default.mydsl:

RW=""
..

readonly.mydsl:

RO=""
...

current.mydsl (implicitly imports default.mydsl + readonly.mydsl):

NEW=""
RO=$RO
RO=""
RW="" <- assignment should not be allowed b/c RW is defined in readonly.mydsl
RW=$RO  <- assignment should not be allowed b/c RW is defined in readonly.mydsl


Could NamesAreUniqueValidator + NamesAreUniqueValidationHelper help solve this problem? But how to restrict the uniqueness constraint to elements defined in readonly.mydsl?

Regards, Lars M

[Updated on: Tue, 17 September 2013 09:55]

Report message to a moderator

Re: uniqueness check restricted to certain (model) resources [message #1110905 is a reply to message #1110763] Tue, 17 September 2013 13:39 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1159
Registered: July 2009
Senior Member
To me, the simplest approach seems to be asking the index for variables declared in readonly.mydsl and validating that those names are not used elsewhere. NamesAreUniqueValidator and Helper in their original implementation are restricted to local names. It is a matter of taste whether you put the above logic there or in the normal validator.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: uniqueness check restricted to certain (model) resources [message #1110968 is a reply to message #1110905] Tue, 17 September 2013 15:20 Go to previous message
Lars Martin is currently offline Lars MartinFriend
Messages: 24
Registered: July 2009
Junior Member
Obviously a small error slipped in my sample code (variable names RO/RW were mixed up). But I think you've got the point.

NEW=""
RW=$RW
RW=""
RO="" <- assignment should not be allowed b/c RO is defined in readonly.mydsl
RO=$RW  <- assignment should not be allowed b/c RO is defined in readonly.mydsl

I will try asking the index as suggested.

Regards, Lars M.
Previous Topic:Find references across languages?
Next Topic:GMF/xtext diagram/model creation problem
Goto Forum:
  


Current Time: Mon Nov 24 16:35:07 GMT 2014

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

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