osrm-backend/include/server/api/nearest_parameter_grammar.hpp
Daniel J. Hofmann 8a2bd09fd0 Adapts all grammars to use expectation parsers without backtracking.
Sequence parsers using `>>` allow for backtracking, expectation parsers
`>` do not. This allows us to properly report the position where parsing
failed, by catching the expectation_failure exception and adapting the
iterator ourselves.

References:
- https://github.com/Project-OSRM/osrm-backend/pull/2188
- https://github.com/Project-OSRM/osrm-backend/issues/2168
- http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/qi/reference/operator/expect.html
2016-04-08 21:03:50 +02:00

44 lines
998 B
C++

#ifndef NEAREST_PARAMETERS_GRAMMAR_HPP
#define NEAREST_PARAMETERS_GRAMMAR_HPP
#include "engine/api/nearest_parameters.hpp"
#include "server/api/base_parameters_grammar.hpp"
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>
namespace osrm
{
namespace server
{
namespace api
{
namespace qi = boost::spirit::qi;
struct NearestParametersGrammar final : public BaseParametersGrammar
{
using Iterator = std::string::iterator;
NearestParametersGrammar() : BaseParametersGrammar(root_rule, parameters)
{
const auto set_number = [this](const unsigned number) {
parameters.number_of_results = number;
};
nearest_rule = (qi::lit("number=") > qi::uint_)[set_number];
root_rule =
query_rule > -qi::lit(".json") > -(qi::lit("?") > (nearest_rule | base_rule) % '&');
}
engine::api::NearestParameters parameters;
private:
qi::rule<Iterator> root_rule;
qi::rule<Iterator> nearest_rule;
};
}
}
}
#endif