boostorg / spirit

Boost.org spirit module
http://boost.org/libs/spirit
393 stars 161 forks source link

Boost.Spirit.X3 how to prevent token from being parsed by previous rule? #584

Closed Abdullah-AlAttar closed 4 years ago

Abdullah-AlAttar commented 4 years ago

given this grammar :

const auto grammar_def = x3::lit("start")
                        > x3::lit("{")
                        > (*(char_("a-zA-Z0-9\".{}=_~")))
                        > x3::lit("}") > x3::lit(";);

the last x3::lit("}") is being consumed by *((char("a-zA-Z0-9\".{}=~"))) since it contains "}"
is there way to prevent that ? something like giving
x3::lit("}")** higher priority during parse?

Kojoley commented 4 years ago

No, there is not.

Use Spirit over tokenized input by a non-backtracking regex engine if you really want to match this kind of thing with a consistent performance.