osrm-backend/include/server/api/table_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

56 lines
1.5 KiB
C++

#ifndef TABLE_PARAMETERS_GRAMMAR_HPP
#define TABLE_PARAMETERS_GRAMMAR_HPP
#include "engine/api/table_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 TableParametersGrammar final : public BaseParametersGrammar
{
using Iterator = std::string::iterator;
using SourcesT = std::vector<std::size_t>;
using DestinationsT = std::vector<std::size_t>;
TableParametersGrammar() : BaseParametersGrammar(root_rule, parameters)
{
const auto set_destiantions = [this](DestinationsT dests) {
parameters.destinations = std::move(dests);
};
const auto set_sources = [this](SourcesT sources) {
parameters.sources = std::move(sources);
};
destinations_rule = (qi::lit("destinations=") > (qi::ulong_ % ";")[set_destiantions]) |
qi::lit("destinations=all");
sources_rule =
(qi::lit("sources=") > (qi::ulong_ % ";")[set_sources]) | qi::lit("sources=all");
table_rule = destinations_rule | sources_rule;
root_rule =
query_rule > -qi::lit(".json") > -(qi::lit("?") > (table_rule | base_rule) % '&');
}
engine::api::TableParameters parameters;
private:
qi::rule<Iterator> root_rule;
qi::rule<Iterator> table_rule;
qi::rule<Iterator> sources_rule;
qi::rule<Iterator> destinations_rule;
};
}
}
}
#endif