We want to parse a file and create a data structure of some sort to be used later (in Python). The content of file looks like this:
plan HELLO
feature A
measure X :
src = "Type ,N ame"
endmeasure //X
measure Y :
src = "Type ,N ame"
endmeasure //Y
feature Aa
measure AaX :
src = "Type ,N ame"
endmeasure //AaX
measure AaY :
src = "Type ,N ame"
endmeasure //AaY
feature Aab
.....
endfeature // Aab
endfeature //Aa
endfeature // A
feature B
......
endfeature //B
endplan
plan HOLA
endplan //HOLA
So there's a file that contain one or more plans and then each plan contains one or more feature, further each feature contains a measure that contains info (src, type, name) and feature can further contain more features.
We need to parse through the file and create a data structure that would have
plan (HELLO)
------------------------------
↓ ↓
Feature A Feature B
---------------------------- ↓
↓ ↓ ↓ ........
Measure X Measure Y Feature Aa
------------------------------
↓ ↓ ↓
Measure AaX Measure AaY Feature Aab
↓
.......
I am trying to parse through the file line by line and create a list of lists that would contain plan -> feature -> measure, feature
Here is a function that would turn your string into a dictionary:
Here is an example call:
The output:
If your input has some other syntax -- not included in your question -- you'll probably need to tune the script further to deal with that.