-
-
Notifications
You must be signed in to change notification settings - Fork 452
Open
Labels
Description
Suggestion
_separated{x, sep}: x (sep x)* // Define a sequence of 'x sep x sep x ...'
a_list: "[" _separated{"a", ","} "]" // works
ab_list1: "[" _separated{"a" | "b", ","} "]" // doesn't work
ab_list2: "[" _separated{("a" | "b"), ","} "]" // doesn't work
This forces us to create intermediary rules that are only used inside a single template
ab: "a" | "b"
ab_list3: "[" _separated{ab, ","} "]" // works
Describe alternatives you've considered
Other solution would be to implement expanding templates:
__separated{x, sep}: x (sep x)* // Define a sequence of 'x sep x sep x ...'
ab_list4: "[" __separated{("a" | "b"), ","} "]" // works, expands to
ab_list5: "[" ("a" | "b") ( "," ("a" | "b") )* "]"
Additional context
This is shortcomming is not documented at https://lark-parser.readthedocs.io/en/latest/grammar.html#templates