2

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!

Silex
  • 2,583
  • 3
  • 35
  • 59

1 Answers1

2

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:

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633