I have a text to be parsed, this is a concise form of the text.
apple {
type=fruit
varieties {
color=red
origin=usa
}
}
the output should be as shown below
apple.type=fruit
apple.varieties.color=red
apple.varieties.origin=usa
So far the only thing I have come up with is a sort of breadth-first approach in python. But I cant figure out how to get all the children within.
progInput = """apple {
type=fruit
varieties {
color=red
origin=usa
}
}
"""
progInputSplitToLines = progInput.split('\n')
childrenList = []
root = ""
def hasChildren():
if "{" in progInputSplitToLines[0]:
global root
root = progInputSplitToLines[0].split(" ")[0]
for e in progInputSplitToLines[1:]:
if "=" in e:
childrenList.append({e.split("=")[0].replace(" ", ""),e.split("=")[1].replace(" ", "")})
hasChildren()
PS: I looked into tree structures in Python and came across anytree (https://anytree.readthedocs.io/en/latest/), do you think it would help in my case?
Would you please be able to help me out ? I'm not very good at parsing text. thanks a bunch in advance. :)