eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
754 stars 68 forks source link

Using Imported Grammar Rules #539

Closed msujew closed 1 year ago

msujew commented 2 years ago

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](https://user-images.githubusercontent.com/2790749/172707209-62e69917-730c-4225-b625-fb1700d35c50.png) But, as you can see, the grammar is imported, and the `BehaviorDef` rule does exist and is valid: ![image](https://user-images.githubusercontent.com/2790749/172707490-6847ef64-be8b-45ea-80d6-be3d6600041b.png) 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 commented 2 years ago

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

spoenemann commented 2 years ago

See also #526 about normalizing relative paths.

msujew commented 1 year ago

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