Overpass API regression suite coverage (Saxony) / overpass_api/frontend/map_ql_parser.cc

overpass_api/frontend/map_ql_parser.cc

1000 of 1112 instrumented lines run by the suite (89.9%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include "../../expat/map_ql_input.h"
20#include "../core/datatypes.h"
21#include "../core/parsed_query.h"
22#include "../dispatch/scripting_core.h"
23#include "../statements/osm_script.h"
24#include "../statements/statement.h"
25#include "../statements/statement_dump.h"
26#include "map_ql_parser.h"
27#include "output_handler_parser.h"
28#include "tokenizer_utils.h"
30#include <cctype>
31#include <fstream>
32#include <iostream>
33#include <iterator>
34#include <queue>
35#include <set>
36#include <sstream>
37#include <vector>
40//-----------------------------------------------------------------------------
42template< class TStatement >
43TStatement* parse_statement(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
44 Tokenizer_Wrapper& token, Error_Output* error_output, int depth);
46std::string probe_into(Tokenizer_Wrapper& token, Error_Output* error_output)
477688682 q{
487688682 q std::string into = "_";
497688682 q if (token.good() && *token == "->")
506700649 q {
516700649 q ++token;
526700649 q clear_until_after(token, error_output, ".");
536700649 q if (token.good())
546700649 q into = get_identifier_token(token, error_output, "Variable");
556700649 q }
567688682 q return into;
577688682 q}
59std::string probe_from(Tokenizer_Wrapper& token, Error_Output* error_output)
61524111 q std::string from = "_";
62524111 q if (token.good() && *token == ".")
63512109 q {
64512109 q ++token;
65512109 q if (token.good())
66512109 q from = get_identifier_token(token, error_output, "Variable");
67512109 q }
68524111 q return from;
71template< class TStatement >
72std::vector< TStatement* > collect_substatements(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
73 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
75756151 q std::vector< TStatement* > substatements;
76756151 q clear_until_after(token, error_output, "(", "{", false);
77756151 q if (!token.good())
780 return substatements;
79756151 q std::string closing_token = (*token == "(" ? ")" : "}");
80756151 q ++token;
811240151 q while (token.good() && *token != closing_token)
8248479 q {
8348479 q std::pair< uint, uint > pos_before = token.line_col();
8448479 q TStatement* substatement = parse_statement< TStatement >
8548479 q (stmt_factory, parsed_query, token, error_output, depth+1);
8648479 q if (substatement)
8748479 q substatements.push_back(substatement);
880 else if (token.line_col() == pos_before)
890 break;
9048479 q }
91756151 q if (token.good())
92756151 q ++token;
94756151 q return substatements;
97template< class TStatement >
98std::vector< TStatement* > collect_substatements_and_probe
99 (typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
100 Tokenizer_Wrapper& token, Error_Output* error_output, bool& is_difference, int depth)
102512114 q is_difference = false;
104512114 q std::vector< TStatement* > substatements;
105512114 q clear_until_after(token, error_output, "(");
106512114 q if (token.good() && *token != ")")
10740494 q {
10840494 q TStatement* substatement = parse_statement< TStatement >
10940494 q (stmt_factory, parsed_query, token, error_output, depth+1);
11040494 q if (substatement)
11140494 q substatements.push_back(substatement);
11240494 q if (*token == "-")
1148821 q is_difference = true;
1158821 q ++token;
11740494 q }
118512114 q if (token.good() && *token != ")")
11921650 q {
12021650 q TStatement* substatement = parse_statement< TStatement >
12121650 q (stmt_factory, parsed_query, token, error_output, depth+1);
12221650 q if (substatement)
12321650 q substatements.push_back(substatement);
12421650 q if (is_difference && *token != ")")
1250 {
1260 if (error_output)
1270 error_output->add_parse_error("difference always requires two operands", token.line_col().first);
1280 clear_until_after(token, error_output, ")", false);
1290 }
13021650 q }
131568114 q while (token.good() && *token != ")")
132566 q {
133566 q std::pair< uint, uint > pos_before = token.line_col();
134566 q TStatement* substatement = parse_statement< TStatement >
135566 q (stmt_factory, parsed_query, token, error_output, depth+1);
136566 q if (substatement)
137566 q substatements.push_back(substatement);
1380 else if (token.line_col() == pos_before)
1390 break;
140566 q }
141512114 q if (token.good())
142512114 q ++token;
144512114 q return substatements;
148//-----------------------------------------------------------------------------
151template< class TStatement >
152TStatement* parse_value_tree(typename TStatement::Factory& stmt_factory, Tokenizer_Wrapper& token,
153 Error_Output* error_output, bool parenthesis_expected,
154 Statement::QL_Context tree_context, const Statement::Return_Type_Checker& eval_type)
15628468 q Token_Tree tree(token, error_output, parenthesis_expected);
15728468 q if (tree.tree.empty())
1580 return 0;
16028468 q return stmt_factory.create_evaluator(Token_Node_Ptr(tree, tree.tree[0].rhs), tree_context,
16128468 q eval_type);
165template< class TStatement >
166TStatement* create_union_statement(typename TStatement::Factory& stmt_factory,
167 std::string into, uint line_nr)
16942496 q std::map< std::string, std::string > attr;
17042496 q attr["into"] = into;
17142496 q return stmt_factory.create_statement("union", line_nr, attr);
174template< class TStatement >
175TStatement* create_difference_statement(typename TStatement::Factory& stmt_factory,
176 std::string into, uint line_nr)
1788821 q std::map< std::string, std::string > attr;
1798821 q attr["into"] = into;
1808821 q return stmt_factory.create_statement("difference", line_nr, attr);
183template< class TStatement >
184TStatement* create_for_statement(typename TStatement::Factory& stmt_factory,
185 std::string stmt_name, std::string from, std::string into, uint line_nr)
18719246 q std::map< std::string, std::string > attr;
18819246 q attr["from"] = from;
18919246 q attr["into"] = into;
19019246 q return stmt_factory.create_statement(stmt_name, line_nr, attr);
194template< class TStatement >
195TStatement* create_make_statement(typename TStatement::Factory& stmt_factory,
196 std::string strategy, std::string from, std::string into, std::string type, uint line_nr)
198632127 q std::map< std::string, std::string > attr;
199632127 q if (from != "")
20033278 q attr["from"] = from;
201632127 q attr["into"] = into;
202632127 q attr["type"] = type;
203632127 q return stmt_factory.create_statement(strategy, line_nr, attr);
207template< class TStatement >
208TStatement* create_complete_statement(typename TStatement::Factory& stmt_factory,
209 std::string maxnum, std::string from, std::string into, uint line_nr)
21133269 q std::map< std::string, std::string > attr;
21233269 q attr["maxnum"] = maxnum;
21333269 q attr["from"] = from;
21433269 q attr["into"] = into;
21533269 q return stmt_factory.create_statement("complete", line_nr, attr);
219template< class TStatement >
220TStatement* create_if_statement(typename TStatement::Factory& stmt_factory, uint line_nr)
2227617 q std::map< std::string, std::string > attr;
2237617 q return stmt_factory.create_statement("if", line_nr, attr);
227template< class TStatement >
228TStatement* create_else_statement(typename TStatement::Factory& stmt_factory, uint line_nr)
230287 q std::map< std::string, std::string > attr;
231287 q return stmt_factory.create_statement("else", line_nr, attr);
235template< class TStatement >
236TStatement* create_retro_statement(typename TStatement::Factory& stmt_factory, uint line_nr)
2386015 q std::map< std::string, std::string > attr;
2396015 q return stmt_factory.create_statement("retro", line_nr, attr);
243template< class TStatement >
244TStatement* create_print_statement(typename TStatement::Factory& stmt_factory,
245 std::string from, std::string mode, std::string order, std::string limit, std::string geometry, std::string show_ids,
246 std::string south, std::string north, std::string west, std::string east,
247 uint line_nr)
24816032673 q{
24916032673 q std::map< std::string, std::string > attr;
25016032673 q attr["from"] = from;
25116032673 q attr["mode"] = mode;
25216032673 q attr["order"] = order;
25316032673 q attr["limit"] = limit;
25416032673 q attr["geometry"] = geometry;
25516032673 q attr["ids"] = show_ids;
25616032673 q attr["s"] = south;
25716032673 q attr["n"] = north;
25816032673 q attr["w"] = west;
25916032673 q attr["e"] = east;
26016032673 q return stmt_factory.create_statement("print", line_nr, attr);
26116032673 q}
264template< class TStatement >
265TStatement* create_timeline_statement(typename TStatement::Factory& stmt_factory, uint line_nr,
266 const std::string& type, const std::string& ref, const std::string& version, const std::string& into)
26814837 q std::map< std::string, std::string > attr;
26914837 q attr["type"] = type;
27014837 q attr["ref"] = ref;
27114837 q attr["version"] = version;
27214837 q attr["into"] = into;
27314837 q return stmt_factory.create_statement("timeline", line_nr, attr);
277template< class TStatement >
278TStatement* create_compare_statement(typename TStatement::Factory& stmt_factory, uint line_nr,
279 const std::string& from, const std::string& into)
2818421 q std::map< std::string, std::string > attr;
2828421 q attr["from"] = (from == "" ? "_" : from);
2838421 q attr["into"] = into;
2848421 q return stmt_factory.create_statement("compare", line_nr, attr);
288template< class TStatement >
289TStatement* create_query_statement(typename TStatement::Factory& stmt_factory,
290 std::string type, std::string into, uint line_nr)
2923409580 q std::map< std::string, std::string > attr;
2933409580 q attr["type"] = type;
2943409580 q attr["into"] = into;
2953409580 q return stmt_factory.create_statement("query", line_nr, attr);
299typedef enum { haskv_plain, haskv_regex, haskv_icase } haskv_type;
302template< class TStatement >
303TStatement* create_has_kv_statement(typename TStatement::Factory& stmt_factory,
304 std::string key, std::string value, haskv_type regex, haskv_type key_regex, bool straight, uint line_nr)
3062284374 q std::map< std::string, std::string > attr;
3082284374 q if (key_regex == haskv_plain)
3092080353 q attr["k"] = key;
31020445 q else
31120445 q attr["regk"] = key;
3132284374 q if (regex == haskv_plain)
3141600298 q attr["v"] = value;
315684138 q else if (regex == haskv_regex)
316660135 q attr["regv"] = value;
317246 q else
318246 q {
319246 q attr["regv"] = value;
320246 q attr["case"] = "ignore";
321246 q }
3232284374 q attr["modv"] = (straight ? "" : "not");
3242284374 q return stmt_factory.create_statement("has-kv", line_nr, attr);
328template< class TStatement >
329TStatement* create_item_statement(typename TStatement::Factory& stmt_factory,
330 std::string from, std::string into, uint line_nr)
332868159 q std::map< std::string, std::string > attr;
333868159 q attr["from"] = from;
334868159 q attr["into"] = into;
335868159 q return stmt_factory.create_statement("item", line_nr, attr);
339template< class TStatement >
340TStatement* create_recurse_statement(typename TStatement::Factory& stmt_factory,
341 std::string type, std::string from, std::string into, uint line_nr)
34337687 q std::map< std::string, std::string > attr;
34437687 q attr["from"] = (from == "" ? "_" : from);
34537687 q attr["into"] = into;
34637687 q attr["type"] = type;
34737687 q return stmt_factory.create_statement("recurse", line_nr, attr);
351template< class TStatement >
352TStatement* create_coord_query_statement(typename TStatement::Factory& stmt_factory,
353 std::string lat, std::string lon, std::string from, std::string into, uint line_nr)
35520050 q std::map< std::string, std::string > attr;
35620050 q attr["from"] = (from == "" ? "_" : from);
35720050 q attr["into"] = into;
35820050 q attr["lat"] = lat;
35920050 q attr["lon"] = lon;
36020050 q return stmt_factory.create_statement("coord-query", line_nr, attr);
364template< class TStatement >
365TStatement* create_map_to_area_statement(typename TStatement::Factory& stmt_factory,
366 std::string from, std::string into, uint line_nr)
3687218 q std::map< std::string, std::string > attr;
3697218 q attr["from"] = (from == "" ? "_" : from);
3707218 q attr["into"] = into;
3717218 q return stmt_factory.create_statement("map-to-area", line_nr, attr);
375template< class TStatement >
376TStatement* create_localize_statement(typename TStatement::Factory& stmt_factory,
377 std::string type, std::string from, std::string into,
378 std::string south, std::string north, std::string west, std::string east, uint line_nr)
3808019 q std::map< std::string, std::string > attr;
3818019 q attr["from"] = (from == "" ? "_" : from);
3828019 q attr["into"] = into;
3838019 q attr["type"] = type;
3848019 q attr["s"] = south;
3858019 q attr["n"] = north;
3868019 q attr["w"] = west;
3878019 q attr["e"] = east;
3888019 q return stmt_factory.create_statement("localize", line_nr, attr);
392//-----------------------------------------------------------------------------
394std::vector< std::string > parse_setup(Tokenizer_Wrapper& token,
395 Error_Output* error_output, Parsed_Query& parsed_query)
3971836352 q ++token;
3981836352 q std::vector< std::string > result;
3991836352 q result.push_back(get_identifier_token(token, error_output, "Keyword"));
4001836352 q clear_until_after(token, error_output, ":", "]");
4011836352 q result.push_back(get_text_token(token, error_output, "Value"));
4021836352 q if (result.front() == "out")
404516129 q Output_Handler_Parser* format_parser =
405516129 q Output_Handler_Parser::get_format_parser(result.back());
407516129 q if (!format_parser)
4080 {
4090 if (error_output)
4100 error_output->add_parse_error("Unknown output format: " + result.back(), token.line_col().first);
4110 }
412516129 q else
414516129 q parsed_query.set_output_handler(format_parser, &token, error_output);
415516129 q if (parsed_query.get_output_handler())
417516129 q result.push_back("output-config");
418516129 q result.push_back(parsed_query.get_output_handler()->dump_config());
422516129 q clear_until_after(token, error_output, "]", true);
4241320298 q else if (result.front() == "diff" || result.front() == "adiff")
42532481 q {
42632481 q clear_until_after(token, error_output, ",", "]", false);
42732481 q if (*token == ",")
4299223 q ++token;
4309223 q result.push_back(get_text_token(token, error_output, "Value"));
4319223 q clear_until_after(token, error_output, "]", true);
43323258 q else
43423258 q ++token;
43532481 q }
436996226 q else if (result.front() == "bbox")
4389223 q clear_until_after(token, error_output, ",", "]", false);
4399223 q if (*token == ",")
4419223 q ++token;
4429223 q result.back() += "," + get_text_token(token, error_output, "Value");
4439223 q clear_until_after(token, error_output, ",", "]", false);
4459223 q if (*token == ",")
4479223 q ++token;
4489223 q result.back() += "," + get_text_token(token, error_output, "Value");
4499223 q clear_until_after(token, error_output, ",", "]", false);
4519223 q if (*token == ",")
4539223 q ++token;
4549223 q result.back() += "," + get_text_token(token, error_output, "Value");
4559223 q clear_until_after(token, error_output, "]");
458904209 q else if (result.front() == "maxsize" || result.front() == "timeout")
45910423 q {
46010423 q while (token.good() && *token != "]")
4610 {
4620 result.back() += (' ' + *token);
4630 ++token;
4640 }
46510423 q clear_until_after(token, error_output, "]");
46610423 q }
467800200 q else
468800200 q clear_until_after(token, error_output, "]");
4691836352 q return result;
473template< class TStatement >
474TStatement* parse_union(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
475 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
477512114 q std::pair< uint, uint > line_col = token.line_col();
479512114 q bool is_difference = false;
480512114 q std::vector< TStatement* > substatements =
481512114 q collect_substatements_and_probe< TStatement >(stmt_factory, parsed_query, token, error_output,
482512114 q is_difference, depth+1);
483512114 q std::string into = probe_into(token, error_output);
484512114 q clear_until_after(token, error_output, ";");
486512114 q TStatement* statement = 0;
487512114 q if (is_difference)
4888821 q statement = create_difference_statement< TStatement >(stmt_factory, into, line_col.first);
48942496 q else
49042496 q statement = create_union_statement< TStatement >(stmt_factory, into, line_col.first);
492512114 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
4931188114 q it != substatements.end(); ++it)
49467694 q statement->add_statement(*it, "");
495512114 q return statement;
499template< class TStatement >
500TStatement* parse_foreach(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
501 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
50311628 q std::pair< uint, uint > line_col = token.line_col();
50411628 q ++token;
50611628 q std::string from = probe_from(token, error_output);
50711628 q std::string into = probe_into(token, error_output);
50811628 q std::vector< TStatement* > substatements =
50911628 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth+1);
51011628 q if (*token == ";")
51141 q ++token;
51311628 q TStatement* statement = create_for_statement< TStatement >
51411628 q (stmt_factory, "foreach", from, into, line_col.first);
51511628 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
51629228 q it != substatements.end(); ++it)
51717627 q statement->add_statement(*it, "");
51811628 q return statement;
522struct For_Stmt_Return_Type_Checker : Statement::Return_Type_Checker
5247619 q For_Stmt_Return_Type_Checker() {}
5267619 q virtual bool eval_required() const { return true; }
527 virtual bool matches(Statement::Eval_Return_Type eval_type) const
5287619 q { return eval_type == Statement::string || eval_type == Statement::container; }
529 virtual std::string expectation() const
5300 { return Statement::eval_to_string(Statement::string) + " or " + Statement::eval_to_string(Statement::container); }
531};
534template< class TStatement >
535TStatement* parse_for(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
536 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
5387619 q std::pair< uint, uint > line_col = token.line_col();
5397619 q ++token;
5417619 q std::string from = probe_from(token, error_output);
5427619 q std::string into = probe_into(token, error_output);
5447619 q clear_until_after(token, error_output, "(");
5457619 q TStatement* condition = parse_value_tree< TStatement >(stmt_factory, token, error_output, true,
5467619 q Statement::elem_eval_possible, For_Stmt_Return_Type_Checker());
5477619 q clear_until_after(token, error_output, ")");
5487619 q std::vector< TStatement* > substatements =
5497619 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth+1);
5507619 q if (*token == ";")
5510 ++token;
5537619 q TStatement* statement = create_for_statement< TStatement >
5547619 q (stmt_factory, "for", from, into, line_col.first);
5557619 q statement->add_statement(condition, "");
5567619 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
55710019 q it != substatements.end(); ++it)
558246 q statement->add_statement(*it, "");
5597619 q return statement;
563template< class TStatement >
564TStatement* parse_complete(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
565 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
56733269 q std::pair< uint, uint > line_col = token.line_col();
56833269 q ++token;
56933269 q std::string maxnum;
57033269 q if (*token == "(")
57133269 q {
57233269 q ++token;
57333269 q maxnum = get_text_token(token, error_output, "maximum loop number");
57433269 q clear_until_after(token, error_output, ")");
57533269 q }
57633269 q std::string from = probe_from(token, error_output);
57733269 q std::string into = probe_into(token, error_output);
57833269 q std::vector< TStatement* > substatements =
57933269 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
58033269 q if (*token == ";")
5810 ++token;
58333269 q TStatement* statement = create_complete_statement< TStatement >
58433269 q (stmt_factory, maxnum, from, into, line_col.first);
58533269 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
58642469 q it != substatements.end(); ++it)
5879214 q statement->add_statement(*it, "");
58833269 q return statement;
592template< class TStatement >
593TStatement* parse_if(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
594 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
5967617 q std::pair< uint, uint > line_col = token.line_col();
5977617 q ++token;
5997617 q clear_until_after(token, error_output, "(");
6007617 q TStatement* condition = parse_value_tree< TStatement >(stmt_factory, token, error_output, true,
6017617 q Statement::evaluator_expected, Statement::Single_Return_Type_Checker(Statement::string));
6027617 q clear_until_after(token, error_output, ")");
6037617 q std::vector< TStatement* > substatements =
6047617 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
6057617 q std::vector< TStatement* > else_statements;
6067617 q if (token.good() && *token == "else")
6085212 q ++token;
6095212 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth)
6105212 q .swap(else_statements);
6127617 q if (*token == ";")
6130 ++token;
6157617 q TStatement* statement = create_if_statement< TStatement >(stmt_factory, line_col.first);
6167617 q if (condition)
6177617 q statement->add_statement(condition, "");
6187617 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
61910017 q it != substatements.end(); ++it)
620246 q statement->add_statement(*it, "");
6217617 q if (!else_statements.empty())
622287 q statement->add_statement(create_else_statement< TStatement >(stmt_factory, line_col.first), "");
6237617 q for (typename std::vector< TStatement* >::const_iterator it = else_statements.begin();
62410417 q it != else_statements.end(); ++it)
625287 q statement->add_statement(*it, "");
6267617 q return statement;
630template< class TStatement >
631TStatement* parse_retro(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
632 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
6346015 q std::pair< uint, uint > line_col = token.line_col();
6356015 q ++token;
6376015 q clear_until_after(token, error_output, "(");
6386015 q TStatement* condition = parse_value_tree< TStatement >(stmt_factory, token, error_output, true,
6396015 q Statement::evaluator_expected, Statement::Single_Return_Type_Checker(Statement::string));
6406015 q clear_until_after(token, error_output, ")");
6416015 q std::vector< TStatement* > substatements =
6426015 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
6436015 q if (*token == ";")
6440 ++token;
6466015 q TStatement* statement = create_retro_statement< TStatement >(stmt_factory, line_col.first);
6476015 q if (condition)
6486015 q statement->add_statement(condition, "");
6496015 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
65015215 q it != substatements.end(); ++it)
6519214 q statement->add_statement(*it, "");
6526015 q return statement;
656template< class TStatement >
657TStatement* parse_timeline(typename TStatement::Factory& stmt_factory,
658 Tokenizer_Wrapper& token, Error_Output* error_output)
66014837 q std::pair< uint, uint > line_col = token.line_col();
66114837 q ++token;
66314837 q clear_until_after(token, error_output, "(");
66414837 q std::string type = get_text_token(token, error_output, "OSM base type");
66514837 q if (type == "rel")
6660 type = "relation";
66814837 q clear_until_after(token, error_output, ",");
66914837 q std::string ref = get_text_token(token, error_output, "OSM element id");
67014837 q clear_until_after(token, error_output, ",", ")", false);
67114837 q std::string version;
67214837 q if (*token == ",")
673246 q {
674246 q ++token;
675246 q version = get_text_token(token, error_output, "Number");
676246 q }
67714837 q clear_until_after(token, error_output, ")");
67914837 q std::string into = probe_into(token, error_output);
68014837 q clear_until_after(token, error_output, ";");
68214837 q return create_timeline_statement< TStatement >(stmt_factory, line_col.first, type, ref, version, into);
686template< class TStatement >
687TStatement* parse_compare(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
688 Tokenizer_Wrapper& token, const std::string& from, Error_Output* error_output, int depth)
6908421 q std::pair< uint, uint > line_col = token.line_col();
6918421 q ++token;
6938421 q TStatement* condition = 0;
6948421 q if (*token == "(")
6968020 q clear_until_after(token, error_output, "(");
6978020 q if (*token == "delta")
6997218 q clear_until_after(token, error_output, "delta");
7007218 q clear_until_after(token, error_output, ":");
7017218 q condition = parse_value_tree< TStatement >(stmt_factory, token, error_output, true,
7027218 q Statement::elem_eval_possible, Statement::Single_Return_Type_Checker(Statement::string));
7048020 q clear_until_after(token, error_output, ")");
7068421 q std::string into = probe_into(token, error_output);
7088421 q std::vector< TStatement* > substatements;
7098421 q if (*token == "(" || *token == "{")
7114411 q collect_substatements< TStatement >(stmt_factory, parsed_query, token, error_output, depth)
7124411 q .swap(substatements);
7134411 q if (*token == ";")
7140 ++token;
7164010 q else
7174010 q clear_until_after(token, error_output, ";");
7198421 q TStatement* statement = create_compare_statement< TStatement >(stmt_factory, line_col.first, from, into);
7208421 q if (condition)
7217218 q statement->add_statement(condition, "");
7228421 q for (typename std::vector< TStatement* >::const_iterator it = substatements.begin();
72313221 q it != substatements.end(); ++it)
7244811 q statement->add_statement(*it, "");
7268421 q return statement;
730template< class TStatement >
731TStatement* parse_output(typename TStatement::Factory& stmt_factory,
732 const std::string& from, Tokenizer_Wrapper& token, Error_Output* error_output)
73316032673 q{
73416032673 q TStatement* statement = 0;
73516032673 q if (*token == "out")
73616032673 q {
73716032673 q ++token;
73816032673 q std::string mode = "body";
73916032673 q std::string order = "id";
74016032673 q std::string limit = "";
74116032673 q std::string geometry = "skeleton";
74216032673 q std::string show_ids = "yes";
74316032673 q std::string south = "";
74416032673 q std::string north = "";
74516032673 q std::string west = "";
74616032673 q std::string east = "";
74737640673 q while (token.good() && *token != ";")
74821608657 q {
74921608657 q if (*token == "ids")
7506784648 q mode = "ids_only";
75114824657 q else if (*token == "tags")
752246 q mode = "tags";
75314800657 q else if (*token == "skel")
75410025 q mode = "skeleton";
75514700657 q else if (*token == "body")
7565213 q mode = "body";
75714648657 q else if (*token == "meta")
75816039 q mode = "meta";
75914488657 q else if (*token == "quirks")
76041 q mode = "quirks";
76114484657 q else if (*token == "count")
7626904650 q mode = "count";
7637580655 q else if (*token == "qt")
76420050 q order = "quadtile";
7657380655 q else if (*token == "asc")
7664411 q order = "id";
7677336655 q else if (*token == "geom")
76810827 q geometry = "full";
7697228652 q else if (*token == "bb")
7708821 q geometry = "bounds";
7717140652 q else if (*token == "center")
7726817 q geometry = "center";
7737072648 q else if (*token == "noids")
7745614 q show_ids = "no";
7757016648 q else if (isdigit((*token)[0]))
7766824648 q limit = *token;
77719248 q else if (*token == "(")
77819248 q {
77919248 q ++token;
78019248 q south = get_text_token(token, error_output, "Number");
78119248 q clear_until_after(token, error_output, ",");
78219248 q west = get_text_token(token, error_output, "Number");
78319248 q clear_until_after(token, error_output, ",");
78419248 q north = get_text_token(token, error_output, "Number");
78519248 q clear_until_after(token, error_output, ",");
78619248 q east = get_text_token(token, error_output, "Number");
78719248 q clear_until_after(token, error_output, ")", false);
78819248 q }
7890 else
7900 {
7910 if (error_output)
7920 error_output->add_parse_error
7930 (std::string("Invalid parameter for print: \"") + *token + "\"", token.line_col().first);
7940 }
79521608657 q ++token;
79621608657 q }
79816032673 q if (statement == 0)
79916032673 q {
80016032673 q statement = create_print_statement< TStatement >
80116032673 q (stmt_factory, from == "" ? "_" : from, mode, order, limit, geometry, show_ids,
80216032673 q south, north, west, east,
80316032673 q token.line_col().first);
80416032673 q }
8050 else
8060 {
8070 if (error_output)
8080 error_output->add_parse_error("Garbage after output statement found.",
8090 token.line_col().first);
8100 }
81116032673 q }
81216032673 q clear_until_after(token, error_output, ";");
81416032673 q return statement;
81516032673 q}
818struct No_Return_Type_Checker : Statement::Return_Type_Checker
8202216127 q No_Return_Type_Checker() {}
8222200127 q virtual bool eval_required() const { return false; }
8230 virtual bool matches(Statement::Eval_Return_Type eval_type) const { return false; }
8240 virtual std::string expectation() const { return Statement::eval_to_string(Statement::non_evaluator); }
825};
828template< class TStatement >
829TStatement* parse_make(typename TStatement::Factory& stmt_factory, const std::string& from,
830 Tokenizer_Wrapper& token, Error_Output* error_output, const std::string& strategy)
832632127 q TStatement* statement = 0;
833632127 q std::vector< TStatement* > evaluators;
834632127 q std::string type = "";
835632127 q if (*token == strategy)
837632127 q ++token;
838632127 q if (*token != ";")
839632127 q type = get_identifier_token(token, error_output, "Element class name");
841632127 q Token_Tree tree(token, error_output, false);
842632127 q if (tree.tree.size() > 1)
844632127 q Statement::QL_Context tree_context = (strategy == "convert" ? Statement::in_convert : Statement::generic);
845632127 q Token_Node_Ptr tree_it(tree, tree.tree[0].rhs);
8472216127 q while (tree_it->token == ",")
8481584115 q {
8491584115 q if (tree_it->rhs)
8501584115 q {
8511584115 q TStatement* stmt = stmt_factory.create_evaluator(tree_it.rhs(), tree_context, No_Return_Type_Checker());
8521584115 q if (stmt)
8531568114 q evaluators.push_back(stmt);
8541584115 q }
8561584115 q tree_it = tree_it.lhs();
8571584115 q }
859632127 q TStatement* stmt = stmt_factory.create_evaluator(tree_it, tree_context, No_Return_Type_Checker());
860632127 q if (stmt)
861632127 q evaluators.push_back(stmt);
863632127 q std::reverse(evaluators.begin(),evaluators.end());
866632127 q std::string into = probe_into(token, error_output);
868632127 q statement = create_make_statement< TStatement >(stmt_factory, strategy, from, into, type, token.line_col().first);
870632127 q for (typename std::vector< TStatement* >::const_iterator it = evaluators.begin();
8712832127 q it != evaluators.end(); ++it)
8722200127 q statement->add_statement(*it, "");
875632127 q clear_until_after(token, error_output, ";");
877632127 q return statement;
881template< class TStatement >
882TStatement* parse_localize(typename TStatement::Factory& stmt_factory,
883 Tokenizer_Wrapper& token, const std::string& from, Error_Output* error_output)
8858019 q uint line_col = token.line_col().first;
8868019 q ++token;
8888019 q std::string type = "l";
8898019 q if (*token != ";" && *token != "->" && *token != "(")
8916014 q type = *token;
8926014 q ++token;
8948019 q std::string south, north, west, east;
8958019 q if (*token == "(")
8960 {
8970 ++token;
8980 south = get_text_token(token, error_output, "Value");
8990 clear_until_after(token, error_output, ",", ")", false);
9000 if (*token == ",")
9010 {
9020 ++token;
9030 west = get_text_token(token, error_output, "Value");
9040 clear_until_after(token, error_output, ",", ")", false);
9050 }
9060 if (*token == ",")
9070 {
9080 ++token;
9090 north = get_text_token(token, error_output, "Value");
9100 clear_until_after(token, error_output, ",", ")", false);
9110 }
9120 if (*token == ",")
9130 {
9140 ++token;
9150 east = get_text_token(token, error_output, "Value");
9160 clear_until_after(token, error_output, ",", ")", false);
9170 }
9180 ++token;
9190 }
9218019 q std::string into = probe_into(token, error_output);
9228019 q clear_until_after(token, error_output, ";");
9248019 q return create_localize_statement< TStatement >(stmt_factory, type, from, into,
9258019 q south, north, west, east, line_col);
929struct Statement_Text
931 Statement_Text(std::string statement_ = "",
932 std::pair< uint, uint > line_col_ = std::make_pair(0, 0))
9332284374 q : statement(statement_), line_col(line_col_) {}
935 std::string statement;
936 std::pair< uint, uint > line_col;
937 std::vector< std::string > attributes;
938};
940template< class TStatement >
941TStatement* create_query_substatement
942 (typename TStatement::Factory& stmt_factory,
943 Tokenizer_Wrapper& token, Error_Output* error_output,
944 const Statement_Text& clause, std::string type, std::string from, std::string into)
9462284374 q if (clause.statement == "has-kv")
9471600298 q return create_has_kv_statement< TStatement >
9481600298 q (stmt_factory, clause.attributes[0], clause.attributes[1], haskv_plain, haskv_plain,
9491600298 q (clause.attributes[2] == ""), clause.line_col.first);
950684138 q else if (clause.statement == "has-kv_regex")
95146095 q return create_has_kv_statement< TStatement >
95246095 q (stmt_factory, clause.attributes[0], clause.attributes[1], haskv_regex, haskv_plain,
95346095 q (clause.attributes[2] == ""), clause.line_col.first);
95422450 q else if (clause.statement == "has-kv_icase")
955205 q return create_has_kv_statement< TStatement >
956205 q (stmt_factory, clause.attributes[0], clause.attributes[1], haskv_icase, haskv_plain,
957205 q (clause.attributes[2] == ""), clause.line_col.first);
95820445 q else if (clause.statement == "has-kv_keyregex_icase")
95941 q return create_has_kv_statement< TStatement >
96041 q (stmt_factory, clause.attributes[0], clause.attributes[1], haskv_icase, haskv_regex,
96141 q (clause.attributes[2] == ""), clause.line_col.first);
96220044 q else if (clause.statement == "has-kv_keyregex")
96320044 q return create_has_kv_statement< TStatement >
96420044 q (stmt_factory, clause.attributes[0], clause.attributes[1], haskv_regex, haskv_regex,
96520044 q (clause.attributes[2] == ""), clause.line_col.first);
9660 else if (clause.statement == "item")
9670 return create_item_statement< TStatement >
9680 (stmt_factory, clause.attributes[0], "_", clause.line_col.first);
9690 return 0;
972template< class TStatement >
973TStatement* parse_full_recurse(typename TStatement::Factory& stmt_factory,
974 Tokenizer_Wrapper& token, const std::string& from, Error_Output* error_output)
97637687 q std::string type = *token;
97737687 q uint line_col = token.line_col().first;
97837687 q ++token;
97937687 q std::string into = probe_into(token, error_output);
98037687 q clear_until_after(token, error_output, ";");
98237687 q if (type == ">")
98313632 q return create_recurse_statement< TStatement >(stmt_factory, "down", from, into, line_col);
98424057 q else if (type == ">>")
9856817 q return create_recurse_statement< TStatement >(stmt_factory, "down-rel", from, into, line_col);
98617241 q else if (type == "<")
98710025 q return create_recurse_statement< TStatement >(stmt_factory, "up", from, into, line_col);
9887218 q else if (type == "<<")
9897218 q return create_recurse_statement< TStatement >(stmt_factory, "up-rel", from, into, line_col);
9900 else
9910 return 0;
994template< class TStatement >
995TStatement* parse_coord_query(typename TStatement::Factory& stmt_factory,
996 Tokenizer_Wrapper& token, const std::string& from, Error_Output* error_output)
99820050 q std::string type = *token;
99920050 q uint line_col = token.line_col().first;
100020050 q ++token;
100220050 q std::string lat, lon;
100320050 q if (*token == "(")
10058421 q ++token;
10068421 q lat = get_text_token(token, error_output, "Number");
10078421 q clear_until_after(token, error_output, ",", ")", false);
10088421 q if (*token == ",")
10108421 q ++token;
10118421 q lon = get_text_token(token, error_output, "Number");
10128421 q clear_until_after(token, error_output, ")", false);
10148421 q ++token;
101620050 q std::string into = probe_into(token, error_output);
101720050 q clear_until_after(token, error_output, ";");
101920050 q return create_coord_query_statement< TStatement >(stmt_factory, lat, lon, from, into, line_col);
1022template< class TStatement >
1023TStatement* parse_map_to_area(typename TStatement::Factory& stmt_factory,
1024 Tokenizer_Wrapper& token, const std::string& from, Error_Output* error_output)
10267218 q std::string type = *token;
10277218 q uint line_col = token.line_col().first;
10287218 q ++token;
10307218 q std::string into = probe_into(token, error_output);
10317218 q clear_until_after(token, error_output, ";");
10337218 q return create_map_to_area_statement< TStatement >(stmt_factory, from, into, line_col);
1037template< class TStatement >
1038TStatement* parse_query(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
1039 const std::string& type, const std::string& from, Tokenizer_Wrapper& token,
1040 Error_Output* error_output)
10425060673 q std::pair< uint, uint > query_line_col = token.line_col();
10445060673 q std::vector< Statement_Text > clauses;
10455060673 q std::vector< Token_Tree > subtrees;
104610996673 q while (token.good() && (*token == "[" || *token == "(" || *token == "."))
10475936666 q {
10485936666 q if (*token == "[")
10492288374 q {
10502288374 q ++token;
10522288374 q bool key_regex = (*token == "~");
10532288374 q if (key_regex)
105420445 q ++token;
10562288374 q if (*token == "!") // [!key] as shortcut for [key !~ ".*"]
105810024 q ++token;
105910024 q std::string key = get_text_token(token, error_output, "Key");
106010024 q clear_until_after(token, error_output, "]");
106110024 q Statement_Text clause("has-kv_regex", token.line_col());
106210024 q clause.attributes.push_back(key);
106310024 q clause.attributes.push_back(".*");
106410024 q clause.attributes.push_back("!");
106510024 q clauses.push_back(clause);
106610024 q continue;
10692188362 q std::string key = get_text_token(token, error_output, "Key");
10702188362 q clear_until_after(token, error_output, "!", "~", "=", "!=", "]", false);
10722188362 q bool straight = true;
10732188362 q if (*token == "!")
107515237 q straight = false;
107615237 q ++token;
107715237 q clear_until_after(token, error_output, "~", "=", "]", false);
10802188362 q if (*token == "]")
108227256 q if (key_regex && error_output)
10830 error_output->add_parse_error(
10840 "A regular expression for a key can only be combined with a regular expression as value criterion",
10850 token.line_col().first);
108727256 q Statement_Text clause("has-kv", token.line_col());
108827256 q clause.attributes.push_back(key);
108927256 q clause.attributes.push_back("");
109027256 q clause.attributes.push_back(straight ? "" : "!");
109127256 q ++token;
109227256 q clauses.push_back(clause);
10941916332 q else if (*token == "=" || *token == "!=")
10951332261 q {
10961332261 q if (key_regex && error_output)
10970 error_output->add_parse_error(
10980 "A regular expression for a key can only be combined with a regular expression as value criterion",
10990 token.line_col().first);
11011332261 q straight = (*token == "=");
11021332261 q ++token;
11031332261 q if (token.good() && *token == "]")
110441 q ++token;
11051328260 q else
11061328260 q {
11071328260 q Statement_Text clause("has-kv", token.line_col());
11081328260 q clause.attributes.push_back(key);
11091328260 q clause.attributes.push_back(get_text_token(token, error_output, "Value"));
11101328260 q if (clause.attributes.back() != "")
11111328260 q {
11121328260 q clause.attributes.push_back(straight ? "" : "!");
11131328260 q clauses.push_back(clause);
11141328260 q }
11151328260 q clear_until_after(token, error_output, "]");
11161328260 q }
11171332261 q }
1118584121 q else //if (*token == "~")
1120584121 q if (key_regex)
112220445 q ++token;
112320445 q Statement_Text clause("has-kv_keyregex", token.line_col());
112420445 q clause.attributes.push_back(key);
112520445 q clause.attributes.push_back(get_text_token(token, error_output, "Value"));
112620445 q clause.attributes.push_back(straight ? "" : "!");
112720445 q clear_until_after(token, error_output, ",", "]", false);
112820445 q if (*token == ",")
113041 q clause.statement = "has-kv_keyregex_icase";
113141 q ++token;
113241 q clear_until_after(token, error_output, "i");
113341 q clear_until_after(token, error_output, "]", false);
113520445 q ++token;
113620445 q clauses.push_back(clause);
113838079 q else
114038079 q ++token;
114138079 q Statement_Text clause("has-kv_regex", token.line_col());
114238079 q clause.attributes.push_back(key);
114338079 q clause.attributes.push_back(get_text_token(token, error_output, "Value"));
114438079 q clause.attributes.push_back(straight ? "" : "!");
114538079 q clear_until_after(token, error_output, ",", "]", false);
114638079 q if (*token == ",")
1148205 q clause.statement = "has-kv_icase";
1149205 q ++token;
1150205 q clear_until_after(token, error_output, "i");
1151205 q clear_until_after(token, error_output, "]", false);
115338079 q ++token;
115438079 q clauses.push_back(clause);
11572188362 q }
11583648570 q else if (*token == "(")
11593648570 q {
11603648570 q ++token;
11613648570 q if (!token.good())
11620 {
11630 if (error_output)
11640 error_output->add_parse_error("':' or '.' expected.", token.line_col().first);
11650 break;
11660 }
11683648570 q subtrees.push_back(Token_Tree(token, error_output, true));
11693648570 q clear_until_after(token, error_output, ")");
11703648570 q }
11710 else
11720 {
11730 Statement_Text clause("item", token.line_col());
11740 clause.attributes.push_back(probe_from(token, error_output));
11750 clauses.push_back(clause);
11760 }
11775936666 q }
11795060673 q std::string into = probe_into(token, error_output);
11815060673 q TStatement* statement = 0;
11825060673 q if (clauses.empty() && subtrees.empty())
1184708133 q if (from == "")
11867619 q if (parsed_query.get_global_bbox_limitation().valid())
11881717 q statement = create_query_statement< TStatement >
11891717 q (stmt_factory, type, into, query_line_col.first);
11915919 q else if (error_output)
11925919 q error_output->add_parse_error("An empty query is not allowed", token.line_col().first);
1194632115 q else
1196632115 q if (type == "")
119744072 q statement = create_item_statement< TStatement >(stmt_factory, from, into, query_line_col.first);
119819246 q else
120019246 q statement = create_query_statement< TStatement >
120119246 q (stmt_factory, type, into, query_line_col.first);
120219246 q TStatement* substatement = create_item_statement< TStatement >(stmt_factory, from, "_", query_line_col.first);
120319246 q statement->add_statement(substatement, "");
12074352666 q else if (clauses.size() == 1 && from == "" && subtrees.empty())
1209772174 q if (clauses.front().statement == "has-kv"
1210772174 q || clauses.front().statement == "has-kv_regex"
1211772174 q || clauses.front().statement == "has-kv_keyregex"
1212772174 q || clauses.front().statement == "has-kv_icase"
1213772174 q || clauses.front().statement == "has-kv_keyregex_icase")
1215772174 q statement = create_query_statement< TStatement >
1216772174 q (stmt_factory, type, into, query_line_col.first);
1217772174 q TStatement* substatement = create_query_substatement< TStatement >
1218772174 q (stmt_factory, token, error_output, clauses.front(), type, from, "_");
1219772174 q if (substatement)
1220772174 q statement->add_statement(substatement, "");
12220 else
12230 {
12240 statement = create_query_substatement< TStatement >
12250 (stmt_factory, token, error_output, clauses.front(), type, from, into);
12260 }
12283580593 q else if (clauses.empty() && from == "" && subtrees.size() == 1)
12291996400 q {
12301996400 q bool can_standalone = false;
12311996400 q TStatement* filter = stmt_factory.create_criterion(
12321996400 q Token_Node_Ptr(subtrees[0], subtrees[0].tree[0].rhs), type, can_standalone, into);
12331996400 q if (filter)
12341992399 q {
12351992399 q if (can_standalone)
12361148246 q statement = filter;
1237844191 q else
1239844191 q statement = create_query_statement< TStatement >(stmt_factory, type, into, query_line_col.first);
1240844191 q statement->add_statement(filter, "");
12421992399 q }
12431996400 q }
12441584336 q else
12451584336 q {
12461584336 q statement = create_query_statement< TStatement >(stmt_factory, type, into, query_line_col.first);
12471584336 q if (!statement)
12480 return 0;
12501584336 q if (from != "")
125223654 q TStatement* substatement = create_item_statement< TStatement >
125323654 q (stmt_factory, from, "_", query_line_col.first);
125423654 q if (substatement)
125523654 q statement->add_statement(substatement, "");
12581584336 q for (std::vector< Statement_Text >::const_iterator it = clauses.begin();
12593096336 q it != clauses.end(); ++it)
12601512246 q {
12611512246 q TStatement* substatement = create_query_substatement< TStatement >
12621512246 q (stmt_factory, token, error_output, *it, type, from, "_");
12631512246 q if (substatement)
12641512246 q statement->add_statement(substatement, "");
12651512246 q }
12663236336 q for (typename std::vector< Token_Tree >::const_iterator it = subtrees.begin(); it != subtrees.end(); ++it)
12671652290 q {
12681652290 q bool can_standalone = false;
12691652290 q TStatement* filter = stmt_factory.create_criterion(
12701652290 q Token_Node_Ptr(*it, it->tree[0].rhs), type, can_standalone, "_");
12711652290 q if (filter)
12721644288 q statement->add_statement(filter, "");
12731652290 q }
12741584336 q }
12755060673 q clear_until_after(token, error_output, ";");
12775060673 q return statement;
1281template< class TStatement >
1282TStatement* parse_statement(typename TStatement::Factory& stmt_factory, Parsed_Query& parsed_query,
1283 Tokenizer_Wrapper& token, Error_Output* error_output, int depth)
128423856683 q{
128523856683 q if (!token.good())
12860 return 0;
128823856683 q if (depth >= 1024)
12890 {
12900 if (error_output)
12910 error_output->add_parse_error("Nesting of statements is limited to 1023 levels", token.line_col().first);
12920 return 0;
12930 }
129523856683 q if (*token == "(")
1296512114 q return parse_union< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
129723344682 q else if (*token == "for")
12987619 q return parse_for< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
129923268682 q else if (*token == "foreach")
130011628 q return parse_foreach< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
130123152681 q else if (*token == "complete")
130233269 q return parse_complete< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
130322820681 q else if (*token == "if")
13047617 q return parse_if< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
130522744681 q else if (*token == "retro")
13066015 q return parse_retro< TStatement >(stmt_factory, parsed_query, token, error_output, depth);
130722684681 q else if (*token == "timeline")
130814837 q return parse_timeline< TStatement >(stmt_factory, token, error_output);
131022536681 q std::string from = "";
131122536681 q if (token.good() && *token == ".")
131217312649 q {
131317312649 q ++token;
131417312649 q if (token.good())
131517312649 q {
131617312649 q from = *token;
131717312649 q ++token;
131817312649 q }
131917312649 q }
132122536681 q if (token.good() && *token == "out")
132216032673 q return parse_output< TStatement >(stmt_factory, from, token, error_output);
13236504677 q else if (token.good() && *token == "convert")
132434079 q return parse_make< TStatement >(stmt_factory, from, token, error_output, "convert");
13256164677 q else if (token.good() && *token == "make")
132629263 q return parse_make< TStatement >(stmt_factory, from, token, error_output, "make");
13275872676 q else if (token.good() && (*token == "<" || *token == "<<" || *token == ">" || *token == ">>"))
132837687 q return parse_full_recurse< TStatement >(stmt_factory, token, from, error_output);
13295496676 q else if (token.good() && *token == "is_in")
133020050 q return parse_coord_query< TStatement >(stmt_factory, token, from, error_output);
13315296673 q else if (token.good() && *token == "map_to_area")
13327218 q return parse_map_to_area< TStatement >(stmt_factory, token, from, error_output);
13335224673 q else if (token.good() && *token == "local")
13348019 q return parse_localize< TStatement >(stmt_factory, token, from, error_output);
13355144673 q else if (token.good() && *token == "compare")
13368421 q return parse_compare< TStatement >(stmt_factory, parsed_query, token, from, error_output, depth);
13385060673 q std::string type = "";
13395060673 q if (*token != "out" && from == "")
13404620672 q {
13414620672 q type = *token;
13424620672 q if (type == "rel")
1343928198 q type = "relation";
13443692591 q else if (type != "node" && type != "way" && type != "relation"
13453692591 q && type != "nwr" && type != "nw" && type != "wr" && type != "nr"
13463692591 q && type != "derived" && type != "area")
134841 q if (error_output)
134941 q error_output->add_parse_error("Unknown type \"" + type + "\"", token.line_col().first);
13514620672 q ++token;
13524620672 q }
13535060673 q if (token.good() && *token == ".")
135542897 q ++token;
135642897 q if (token.good())
135842897 q from = *token;
135942897 q ++token;
13635060673 q return parse_query< TStatement >(stmt_factory, parsed_query, type, from, token, error_output);
136422536681 q}
1367template< class TStatement >
1368void generic_parse_and_validate_map_ql
1369 (typename TStatement::Factory& stmt_factory,
1370 const std::string& xml_raw, Error_Output* error_output, std::vector< TStatement* >& stmt_seq, Parsed_Query& parsed_query)
13722736684 q std::istringstream in(xml_raw);
13732736684 q Tokenizer_Wrapper token(in);
13752736684 q std::map< std::string, std::string > attr;
13764572684 q while (token.good() && *token == "[")
13771836352 q {
13781836352 q std::vector< std::string > kv = parse_setup(token, error_output, parsed_query);
13791836352 q if (kv.size() < 2)
13800 continue;
13811836352 q if (kv[0] == "maxsize")
1382123 q kv[0] = "element-limit";
13831824352 q else if (kv[0] == "out")
1384516129 q kv[0] = "output";
13851308298 q else if (kv[0] == "diff" || kv[0] == "adiff")
138732481 q if (kv[0] == "adiff")
138813233 q attr["augmented"] = "deletions";
138932481 q if (kv.size() >= 3)
13909223 q attr["date"] = kv[2];
139132481 q kv[0] = "from";
13931836352 q attr[kv[0]] = kv[1];
13941836352 q if (kv.size() == 4)
1395516129 q attr[kv[2]] = kv[3];
13961836352 q }
13982736684 q TStatement* base_statement = stmt_factory.create_statement
13992736684 q ("osm-script", token.line_col().first, attr);
14012736684 q if (!attr.empty())
14021408352 q clear_until_after(token, error_output, ";");
140425432684 q while (token.good())
140522696683 q {
140622696683 q std::pair< uint, uint > pos_before = token.line_col();
140722696683 q TStatement* statement = parse_statement< TStatement >(stmt_factory, parsed_query, token, error_output, 0);
140822696683 q if (statement)
140922633682 q base_statement->add_statement(statement, "");
14106320 q else if (token.line_col() == pos_before)
14110 break;
141222696683 q }
14142736684 q stmt_seq.push_back(base_statement);
1418void parse_and_validate_map_ql
1419 (Statement::Factory& stmt_factory, const std::string& xml_raw, Error_Output* error_output, Parsed_Query& parsed_query)
1421684684 q generic_parse_and_validate_map_ql< Statement >
1422684684 q (stmt_factory, xml_raw, error_output, *get_statement_stack(), parsed_query);
1425void parse_and_dump_xml_from_map_ql
1426 (Statement::Factory& stmt_factory_, const std::string& xml_raw, Error_Output* error_output, Parsed_Query& parsed_query)
1428684684 q Statement_Dump::Factory stmt_factory(stmt_factory_);
1429684684 q std::vector< Statement_Dump* > stmt_seq;
1430684684 q generic_parse_and_validate_map_ql< Statement_Dump >(stmt_factory, xml_raw, error_output, stmt_seq, parsed_query);
1431684684 q for (std::vector< Statement_Dump* >::const_iterator it = stmt_seq.begin();
14321368684 q it != stmt_seq.end(); ++it)
1433684684 q std::cout<<(*it)->dump_xml();
1434684684 q for (std::vector< Statement_Dump* >::iterator it = stmt_seq.begin();
14351368684 q it != stmt_seq.end(); ++it)
1436684684 q delete *it;
1439void parse_and_dump_compact_from_map_ql
1440 (Statement::Factory& stmt_factory_, const std::string& xml_raw, Error_Output* error_output, Parsed_Query& parsed_query)
1442684684 q Statement_Dump::Factory stmt_factory(stmt_factory_);
1443684684 q std::vector< Statement_Dump* > stmt_seq;
1444684684 q generic_parse_and_validate_map_ql< Statement_Dump >(stmt_factory, xml_raw, error_output, stmt_seq, parsed_query);
1445684684 q for (std::vector< Statement_Dump* >::const_iterator it = stmt_seq.begin();
14461368684 q it != stmt_seq.end(); ++it)
1447684684 q std::cout<<(*it)->dump_compact_map_ql(stmt_factory_)<<'\n';
1448684684 q for (std::vector< Statement_Dump* >::iterator it = stmt_seq.begin();
14491368684 q it != stmt_seq.end(); ++it)
1450684684 q delete *it;
1453void parse_and_dump_bbox_from_map_ql
1454 (Statement::Factory& stmt_factory_, const std::string& xml_raw, Error_Output* error_output, Parsed_Query& parsed_query)
14560 Statement_Dump::Factory stmt_factory(stmt_factory_);
14570 std::vector< Statement_Dump* > stmt_seq;
14580 generic_parse_and_validate_map_ql< Statement_Dump >(stmt_factory, xml_raw, error_output, stmt_seq, parsed_query);
14590 for (std::vector< Statement_Dump* >::const_iterator it = stmt_seq.begin();
14600 it != stmt_seq.end(); ++it)
14610 std::cout<<(*it)->dump_bbox_map_ql(stmt_factory_)<<'\n';
14620 for (std::vector< Statement_Dump* >::iterator it = stmt_seq.begin();
14630 it != stmt_seq.end(); ++it)
14640 delete *it;
1467void parse_and_dump_pretty_from_map_ql
1468 (Statement::Factory& stmt_factory_, const std::string& xml_raw, Error_Output* error_output, Parsed_Query& parsed_query)
1470684684 q Statement_Dump::Factory stmt_factory(stmt_factory_);
1471684684 q std::vector< Statement_Dump* > stmt_seq;
1472684684 q generic_parse_and_validate_map_ql< Statement_Dump >(stmt_factory, xml_raw, error_output, stmt_seq, parsed_query);
1473684684 q for (std::vector< Statement_Dump* >::const_iterator it = stmt_seq.begin();
14741368684 q it != stmt_seq.end(); ++it)
1475684684 q std::cout<<(*it)->dump_pretty_map_ql(stmt_factory_);
1476684684 q for (std::vector< Statement_Dump* >::iterator it = stmt_seq.begin();
14771368684 q it != stmt_seq.end(); ++it)
1478684684 q delete *it;