jeudi 28 septembre 2023

Boost Spiri Qi recursive expression parser

    struct NestedStr;

    typedef boost::variant<std::string, boost::recursive_wrapper< NestedStr>> expression;

    struct NestedStr
    {
        vector<expression> children;  // variant instantiated here...

        NestedStr(const vector<expression> & child) : children(child)        
        {
        }

        NestedStr()
        {
        }
    };

    template <typename Iterator>
        struct TimingGrammar : qi::grammar<Iterator, SDFDelayInfo(), ascii::space_type>
    {
        TimingGrammar() : TimingGrammar::base_type(start)
        {

            str_rule            %= +(qi::char_ - (qi::lit('(') | qi::lit(')')));
            brace_rule          %= '(' >> str_rule >> brace_rule >> ')'; 

            start   %= '(' >> qi::lit("TIMING") >> brace_rule ')';
        }

        qi::rule<Iterator, string(), ascii::space_type> str_rule;
        qi::rule<Iterator, NestedStr(), ascii::space_type> start;


    };

I am parsing this nested expression and want to parse till the closing bracket.

(TIMING (RECOVERY (COND(COND(COND(COND))))) (WIDTH (COND AB == 1'b1 (pos CK)) (0.040::0.040)) )

But facing long compiler error.

And second question is there any way whenever "(TIMING" is encountered, omit everything in between the closing bracket of "(TIMING" and move the string iterator after the closing bracket.

Aucun commentaire:

Enregistrer un commentaire