<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2012 <NAME>
 *
 * 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
 *
 *****************************************************************************/

#include <boost/version.hpp>
#if BOOST_VERSION >= 104700

// mapnik
#include <mapnik/json/geometry_grammar.hpp>

// boost
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>                     // for clog, endl, etc
#include <string>                       // for string

namespace mapnik { namespace json {

template <typename Iterator>
geometry_grammar<Iterator>::geometry_grammar()
    : geometry_grammar::base_type(geometry,"geometry")
{

    using qi::lit;
    using qi::int_;
    using qi::double_;
    using qi::_val;
    using qi::_1;
    using qi::_2;
    using qi::_3;
    using qi::_4;
    using qi::_a;
    using qi::_b;
    using qi::_r1;
    using qi::_r2;
    using qi::eps;
    using qi::_pass;
    using qi::fail;
    using qi::on_error;
    using boost::phoenix::new_;
    using boost::phoenix::push_back;
    using boost::phoenix::construct;
   // Nabialek trick - FIXME: how to bind argument to dispatch rule?
    // geometry = lit("\"geometry\"")
    //    >> lit(':') >> lit('{')
    //    >> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1]
    //    >> lit(',') >> lit("\"coordinates\"") >> lit(':')
    //    >> qi::lazy(*_a)
    //    >> lit('}')
    //    ;
    // geometry_dispatch.add
    //    ("\"Point\"",&point_coordinates)
    //    ("\"LineString\"",&linestring_coordinates)
    //    ("\"Polygon\"",&polygon_coordinates)
    //    ;
    //////////////////////////////////////////////////////////////////

    geometry = (lit('{')[_a = 0 ]
                >> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1] // <---- should be Nabialek trick!
                >> lit(',')
                >> (lit("\"coordinates\"") > lit(':') > coordinates(_r1,_a)
                    |
                    lit("\"geometries\"") > lit(':')
                    >> lit('[') >> geometry_collection(_r1) >> lit(']'))
                >> lit('}'))
        | lit("null")
        ;
<commit_msg>geojson parser : support 'null' as valid coordinates property (empty geometry)<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2012 <NAME>
 *
 * 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
 *
 *****************************************************************************/

#include <boost/version.hpp>
#if BOOST_VERSION >= 104700

// mapnik
#include <mapnik/json/geometry_grammar.hpp>

// boost
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>                     // for clog, endl, etc
#include <string>                       // for string

namespace mapnik { namespace json {

template <typename Iterator>
geometry_grammar<Iterator>::geometry_grammar()
    : geometry_grammar::base_type(geometry,"geometry")
{

    using qi::lit;
    using qi::int_;
    using qi::double_;
    using qi::_val;
    using qi::_1;
    using qi::_2;
    using qi::_3;
    using qi::_4;
    using qi::_a;
    using qi::_b;
    using qi::_r1;
    using qi::_r2;
    using qi::eps;
    using qi::_pass;
    using qi::fail;
    using qi::on_error;
    using boost::phoenix::new_;
    using boost::phoenix::push_back;
    using boost::phoenix::construct;
   // Nabialek trick - FIXME: how to bind argument to dispatch rule?
    // geometry = lit("\"geometry\"")
    //    >> lit(':') >> lit('{')
    //    >> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1]
    //    >> lit(',') >> lit("\"coordinates\"") >> lit(':')
    //    >> qi::lazy(*_a)
    //    >> lit('}')
    //    ;
    // geometry_dispatch.add
    //    ("\"Point\"",&point_coordinates)
    //    ("\"LineString\"",&linestring_coordinates)
    //    ("\"Polygon\"",&polygon_coordinates)
    //    ;
    //////////////////////////////////////////////////////////////////

    geometry = (lit('{')[_a = 0 ]
                >> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1] // <---- should be Nabialek trick!
                >> lit(',')
                >> (lit("\"coordinates\"") > lit(':') > (lit("null") | coordinates(_r1,_a))
                    |
                    lit("\"geometries\"") > lit(':')
                    >> lit('[') >> geometry_collection(_r1) >> lit(']'))
                >> lit('}'))
        | lit("null")
        ;

{'fraction_non_alphanumeric': 0.2163882259347653, 'fraction_numerical': 0.010819411296738265, 'mean_word_length': 2.589948600799543, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337249', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1838, 'n_words': 516}