-
I'm working on development of a Python-like language for usage in a browser code editor and have a couple of questions about adding a builtin library support.
# file1:
def func1():
return 'f1'
#file2:
def func2():
return 'f2'
# user code
import file1
file1.func1()
file2.func2() # should be an error cause it's not imported I beleive it could be done with coordination of custom lexer and workspace manager, am I right? Could you please tell me what is an optimal way to do this?
from file1 import func1 as Foo
from file2 import func2
Foo() # I wanna have a tooltips for func1 from builtins here
func2 = 100 # I don't want to have any tooltips for func2 further cause it is int from now How can I implement such things with Langium? Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @Gilyermo
No, unless you actually want to modify how certain tokens are parsed, you shouldn't need to touch the lexer at all (though indentation aware parsing like in Python requires special
Through scoping as well. Generally, when the question is "How can I handle cross references to other elements in Langium", the answer is almost always scoping. More specifically, in both of these cases, you want to change how AST node descriptions are built during the scope computation phase. In the first case, you want to export an AST node using a different name (this is roughly outlined here), and in the second case you probably want to invert the lexical scope (i.e. the list of objects available in the current block), so that a reference always refers to the last place it is declared, instead of the first. |
Beta Was this translation helpful? Give feedback.
Hey @Gilyermo
No, unless you actually want to modify how certain tokens are parsed, you shouldn't need to touch the lexer at all (though indentation aware parsing like in Python requires special
INDENT
andDEDENT
tokens). Import features are accomplished via scoping. See our langium grammar scope as an example.Through scoping as well. Generally, when the question is "How can I handle cross references to other elements in Langium", the answer is almost always scoping. More specifically, in both of these cases, you want to change how AST node des…