JetBrains / MPS-extensions

MPS-extensions aims to ease language development within MPS.
https://jetbrains.github.io/MPS-extensions/
Apache License 2.0
80 stars 47 forks source link

com.mbeddr.mpsutil.blutil: Add a new ifInstanceOf statement that supports else if and else branches #764

Closed alexanderpann closed 5 months ago

alexanderpann commented 5 months ago

Example:

test withElseIfAndElse { 
  node<ClassConcept> node = new node<ClassConcept>(); 
  int result; 
  ifInstanceOf (node is ClassConcept cls) { 
    result = cls.isNotNull ? 0 : 1; 

  } else ifInstanceOf (node is AbstractCatchClause acc) { 
    result = acc.isNotNull ? 2 : 3; 
  } else ifInstanceOf (node is AbstractClassifierReference acr) { 
    result = acr.isNotNull ? 5 : 6; 
  } else { 
    result = 7; 
  } 

  assert 0 equals result ; 
}
alexanderpann commented 5 months ago

The naming convention comes from IfInstanceOfStatement and maybe the Clause prefix is a bit confusing. I am keeping it that way, I think it is not that important.