Skip to main content



      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 05:53 Go to next message
Eclipse UserFriend
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 05:55] by Moderator

Re: uniqueness check restricted to certain (model) resources [message #1110905 is a reply to message #1110763] Tue, 17 September 2013 09:39 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: uniqueness check restricted to certain (model) resources [message #1110968 is a reply to message #1110905] Tue, 17 September 2013 11:20 Go to previous message
Eclipse UserFriend
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: Sat Jul 12 19:05:52 EDT 2025

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

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

Back to the top