• 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 VERIFICATION_CONFIG_HANDLERS_LITERAL_PARSER_H
17 #define VERIFICATION_CONFIG_HANDLERS_LITERAL_PARSER_H
18 
19 #include "runtime/include/mem/panda_containers.h"
20 #include "runtime/include/mem/panda_string.h"
21 #include "verification/util/parser/parser.h"
22 
23 #include <string>
24 
25 namespace panda::verifier::debug {
26 
27 template <typename Parser, typename Handler>
LiteralParser(Handler & handler)28 const auto &LiteralParser(Handler &handler)
29 {
30     using panda::parser::action;
31     using panda::parser::charset;
32     using panda::parser::parser;
33 
34     struct Literal;
35 
36     using p = typename Parser::template next<Literal>;
37 
38     static const auto LITERAL_NAME_HANDLER = [&](action a, typename p::Ctx &c, auto from, auto to) {
39         if (a == action::PARSED) {
40             return handler(c, PandaString {from, to});
41         }
42         return true;
43     };
44 
45     static const auto LITERAL_NAME = p::of_charset(charset {"abcdefghijklmnopqrstuvwxyz_-"}) |= LITERAL_NAME_HANDLER;
46 
47     return LITERAL_NAME;
48 }
49 
LiteralsParser()50 inline const auto &LiteralsParser()
51 {
52     using panda::parser::action;
53     using panda::parser::charset;
54     using panda::parser::parser;
55 
56     struct Literals;
57 
58     using Context = PandaVector<PandaString>;
59 
60     using p = typename parser<Context, const char, const char *>::template next<Literals>;
61     using p1 = typename p::p;
62     using p2 = typename p1::p;
63 
64     static const auto WS = p::of_charset(" \t");
65     static const auto COMMA = p1::of_charset(",");
66 
67     static const auto LITERAL_HANDLER = [](Context &c, PandaString &&str) {
68         c.emplace_back(std::move(str));
69         return true;
70     };
71 
72     static const auto LITERALS = ~WS >> *(~WS >> LiteralParser<p2>(LITERAL_HANDLER) >> ~WS >> ~COMMA) >> p::end();
73 
74     return LITERALS;
75 }
76 
77 }  // namespace panda::verifier::debug
78 
79 #endif  // VERIFICATION_CONFIG_HANDLERS_LITERAL_PARSER_H
80