Reputation: 2713
I would like to parse a file with Boost::Spirit and I would like to pass the parsed data to my class. I never used Boost::Spirit before, therefore I can't really decide which is the best way to solve this problem.
My file structure looks something like this:
Object {
Attribute1(2) {
1,2,3
4,5,6
}
Attribute2(3) {
1,2,3
3,4,5
6,7,8
}
Attribute3(1) {
1,2
}
ComplexAttribute1 {
Inner_Attribute1: 1
Inner_Attribute2: 2
Inner_Atribute3(2) {
1,2,3, 4,5,6, 7,8,9
9,8,7, 6,5,4, 3,2,1
}
}
ComplexAttribute2 {
Inner_Attribute1: 1
Inner_Attribute2: 2
Inner_Atribute3(2) {
1,2,3, 4,5,6, 7,8,9
9,8,7, 6,5,4, 3,2,1
}
}
First I was thinking that I read the file by chunks. One chunk would be the text between { and } characters and I would write a grammer for a chunk like that. Than with a while loop I would go through the chunks. But it feels like this is not a good solution.
Is there a way to write a grammer as big which can parse the whole file?
Something like:
if "Object" then ... if "Attribute1" then... etc...
Anybody can give me some example code which does something similar would be much appreciated! Of course I am happy with any advices/links which can help me.
Thanks in advance!
Upvotes: 2
Views: 553
Reputation: 393134
Is there a way to write a grammer as big which can parse the whole file?
A - Yes.
Look at the following for very similar grammars:
Upvotes: 2