langium icon indicating copy to clipboard operation
langium copied to clipboard

Using Imported Grammar Rules

Open msujew opened this issue 3 years ago • 2 comments

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:

image

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

image

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.

msujew avatar Jun 14 '22 09:06 msujew

@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.

msujew avatar Jun 14 '22 09:06 msujew

See also #526 about normalizing relative paths.

spoenemann avatar Jun 14 '22 13:06 spoenemann

This has been resolved with https://github.com/langium/langium/pull/763.

msujew avatar May 22 '23 06:05 msujew