mardi 31 octobre 2017

Boost Spirit failing on empty string input

I am trying to parse the following string and extract the parts inside the parenthesis.

This string fails:

_FIND('Something', '')_
Should return
part1 = 'Something'
part2 = ''

This string passes:

_FIND('Something', '*')_
Returns
part1 = 'Something'
part2 = '*'

I assume the problem lies with the "quoted_string"

    find_parser() : find_parser::base_type(start)
    {
        using qi::lit;
        using qi::lexeme;
        using standard_wide::char_;

        /// simple quoted string.
        quoted_string %= lexeme['\'' >> +(char_ - '\'') >> '\''];

        start %=
            -(lit("$(")) // optional
            >> lit("_FIND")
            >> '('
            >> quoted_string
            >> -(',' >> quoted_string) // 2nd parameter optional
            >> ")_"
            >> -(lit(")")) // optional
            ;
    }

I tried added an "empty" string lexeme like this, but it does not work.

        quoted_string %= lexeme['\'' >> +(char_ - '\'') >> '\''];
        empty_quoted_string %= lexeme['\'' >> +(qi::space - '\'') >> '\''];

        start %=
            lit("_FIND")
            >> '('
            >> (quoted_string|empty_quoted_string)
            >> -(',' >> (quoted_string|empty_quoted_string)) // 2nd parameter optional
            >> ")_"
            ;

I know it must be a simple thing, but I cannot put my finger on it.

Thanks for any inputs, hints or tips.

Aucun commentaire:

Enregistrer un commentaire