Check for duplicate defined variables #1879
-
Hello,
I was thinking something like the sample for dependency-loops
/E |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @ejfasting,
Not possible, there is no hook during the parsing phase that allows to do so.
It depends on your data structure. In the Langium grammar language we can get away using a DFS for searching all rules and identifying those with duplicate names by creating a map of names: langium/packages/langium/src/grammar/validation/validator.ts Lines 174 to 177 in 89c0a9d Often times you can also use the index to find those elements, that could be faster, and has the optional benefit of finding elements across multiple files.
You can use the |
Beta Was this translation helpful? Give feedback.
In Langium, an import is just a filter of the global scope (collection of all exported symbols from all workspace files), selecting the symbols defined in a specific document. Typically, these are added as the outermost scope in the chain of scopes (usually each block of statements opens a new subscope). But it's perfectly fine to inject a filtered global scope somewhere in the middle of the chain of scopes, depending on where your import is declared. Your custom ScopeProvider is where you can describe this language-specific logic.