textX: Scoping issue - problems to do a cross-ref of a variable with same name in two different contexts
Hello guys, I would appreciate your help in order to resolve this cross-referencing issue. In the grammar bellow, I need to recognize var1, var2 and var3 as belonging to its context(ZventoA and ZventoB) without conflicts:
from textx.metamodel import metamodel_from_str
from textx.exceptions import TextXError
from textx.model import get_parent_of_type
grammar = """
F:
events *= Event;
Event:
'event' name=ID '(' parameters+=Variable[','] ')' ':'
argumentos+=Repetition[',']
'end'
;
Repetition:
ID '=' paramName=[Variable];
Variable: name=ID;
"""
try:
meta = metamodel_from_str(grammar, autokwd=True)
print("Meta-Model OK")
except TextXError as e:
print("Error in meta-model:")
print(e)
code ='''
event ZeventA (var1,var2,var3):
x1=var1,
x2=var2,
x3=var3
end
event ZeventoB (var1,var2,var3):
x1=var1,
x2=var2,
x3=var3
end
'''
try:
model = meta.model_from_str(code)
print("Model ok")
except TextXError as e:
print("Error in model: ", e)
But I have the following output when running the code above:
Meta-Model OK
Error in model: None:3:8: error: name var1 is not unique.
When I change the name of var1 of event ZeventB to, for example ZeventB (var1aux,var2,var3), then the problem is transferred to var2
Meta-Model OK
Error in model: None:4:8: error: name var2 is not unique.
How could I link var1, var2 and var3 to it’s specific events ZeventA and ZeventB? Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (12 by maintainers)
Hi. Thank you for question.
Can you try with the fqn scope provider? This should work. http://textx.github.io/textX/stable/scoping/