I have a string which looks like the following.
"""
1: a
2: a, b
3: a, b, c
"""
I would like to use pyparsing to define a grammar which is dynamic and picks up the correct number of inputs after reading the number in the beginning of each line. If the number of inputs are not the same, it should give an error. I did look into some documentation, but I only found Forward, and I am not sure if I can use it for this sort of an application. How do I define grammar for this sort of an input using pyparsing?
A possible solution (although pyparsing is not used):
When the given integer does not match the number of strings, an exception is raised: