/root/doris/be/src/geo/wkt_parse.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "geo/wkt_parse.h" |
19 | | |
20 | | #include <utility> |
21 | | |
22 | | #include "geo/wkt_lex.l.h" |
23 | | #include "geo/wkt_parse_ctx.h" |
24 | | #include "geo/wkt_parse_type.h" // IWYU pragma: keep |
25 | | #include "geo/wkt_yacc.y.hpp" |
26 | | |
27 | | extern int wkt_lex_init_extra(WktParseContext*, yyscan_t*); |
28 | | |
29 | | namespace doris { |
30 | | #include "common/compile_check_avoid_begin.h" |
31 | | |
32 | 160 | GeoParseStatus WktParse::parse_wkt(const char* str, size_t len, std::unique_ptr<GeoShape>& shape) { |
33 | 160 | WktParseContext ctx; |
34 | | |
35 | 160 | if (wkt_parse(str, len, ctx) == GEO_PARSE_OK) { |
36 | 145 | shape = std::move(ctx.shape); |
37 | 145 | } else if (ctx.parse_status == GEO_PARSE_OK) { |
38 | | /// For Syntax errors(e.g., `POIN(1 2)`, `POINT(1, 2)`) |
39 | | /// wkt_parse won't set parse_status, so we need to set it here. |
40 | | /// For semantic errors (e.g., invalid coordinates) |
41 | | /// wkt_parse will be set to GEO_PARSE_COORD_INVALID |
42 | 9 | ctx.parse_status = GEO_PARSE_WKT_SYNTAX_ERROR; |
43 | 9 | } |
44 | 160 | return ctx.parse_status; |
45 | 160 | } |
46 | | |
47 | 160 | int WktParse::wkt_parse(const char* str, size_t len, WktParseContext& ctx) { |
48 | 160 | wkt_lex_init_extra(&ctx, &ctx.scaninfo); |
49 | 160 | YY_BUFFER_STATE buffer = wkt__scan_bytes(str, len, ctx.scaninfo); |
50 | | |
51 | 160 | wkt_::parser parser(&ctx, ctx.scaninfo); |
52 | 160 | int res = parser.parse(); |
53 | 160 | wkt__delete_buffer(buffer, ctx.scaninfo); |
54 | 160 | wkt_lex_destroy(ctx.scaninfo); |
55 | 160 | return res; |
56 | 160 | } |
57 | | |
58 | | #include "common/compile_check_avoid_end.h" |
59 | | } // namespace doris |