Parsing a user defined format?

2019-07-25 11:15发布

I love the way of how Boost property_tree parsing certain types of files. But my file is kind of different

/*--------------------------------*- C++ -*----------------------------------*\
| WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW |
\*---------------------------------------------------------------------------*/
INFORMATION
{
    version     2.0;
    format      ascii;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

school
{
    "(boys|girls)"
    {
        hair red;
        legs short;
        nose long;
        mood good;
    }

    workers
    {
        hair green;
        legs long;
        nose abnormal;
        mood bad;
    }
}

// ************************************************************************* //

I hope it can be used in this way

string myMood = pt.get<std::string>("school.boys.mood");
cout<< "\tmyMood is = " << myMood << endl;

Which is very clean and straightforward.

But it seems currently the boost ptree INFO parser cannot handle comments and "(boys|girls)" type.

Any solution?

0条回答
登录 后发表回答