diff --git a/include/mapnik/expression_grammar_x3_config.hpp b/include/mapnik/expression_grammar_x3_config.hpp index c9ca4d7ee..402fdd6b3 100644 --- a/include/mapnik/expression_grammar_x3_config.hpp +++ b/include/mapnik/expression_grammar_x3_config.hpp @@ -27,11 +27,6 @@ #include #include -#pragma GCC diagnostic push -#include -#include -#pragma GCC diagnostic pop - namespace mapnik { namespace grammar { namespace x3 = boost::spirit::x3; diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index a3ddcf51b..0ef8fe960 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2015 Artem Pavlenko + * Copyright (C) 2016 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -420,7 +420,7 @@ namespace mapnik { namespace grammar { primary_expression ); -}} + }} namespace mapnik { diff --git a/include/mapnik/path_expression_grammar_impl.hpp b/include/mapnik/path_expression_grammar_impl.hpp deleted file mode 100644 index 22002bf33..000000000 --- a/include/mapnik/path_expression_grammar_impl.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2015 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -#include - - -#pragma GCC diagnostic push -#include -#include -#include -#include -#pragma GCC diagnostic pop - -namespace mapnik -{ - -template -path_expression_grammar::path_expression_grammar() - : path_expression_grammar::base_type(expr) -{ - standard_wide::char_type char_; - qi::_1_type _1; - qi::_val_type _val; - qi::lit_type lit; - qi::lexeme_type lexeme; - using phoenix::push_back; - using boost::phoenix::construct; - - expr = - * ( - str [ push_back(_val, _1)] - | - ( '[' >> attr [ push_back(_val, construct( _1 )) ] >> ']') - ) - ; - - attr %= +(char_ - ']'); - str %= lexeme[+(char_ -'[')]; -} - -} diff --git a/include/mapnik/path_expression_grammar.hpp b/include/mapnik/path_expression_grammar_x3.hpp similarity index 58% rename from include/mapnik/path_expression_grammar.hpp rename to include/mapnik/path_expression_grammar_x3.hpp index 61a3db7ed..86e811fea 100644 --- a/include/mapnik/path_expression_grammar.hpp +++ b/include/mapnik/path_expression_grammar_x3.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2015 Artem Pavlenko + * Copyright (C) 2016 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,40 +20,25 @@ * *****************************************************************************/ -#ifndef MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP -#define MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP +#ifndef MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_HPP +#define MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_HPP // mapnik #include #pragma GCC diagnostic push #include -#include +#include #pragma GCC diagnostic pop -// stl -#include -#include +namespace mapnik { namespace grammar { -namespace mapnik -{ +namespace x3 = boost::spirit::x3; +struct path_expression_class; // top-most ID +using path_expression_grammar_type = x3::rule; -using namespace boost; -namespace qi = boost::spirit::qi; -namespace phoenix = boost::phoenix; -namespace standard_wide = boost::spirit::standard_wide; +BOOST_SPIRIT_DECLARE(path_expression_grammar_type); -using standard_wide::space_type; +}} -template -struct path_expression_grammar : qi::grammar(), space_type> -{ - path_expression_grammar(); - qi::rule() , space_type> expr; - qi::rule attr; - qi::rule str; -}; - -} - -#endif // MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP +#endif // MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_HPP diff --git a/include/mapnik/path_expression_grammar_x3_def.hpp b/include/mapnik/path_expression_grammar_x3_def.hpp new file mode 100644 index 000000000..7dc772aa1 --- /dev/null +++ b/include/mapnik/path_expression_grammar_x3_def.hpp @@ -0,0 +1,63 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2016 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_DEF_HPP +#define MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_DEF_HPP +// mapnik +#include +#include + +namespace mapnik { namespace grammar { + +namespace x3 = boost::spirit::x3; +using x3::standard_wide::char_; +using x3::lexeme; +auto create_string = [](auto & ctx) { _val(ctx).push_back(_attr(ctx)); }; +auto create_attribute = [](auto & ctx) { _val(ctx).push_back(mapnik::attribute(_attr(ctx))); }; +// top-most rule +path_expression_grammar_type const path_expression("path_expression"); +// rules +x3::rule const attr_expression("attribute"); +x3::rule const str_expression("string"); + +auto const attr_expression_def = +(char_ - ']'); +auto const str_expression_def = lexeme[+(char_ -'[')]; +auto const path_expression_def = *(str_expression[create_string] | '[' > attr_expression[create_attribute] > ']'); + +BOOST_SPIRIT_DEFINE( + path_expression, + attr_expression, + str_expression +); + +}} + +namespace mapnik { + +grammar::path_expression_grammar_type path_expression_grammar() +{ + return grammar::path_expression; +} + +} + +#endif //MAPNIK_PATH_EXPRESSIONS_GRAMMAR_X3_DEF_HPP diff --git a/src/parse_path.cpp b/src/parse_path.cpp index a3d67c2cb..ebf50fbcc 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -21,26 +21,35 @@ *****************************************************************************/ #include -#include -#include #include #include #include #include +#include +#include + // stl #include -namespace mapnik { +namespace mapnik { namespace grammar { + +namespace x3 = boost::spirit::x3; +using iterator_type = std::string::const_iterator; +using context_type = x3::phrase_parse_context::type; + +BOOST_SPIRIT_INSTANTIATE(path_expression_grammar_type, iterator_type, context_type); + +} path_expression_ptr parse_path(std::string const& str) { - static const path_expression_grammar g; + namespace x3 = boost::spirit::x3; auto path = std::make_shared(); - boost::spirit::standard_wide::space_type space; + using boost::spirit::x3::standard_wide::space; std::string::const_iterator itr = str.begin(); std::string::const_iterator end = str.end(); - bool r = qi::phrase_parse(itr, end, g, space, *path); + bool r = x3::phrase_parse(itr, end, path_expression_grammar(), space, *path); if (r && itr == end) { return path;