TypeFox / xtext2langium

A tool for migrating an Xtext language to Langium
https://www.typefox.io/blog/xtext-to-langium
MIT License
7 stars 1 forks source link

Generating dependent grammars generates type files that aren't generated by the dependency itself #3

Closed steve-hickman-epistimis closed 1 year ago

steve-hickman-epistimis commented 1 year ago

I have several XText grammars with dependencies as follows:

grammar com.epistimis.privacy.Privacy with com.epistimis.face.Face
grammar com.epistimis.face.Face with com.epistimis.uddl.Uddl
grammar com.epistimis.uddl.Uddl with org.eclipse.xtext.common.Terminals

When I generate from the Privacy grammar, I get the following files:

Privacy.langium
Face.langium
Face-types.langium
Uddl.langium
Uddl-types.langium
Terminals.langium

However, when I generate from the Uddl grammar, I get only

Uddl.langium

It isn't clear why this inconsistency exists.

Also - it appears that the

import 'Uddl-types'

in Face.langium results in the following error:

Inferred and declared versions of type 'ConceptualView' both have to be interfaces or unions

ConceptualView is defined in my Uddl.xtext grammar as:

UddlElement:
    DataModel |
    ConceptualDataModel | LogicalDataModel | PlatformDataModel|
    ConceptualElement|
    LogicalElement |
    PlatformElement
;
....
ConceptualElement:
    ConceptualDomain |
    ConceptualBasisEntity |
    ConceptualComposableElement |
    ConceptualView
;
....

ConceptualView:
    ConceptualQuery |
    ConceptualCompositeQuery
;

ConceptualQuery:
    'cq' name=ID (description=STRING)? '{'
        'spec:' specification=STRING
    '};'
;

ConceptualCompositeQuery:
    'ccq' name=ID (description=STRING)? '{'
        isUnion?='isUnion'
        composition+=ConceptualQueryComposition
        (composition+=ConceptualQueryComposition)+
    '};'
;

ConceptualQueryComposition:
    type=[ConceptualView|QN] rolename=ID ';'
;

Uddl.langium contains:

ConceptualView infers ConceptualView:
    ConceptualQuery | ConceptualCompositeQuery 
;

ConceptualQuery infers ConceptualQuery:
    'cq' name=ID  (description=STRING )? '{' 'spec:' specification=STRING  '};'  
;

ConceptualCompositeQuery infers ConceptualCompositeQuery:
    'ccq' name=ID  (description=STRING )? '{' isUnion?='isUnion'  composition+=ConceptualQueryComposition  (composition+=ConceptualQueryComposition )+ '};'  
;

ConceptualQueryComposition infers ConceptualQueryComposition:
    ^type=[ConceptualView:QN ] rolename=ID  ';'  
;

Uddl-types.langium contains:


interface ConceptualView extends ConceptualElement {
}

interface ConceptualElement extends UddlElement {
}

interface UddlElement {
    name?: string
    description?: string
}

Removing import 'Uddl-types' from Face.langium appears to correct that problem.

dhuebner commented 1 year ago

@steve-hickman-epistimis Thank you for reporting. Grammar Mixins are not very well supported in Xtext2Langium, so I'am very glad to see your feedback here!

However, when I generate from the Uddl grammar, I get only Uddl.langium

I would expect at least to see Terminals.langium. Hard to say what is going on without be able to see your project setup.

in Face.langium results in the following error: Inferred and declared versions of type 'ConceptualView' both have to be interfaces or unions

That is a know validation issue in Langium. However ConceptualView infers ConceptualView: should be ConceptualView returns ConceptualView:, then import 'Uddl-types' should work.

You are not using generated ecore models, right? Are you using Xcore or Genmodel? Is it possible to look into you Languages setup? Or maybe you can create a small reproducible example and share it?

steve-hickman-epistimis commented 1 year ago

I am using generated ecore - via Genmodel. The Language section from the MWE2 file is:

        language = StandardLanguage {
            name = "com.epistimis.uddl.Uddl"
            fileExtensions = "uddl"

            fragment = io.typefox.xtext2langium.Xtext2LangiumFragment {
                outputPath = './langium'
            }
            // rename refactoring
            fragment = refactoring.RefactorElementNameFragment2 {}
            fragment = org.eclipse.xtext.xtext.generator.ui.codemining.CodeMiningFragment {}

            serializer = {
                generateStub = false
            }
            validator = {
                composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
                // Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage
                generateDeprecationValidation = true
                generateStub = true
            }
            formatter = {
                generateStub = true
                generateXtendStub = true
            }
            generator = {
                generateXtendStub = true
                generateJavaMain = true
            }
            junitSupport = {
                junitVersion = "5"
            }
            fileWizard = {
                generate = true
            }
            projectWizard = {
                generate = true
            }
        }

I am planning to FOSS the repo this weekend if all goes well so you'll be able to see the whole thing at that point. Just gotta clean it up, add licensing, etc. first.

steve-hickman-epistimis commented 1 year ago

See the public repos here: https://github.com/Epistimis

dhuebner commented 1 year ago

@steve-hickman-epistimis Great, thanks! I will try it out this week

dhuebner commented 1 year ago

@steve-hickman-epistimis Imported metamodels, even if they were generated in super language, were treated as referenced metamodels which leads to the behavior you described. In your projects there should be any *.xyz-types files as they are all inferred. I solved the problem in master. Will try to release a new version today.