diff --git a/example/x3/calc/calc7/expression_def.hpp b/example/x3/calc/calc7/expression_def.hpp index dc73c288ce..69fb947e05 100644 --- a/example/x3/calc/calc7/expression_def.hpp +++ b/example/x3/calc/calc7/expression_def.hpp @@ -64,7 +64,7 @@ namespace client { calculator_grammar::expression_type expression() { - return calculator_grammar::expression; + return {"expression"}; } } diff --git a/example/x3/calc/calc8/expression.hpp b/example/x3/calc/calc8/expression.hpp index d619510cd7..528a6f9a6f 100644 --- a/example/x3/calc/calc8/expression.hpp +++ b/example/x3/calc/calc8/expression.hpp @@ -20,7 +20,7 @@ namespace client BOOST_SPIRIT_DECLARE(expression_type); } - parser::expression_type const& expression(); + parser::expression_type expression(); } #endif diff --git a/example/x3/calc/calc8/expression_def.hpp b/example/x3/calc/calc8/expression_def.hpp index fe9eaee98b..bd08f361af 100644 --- a/example/x3/calc/calc8/expression_def.hpp +++ b/example/x3/calc/calc8/expression_def.hpp @@ -82,9 +82,9 @@ namespace client { namespace parser namespace client { - parser::expression_type const& expression() + parser::expression_type expression() { - return parser::expression; + return {"expression"}; } } diff --git a/example/x3/calc/calc8/statement.hpp b/example/x3/calc/calc8/statement.hpp index 7b8973d0da..ac6e58ec7c 100644 --- a/example/x3/calc/calc8/statement.hpp +++ b/example/x3/calc/calc8/statement.hpp @@ -20,7 +20,7 @@ namespace client BOOST_SPIRIT_DECLARE(statement_type); } - parser::statement_type const& statement(); + parser::statement_type statement(); } #endif diff --git a/example/x3/calc/calc8/statement_def.hpp b/example/x3/calc/calc8/statement_def.hpp index 8772c76fe3..c5f87bf961 100644 --- a/example/x3/calc/calc8/statement_def.hpp +++ b/example/x3/calc/calc8/statement_def.hpp @@ -39,7 +39,7 @@ namespace client { namespace parser variable_type const variable = "variable"; // Import the expression rule - namespace { auto const& expression = client::expression(); } + namespace { auto expression = client::expression(); } auto const statement_list_def = +(variable_declaration | assignment) @@ -75,7 +75,7 @@ namespace client { namespace parser namespace client { - parser::statement_type const& statement() + parser::statement_type statement() { return parser::statement; } diff --git a/example/x3/calc/calc9/expression.hpp b/example/x3/calc/calc9/expression.hpp index f9fa1cc3b2..07bede71ae 100644 --- a/example/x3/calc/calc9/expression.hpp +++ b/example/x3/calc/calc9/expression.hpp @@ -20,7 +20,7 @@ namespace client BOOST_SPIRIT_DECLARE(expression_type); } - parser::expression_type const& expression(); + parser::expression_type expression(); } #endif diff --git a/example/x3/calc/calc9/expression_def.hpp b/example/x3/calc/calc9/expression_def.hpp index 251fb840df..5556db5617 100644 --- a/example/x3/calc/calc9/expression_def.hpp +++ b/example/x3/calc/calc9/expression_def.hpp @@ -36,54 +36,55 @@ namespace client { namespace parser x3::symbols unary_op; x3::symbols<> keywords; - void add_keywords() + namespace { - static bool once = false; - if (once) - return; - once = true; - - logical_op.add - ("&&", ast::op_and) - ("||", ast::op_or) - ; - - equality_op.add - ("==", ast::op_equal) - ("!=", ast::op_not_equal) - ; - - relational_op.add - ("<", ast::op_less) - ("<=", ast::op_less_equal) - (">", ast::op_greater) - (">=", ast::op_greater_equal) - ; - - additive_op.add - ("+", ast::op_plus) - ("-", ast::op_minus) - ; - - multiplicative_op.add - ("*", ast::op_times) - ("/", ast::op_divide) - ; - - unary_op.add - ("+", ast::op_positive) - ("-", ast::op_negative) - ("!", ast::op_not) - ; - - keywords.add - ("var") - ("true") - ("false") - ("if") - ("else") - ("while") - ; + struct add_keywords + { + add_keywords() { + logical_op.add + ("&&", ast::op_and) + ("||", ast::op_or) + ; + + equality_op.add + ("==", ast::op_equal) + ("!=", ast::op_not_equal) + ; + + relational_op.add + ("<", ast::op_less) + ("<=", ast::op_less_equal) + (">", ast::op_greater) + (">=", ast::op_greater_equal) + ; + + additive_op.add + ("+", ast::op_plus) + ("-", ast::op_minus) + ; + + multiplicative_op.add + ("*", ast::op_times) + ("/", ast::op_divide) + ; + + unary_op.add + ("+", ast::op_positive) + ("-", ast::op_negative) + ("!", ast::op_not) + ; + + keywords.add + ("var") + ("true") + ("false") + ("if") + ("else") + ("while") + ; + } + + } init_helper; } //////////////////////////////////////////////////////////////////////////// @@ -172,10 +173,9 @@ namespace client { namespace parser namespace client { - parser::expression_type const& expression() + parser::expression_type expression() { - parser::add_keywords(); - return parser::expression; + return {"expression"}; } } diff --git a/example/x3/calc/calc9/statement.hpp b/example/x3/calc/calc9/statement.hpp index d0c3f514fc..e6a752016a 100644 --- a/example/x3/calc/calc9/statement.hpp +++ b/example/x3/calc/calc9/statement.hpp @@ -21,7 +21,7 @@ namespace client BOOST_SPIRIT_DECLARE(statement_type); } - parser::statement_type const& statement(); + parser::statement_type statement(); } #endif diff --git a/example/x3/calc/calc9/statement_def.hpp b/example/x3/calc/calc9/statement_def.hpp index 84355caa6f..f09f9ab6ef 100644 --- a/example/x3/calc/calc9/statement_def.hpp +++ b/example/x3/calc/calc9/statement_def.hpp @@ -39,7 +39,7 @@ namespace client { namespace parser variable_type const variable("variable"); // Import the expression rule - namespace { auto const& expression = client::expression(); } + namespace { auto expression = client::expression(); } auto const statement_list_def = +(variable_declaration | assignment) @@ -75,9 +75,10 @@ namespace client { namespace parser namespace client { - parser::statement_type const& statement() + parser::statement_type statement() { - return parser::statement; + //return parser::statement; + return {"statement"}; } }