python - Multiple Aliases for a Terminal or Rule - Stack Overflow

admin2025-05-02  1

Can one assign multiple aliases for a terminal or rule in Lark ?

Consider the following grammar

coordinate : "(" X "," Y ")"

%import common.SIGNED_NUMBER -> X
%import common.SIGNED_NUMBER -> Y

which returns the error

lark.exceptions.GrammarError: Rule 'X' used but not defined (in rule coordinate)

My full script for reference is as follows :

from lark import Lark

parser = Lark("""\
coordinate : "(" X "," Y ")"

%import common.SIGNED_NUMBER -> X
%import common.SIGNED_NUMBER -> Y
""")

parser.parse("(12,43)")
转载请注明原文地址:http://www.anycun.com/QandA/1746133008a92030.html