langium
langium copied to clipboard
Using Imported Grammar Rules
Discussed in https://github.com/langium/langium/discussions/532
Originally posted by ballcoach12 June 8, 2022 I have a grammar that imports rules from another grammar. My entry rule looks like this:
entry TemplateLibraryModel:
(library=TemplateLibrary |
(
globalBehaviors+=BehaviorDef*
)
)
;
The imported grammar appears to be valid, but the other grammar is showing errors in the Langium editor:

But, as you can see, the grammar is imported, and the BehaviorDef rule does exist and is valid:

I am unsure about what is causing this error. I used the editor's Quick Fix to insert the import statement, so I think the file is accessible. Is this a bug, or am I going about this import the wrong way?
** I will also note that the error in the editor goes away if I use BehaviorDef as a cross-reference instead of a grammar rule in the Xeta grammar file.
*** For reference, my overall goal here is to populate a global scope with BehaviorDef elements that are loaded from an external DSL file.
@ballcoach12 This isn't actually intended behavior, but a bug. For some reason the validation triggers even though the import exists. This only seems to happen if the import contains ... The import URI isn't normalized and creates a weird document URI. Since we check for document equality by comparing URIs, the check fails and the validation triggers. I'll look into this.
See also #526 about normalizing relative paths.
This has been resolved with https://github.com/langium/langium/pull/763.