3

I'd like to define a language with different elements that shall be contained into different kind of files though linked (i.e. similarly to C++ with .cpp and .h files). Is grammar mixin the right way to do that? If so how should I proceed?

Andrea Sindico
  • 7,358
  • 6
  • 47
  • 84

1 Answers1

0

Different elements in different file kinds sounds like a use case for Grammar Mixins. The base grammar should define the language concepts common for both languages, and the sub-languages would inherit from the base grammar.

Ideally create a manually written Ecore metamodel and map the concept to it (i.e. don't use 'generate').

Since 2.10, Xtext supports parser rule fragments. This means you can define certain reusable parts of rules with the 'fragment' keyword. See https://github.com/eclipse/xtext-core/blob/761ffeac7e62525be5a5473988d7f1d577298b67/org.eclipse.xtext.tests/src/org/eclipse/xtext/parser/fragments/FragmentTestLanguage.xtext.

kthoms
  • 39
  • 6