Is it possible to modify the parser of a rule at runtime? I am able to dynamically create parsers (classes that are derived from parser_base), but I dont know how I can assign the new parser to an existing rule.
Basically my problem is that I want to define a parser for a line that consists of elements like numbers (lets call them constants in the sense that they are invariant over all my parser input) and symbols (the variants that I want to capture with a dynamic parser approach). Since the symbols are based on the current environment at runtime I think I need a dynamic parser.
minimalistic issue, I want symbols and a line-end:
namespace parser
{
x3::rule<class line, ast::line> line = "line";
auto const line_def = variants_def >> lineend_def;
BOOST_SPIRIT_DEFINE(line);
}
using line_type = boost::spirit::x3::rule<class client::parser::line, ast::line>;
line_type line(boost::spirit::x3::plus<boost::spirit::x3::symbols_parser<boost::spirit::char_encoding::standard, client::ast::command, boost::spirit::x3::tst<boost::spirit::char_encoding::standard::char_type, client::ast::command>>> symbols_parser)
{
auto line_end = lineend();
auto const line_def2 = symbols_parser >> line_end;
return parser::line; // <-- how can I change the line_type to use line_def2?
}
This code might be far from minimal, but unfortunately Im not so familiar with C++ yet.