Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generated dependent grammar selects incorrect entry rule #4

Closed
steve-hickman-epistimis opened this issue Jan 24, 2023 · 7 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@steve-hickman-epistimis

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

The Face.langium grammar is generated like this (corrected for issues 2 & 3):

grammar Face
import 'Uddl'
//import 'Uddl-types'

entry FaceElement infers FaceElement:
    ArchitectureModel | UopUoPModel | IntegrationIntegrationModel | UopElement 
;

However, Face.xtext is defined like this:

grammar com.epistimis.face.Face with com.epistimis.uddl.Uddl

generate face "http://www.epistimis.com/face/Face"

import "http://www.epistimis.com/uddl/Uddl" as uddl

	
ArchitectureModel:
	'am' name=ID description=STRING '{'
	(dm+=DataModel | um+=UopUoPModel | im+=IntegrationIntegrationModel)+
	'}'
;

FaceElement:
	ArchitectureModel |
	UopUoPModel |
	IntegrationIntegrationModel |
	UopElement
;

Note that ArchitectureModel is the entry rule for the Face.xtext grammar. It isn't even generated for the Face.langium grammar.

@dhuebner
Copy link
Member

dhuebner commented Feb 3, 2023

@steve-hickman-epistimis

Note that ArchitectureModel is the entry rule for the Face.xtext grammar. It isn't even generated for the Face.langium grammar.

Is ArchitectureModel overridden in com.epistimis.privacy.Privacy? If so then this ParserRule was removed from Face.langium as otherwise Langium would report in error like: A rule with the name 'ArchitectureModel' already exists in an imported grammar

I think it would be a nice fragment option to force-generate overridden rules in super grammars.

@dhuebner dhuebner added the enhancement New feature or request label Feb 3, 2023
@dhuebner dhuebner self-assigned this Feb 3, 2023
@steve-hickman-epistimis
Copy link
Author

Yes, ArchitectureModel is overridden in com.epistimis.privacy.Privacy

@dhuebner
Copy link
Member

@steve-hickman-epistimis
Langium doesn't support overriding rules from super grammar. You need to refactor your grammar, for example using parser rule parameters to control you super grammar rule.

I think it would be better to just generate duplicates to see the errors reported by Langium. See also #7

@steve-hickman-epistimis
Copy link
Author

The challenge there is the usability of the net result. The base rules are defined in a published standard - so I don't have much room for modifications there - and changes to remove the overriding rules could make the net result less user friendly.

@dhuebner
Copy link
Member

The base rules are defined in a published standard - so I don't have much room for modifications there

Currently there is no way to directly override a super grammar rule.

and changes to remove the overriding rules could make the net result less user friendly.

I agree, I will set removing overridden rules to false by default.

@dhuebner
Copy link
Member

By default overridden rules will not be removed, but you will see an error in the sub grammar and need to resolve it.

@dhuebner
Copy link
Member

@steve-hickman-epistimis
I just published version 0.4.0, please try it out. Before starting mwe2 workflow remove or move files in ./langium first to have a clean state.
It could be that you need to import transitiv grammar imports like e.g. terminals.langium by hand. I'm not sure it is a bug in Langium or expected...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants