Creating a new structure language

Hi,

I'm trying to create new languages in MPS that can be used instead of the core languages (found in jetbrains.mps.lang.*).

At the moment I have created a simple replacement for the structure language that allows for defining concepts. The language has a concept called Type that extends ConceptDeclaration, and another concept, Attribute, for defining properties of the Type. The Type concept seems to be working, but I have not found a way for my Attribute to be used instead of the PropertyDeclaration that is defined in MPS' AbstractConceptDeclaration.

If I define a concept with a property using my own structure language I end up with an error on the property: "Error: property 'name' is already declared in null". The error seems to originate from check_PropertyDeclaration that is part of jetbrains.mps.lang.structure's typesystem. If I have a collection of PropertyDeclaration in my structure language, how do I actually turn them into properties in the languages I define using my language?

Also, I wanted to experiment using the structure language that is found in MPS, but have not found any way to do this. All of the core languages seems to be read-only, and I haven't found a way to copy languages. Is there a way to copy languages in MPS?

Any tips on how to proceed are very much appreciated. Thanks!

Example project: MyBaseLanguages.zip (190KB)
1 comment
If you right click -> Go to rule which caused error you see that the checking rule check_PropertyDeclaration caused the error. It checks if the property is already declared. findPropertyDeclaration returns null because you use your own implementation of the attributes. Null is not your attribute and therefore the error is triggered. You can override this rule with your own:
checking rule AttributeDeclaration {         
  applicable for concept = Attribute as prop 
  overrides true              

  do {         
    // property overriding is banned 
if (prop.name == null) { return; } 
node<AbstractConceptDeclaration> concept = prop.ancestor<concept = AbstractConceptDeclaration>; 
node<PropertyDeclaration> propInConcept = concept.findPropertyDeclaration(prop.name); 
if (propInConcept != null && prop != propInConcept) { 
  error "property '" + prop.name + "' is already declared in " + propInConcept.ancestor<concept = AbstractConceptDeclaration>.name -> prop; 
  return; 
} 
// check constant names generated in adapters 
string name = NameUtil.toConstantName(prop.name); 
node<PropertyDeclaration> node = concept.getPropertyDeclarations().findFirst({~it => it != prop && name :eq: NameUtil.toConstantName(it.name); }); 
if (node.isNotNull) { 
  error "similar property '" + node.name + "' is declared in " + node.ancestor<concept = AbstractConceptDeclaration>.name -> prop; 
}
  }            
}              
prettyPrint();
Just only have to set override to true and make a null check.
Bear in mind that this approach only removes the error. If you want to check if the property is already declared you have to somehow write a correct findPropertyDeclaration method for your attributes.
0

Please sign in to leave a comment.