Language modularization
The goal of modularization is to separate the grammar and the interpreters of the DSLs in separate files. The scientific computing language (SCL) and the atomic and molecular modeling language (AMML) have different domains. The AMML can be regarded as a more specialized language than the SCL in direction computational chemistry and materials science. Potentially the SCL can be reused in other DSLs defined in other domains of scientific computing. Thus, if SCL
is a subset of AMML
, the grammar and the interpreter for SCL
must be still valid after removal of all files corresponding to AMML \ SCL
.
Therefore it makes sense to re-structure the grammar, the modular structure of metamodel, object and model processors, interpreter, the examples, the tests and also the packaging. This will allow easier reuse in other domains.
- Regarding extending the metamodel: http://textx.github.io/textX/3.1/multimetamodel/
- Grammar modularization: http://textx.github.io/textX/3.1/grammar/#grammar-modularization
- Language modularization (a draft with open issues): http://textx.github.io/textX/3.1/ideas/language_modularization/
Implementation (grammar)
If lang1
is part of lang2
:
File lang2.tx
:
import lang1
Rule2: 'match2' Parameter;
File lang1.tx
:
import lang2
Parameter: Rule1 | Rule2;
Rule1: 'match1';
This does not work:
File lang2_parameter.tx
:
import lang1_rules
import lang2_rules
Parameter: Rule1 | Rule2;
File lang2.tx
:
import lang2_parameter
Rule2: 'match2' Parameter;
File lang1.tx
:
import lang1_parameter
import lang
Parameter: Rule1;
Rule1: 'match1';
A probably working solution:
File lang1.tx
:
Parameter: Rule1;
Rule1: 'match1';
Variable: name = ID '=' parameter = Parameter;
File lang2.tx
:
import lang1
Lang2Parameter: Rule1 | Rule2;
Rule2: 'match2' Lang2Parameter;
Variable: name = ID '=' parameter = Lang2Parameter;
We should check whether rules from imported modules are used only if no such rule is found in current module. If this is the policy then Variable
in lang2
has a different definition as required. Another thing is to test the effect of placement of import statement.