scenario_simulator_v2 C++ API
function_call_expression.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSCENARIO_INTERPRETER__REGEX__FUNCTION_CALL_EXPRESSION_HPP_
16 #define OPENSCENARIO_INTERPRETER__REGEX__FUNCTION_CALL_EXPRESSION_HPP_
17 
18 #include <regex>
19 
21 {
22 inline namespace regex
23 {
25 {
26  /* ---- NOTE ---------------------------------------------------------------
27  *
28  * function(foo, &quot;hello, world!&quot;, 3.14)
29  *
30  * result[0] = function(foo, "hello, world!", 3.14)
31  * result[1] = function
32  * result[2] = (foo, "hello, world!", 3.14)
33  * result[3] = foo, "hello, world!", 3.14
34  *
35  * ---------------------------------------------------------------------- */
36  static auto pattern() -> const auto &
37  {
38  static const auto pattern =
39  std::regex(R"(^([\w@]+)(\‍(((?:(?:[^\‍("\s,\)]+|\"[^"]*\"),?\s*)*)\))?$)");
40  return pattern;
41  }
42 
43  static auto splitParameters(const std::string & s) -> std::vector<std::string>
44  {
45  static const auto pattern = std::regex(R"(([^\‍("\s,\)]+|\"[^"]*\"),?\s*)");
46 
47  std::vector<std::string> args;
48 
49  for (auto iter = std::sregex_iterator(std::begin(s), std::end(s), pattern);
50  iter != std::sregex_iterator(); ++iter) {
51  args.emplace_back((*iter)[1]);
52  }
53 
54  return args;
55  }
56 };
57 } // namespace regex
58 } // namespace openscenario_interpreter
59 
60 #endif // OPENSCENARIO_INTERPRETER__REGEX__FUNCTION_CALL_EXPRESSION_HPP_
Definition: hypot.hpp:22
std::string string
Definition: junit5.hpp:26
Definition: function_call_expression.hpp:25
static auto splitParameters(const std::string &s) -> std::vector< std::string >
Definition: function_call_expression.hpp:43
static auto pattern() -> const auto &
Definition: function_call_expression.hpp:36