I am trying out a prototype for a language using the textx module for python that can interpret grammars.
I am creating a model like this:
from textx import metamodel_from_str
funl_grammar = """
Model: statement *= Statement;
Statement: FunctionDefinition | Function;
FunctionDefinition: name=ID '=' function=Function;
Function: name=ID '(' params*=Param (',' params*=Param)* ')';
Param: Function | INT | ID | STRING;
Comment: /#.*$/;
ID: /[a-zA-Z_][a-zA-Z0-9_]*/;
INT: /[0-9]+/;
STRING: /".*"/;
"""
mm = metamodel_from_str(funl_grammar)
Now my question is, how can I typecheck for it using mypy?
If I create a function like this where I want to be sure that the parameter is part of my grammar and textx considers it a Param
:
def my_func(param: mm["Param"]):
...
I get the mypy error error: Name "Param" is not defined [name-defined]
.
Do you know how I could fix that? Googling and ChatGPT has not helped so far.