I would like to understand how to use pyparsing to parse something like a nested Python list. This is a question to understand pyparsing. Solutions that circumvent the problem because the list of the example might look like JSON or Python itself should not prevent the usage of pyparsing.
So before people start throwing json and literal_eval at me let's consider a string and result that looks like this:
Input:
{1,2,3,{4,5}}
Expected Output (Python list):
[1,2,3,[4,5]]
I currently have this code but the output does not parse the nested list
import pyparsing
print(
pyparsing.delimited_list(
pyparsing.Word(pyparsing.nums) | pyparsing.nested_expr("{", "}")
)
.parse_string("{1,2,3,{4,5}}")
.as_list()
)
# [['1,2,3,', ['4,5']]]
There is pretty much the same question here already but this one was circumvented by using json parsing: Python parse comma seperated nested brackets using Pyparsing