• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
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 
16 #ifndef PANDA_VERIFIER_DEBUG_METHOD_GROUP_PARSER_H_
17 #define PANDA_VERIFIER_DEBUG_METHOD_GROUP_PARSER_H_
18 
19 #include "verification/util/parser/parser.h"
20 #include "runtime/include/mem/panda_string.h"
21 
22 namespace panda::verifier {
23 
24 template <typename Parser, typename RegexHandler>
MethodGroupParser(RegexHandler & regex_handler)25 const auto &MethodGroupParser(RegexHandler &regex_handler)
26 {
27     using panda::parser::action;
28     using panda::parser::charset;
29     using panda::parser::parser;
30 
31     struct MethodGroup;
32 
33     using p = typename Parser::template next<MethodGroup>;
34     using p1 = typename p::p;
35 
36     static const auto QUOTE = p::of_string("'");
37     static const auto NON_QUOTES = p1::of_charset(!charset("'"));
38 
39     static const auto REGEX_HANDLER = [&](action a, typename p::Ctx &c, auto from, auto to) {
40         if (a == action::PARSED) {
41             auto *start = from;
42             ++start;
43             auto *end = to;
44             --end;
45             return regex_handler(c, PandaString {start, end});
46         }
47         return true;
48     };
49 
50     static const auto REGEX = QUOTE >> NON_QUOTES >> QUOTE |= REGEX_HANDLER;
51 
52     return REGEX;
53 }
54 
55 }  // namespace panda::verifier
56 
57 #endif  //! PANDA_VERIFIER_DEBUG_METHOD_GROUP_PARSER_H_
58