Spirit : Is possible to build rule step by step?
I'm trying to write a small example using spirit. I can write a rule in this way: my_rule = lit("example") | lit("example2"); Also in this way: std::string ex("example") std::string ex2("example2"); my_rule = lit(ex) | lit(ex2)) Is there a way to do this: std::string ex("example") std::string ex2("example2"); my_rule = lit(ex); my_rule = my_rule | lit(ex2)); I need to append strings from an array... Maybe I miss something from docs.
I'm trying to write a small example using spirit.
I can write a rule in this way:
my_rule = lit("example") | lit("example2");
Also in this way:
std::string ex("example") std::string ex2("example2"); my_rule = lit(ex) | lit(ex2))
Is there a way to do this: std::string ex("example") std::string ex2("example2"); my_rule = lit(ex); my_rule = my_rule | lit(ex2));
Make that: my_rule = my_rule.copy() | lit(ex2)); and it will work. The explicit copy is needed, as in this context rules are always held by reference.
I need to append strings from an array... Maybe I miss something from docs.
But since you seem to have only a bunch of strings to match, why don't you use a symbol table (see qi::symbols). This is not only easier to set up iteratively, it's more efficient at runtime as well. Regards Hartmut --------------- http://boost-spirit.com
Thank you Hartmut, really helpful.
On 17 January 2011 17:24, Hartmut Kaiser
I'm trying to write a small example using spirit.
I can write a rule in this way:
my_rule = lit("example") | lit("example2");
Also in this way:
std::string ex("example") std::string ex2("example2"); my_rule = lit(ex) | lit(ex2))
Is there a way to do this: std::string ex("example") std::string ex2("example2"); my_rule = lit(ex); my_rule = my_rule | lit(ex2));
Make that:
my_rule = my_rule.copy() | lit(ex2));
and it will work. The explicit copy is needed, as in this context rules are always held by reference.
I need to append strings from an array... Maybe I miss something from docs.
But since you seem to have only a bunch of strings to match, why don't you use a symbol table (see qi::symbols). This is not only easier to set up iteratively, it's more efficient at runtime as well.
Regards Hartmut --------------- http://boost-spirit.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Andrea Fontana
-
Andrea Fontana
-
Hartmut Kaiser