I am parsing a file with a format that can include:
INT32 price min 10 max 100 alertIfSold ;
The min, max and alertIfSold tokens are all optional and can appear in any order. That is
INT32 price max 100 alertIfSold ;
INT32 price max 100 min 10 alertIfSold ;
INT32 price alertIfSold ;
INT32 price;
are all valid examples.
Below is a simple version of the grammar I'm testing. running python test.py generate this error:
lark.common.ParseError: Infinite recursion detected! (rule <__anon_star_1 : __anon_star_1>)
I've tried expressing the same optional tokens using other grammar rules, with similar results (Infinite recursion).
What is the proper grammar to express the optional parameters?
#test.py
from lark import lark
simplified_grammar = """
start: line+
line: TYPE CNAME [MIN MAX ALERT]* ";" -> foo
TYPE: "INT32" | "INT64"
MIN: "min" /[0-9]+/
MAX: "max" /[0-9]+/
ALERT: "alertIfSold"
%import common.CNAME
%import common.WS
%ignore WS
"""
sample = """
INT32 price max 100 alertIfSold ;
INT32 price max 100 min 10 alertIfSold ;
INT32 price alertIfSold ;
INT32 price;
"""
parser = lark.Lark(simplified_grammar)
def main():
parse_tree = parser.parse(sample)
if __name__ == '__main__':
main()