0

Has some lang like this.

language sample.linking.SampleLang;
generate SampleLang "http://sample/linking/samplelang/v1"
Model:
    entity_node = Entity
;

Entity:
    type = ('blabla1' | 'blabla2') ':' name = ID (annotation = Annotation)? '{'
    (parts += EntityPart)*
    '}'
;

Annotation:
    'deprecated' ( '->' name = ID )?
;

//SomeOtherRools
EntityPart:
    'createNewEntity' '(' entity=STRING ')'
;

I have multiple files, which must be checked

name1.ext
blabla2:name1
{
    ...
}

name2.ext
blabla2:name2 deprecated -> name1
{
    ...
}

name3.ext
blabla1:name3
{
    createNewEntity("name2") - show warning about deprecation
    createNewEntity("name1")
}

Need to check is Entity, which I'm try to "create" from some other entity deprecated or not. Can't do it through the cross-reference, because I've must specify the name by string. How can I write checker for this situation?

@Check
def checkDeprecation(EntityPart entityPart) {
    /*???*/
}
ArchCC
  • 83
  • 9
  • 1
    can you give some more hints? what is the search scope? same file - all files? what is the search criteria? why does STRING prevent you from cross referencing (https://christiandietrich.wordpress.com/2015/03/19/xtext-and-strings-as-cross-references/) – Christian Dietrich May 30 '16 at 13:29
  • Add some edits to post...I've try to change rule EntityPart: 'createNewEntity' '(' entity=STRING ')'; to EntityPart: 'createNewEntity' '(' entity=[Entity|STRING] ')'; and it's always show "Couldn't resolve reference to Entity"(Also try to change Entity rule to use name = STRING with same result) – ArchCC May 31 '16 at 08:03
  • Please share complete grammar and sample model – Christian Dietrich May 31 '16 at 08:04
  • (p.s. i could not reproduce it by simply chaning the grammar) – Christian Dietrich May 31 '16 at 08:13
  • This is link to test project with grammar https://www.dropbox.com/s/6tef8czoquv6mi9/testGrammarProject.zip?dl=0 – ArchCC May 31 '16 at 13:39
  • This is link to test project with samples https://www.dropbox.com/s/co0htcq9yuzu58o/testProject.zip?dl=0 – ArchCC May 31 '16 at 13:40
  • the grammar project seems to contain all projects twice. i imported the stuff under parent. i imported the test project and added the missing xtext nature (editor asks if you open a mydsl file) - and i dont get any errors – Christian Dietrich May 31 '16 at 13:50

1 Answers1

1

As Christian Dietrich suggest in comment for such task EntityPart can be changed to

EntityPart:
    'createNewEntity' '(' entity=[Entity|STRING] ')'
;

and add to *validator.xtend

   @Check
   def checkDeprecation(EntityPart entityPart) {
      if(entityPart.getEntity().getAnnotation() != null) {
          var warningString = "Usage of deprecated entity";
          if(entityPart.getEntity().getAnnotation().name != null) {
               warningString = "Usage of deprecated entity, use "+entityPart.getEntity().getAnnotation().name+" instead"
          }
          warning(warningString, null);
      }
   }

Why this may not work...

For Eclipse you need:

  1. xtext project nature
  2. enabled Project - Properties - Builders - Xtext Project Puilder
  3. enabled Project - Build Automatically

For Intellj Idea you need:

  1. facet of you'r dsl lang on module
  2. work only under folders marked as source
ArchCC
  • 83
  • 9