• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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_LITERAL_PARSER_H_
17 #define PANDA_VERIFIER_DEBUG_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 ark::verifier::debug {
26 
27 template <typename Parser, typename Handler>
LiteralParser(Handler & handler)28 const auto &LiteralParser(Handler &handler)
29 {
30     using ark::parser::Action;
31     using ark::parser::Charset;
32     // using ark::parser::Parser;
33 
34     struct Literal;
35 
36     using P = typename Parser::template Next<Literal>;
37 
38     // NOLINTNEXTLINE(readability-identifier-naming)
39     static const auto literalNameHandler = [&handler](Action a, typename P::Ctx &c, auto from, auto to) {
40         if (a == Action::PARSED) {
41             return handler(c, PandaString {from, to});
42         }
43         return true;
44     };
45     // NOLINTNEXTLINE(readability-identifier-naming)
46     static const auto literalName = P::OfCharset(Charset {"abcdefghijklmnopqrstuvwxyz_-"}) |= literalNameHandler;
47     return literalName;
48 }
49 
LiteralsParser()50 inline const auto &LiteralsParser()
51 {
52     using ark::parser::Parser;
53     using P = typename Parser<PandaVector<PandaString>, const char, const char *>::template Next<struct Literals>;
54 
55     static const auto LITERAL_HANDLER = [](PandaVector<PandaString> &c, PandaString &&str) {
56         c.emplace_back(std::move(str));
57         return true;
58     };
59 
60     static const auto WS = P::OfCharset(" \t");
61     static const auto LITERALS =
62         ~WS >> *(~WS >> LiteralParser<P::P::P>(LITERAL_HANDLER) >> ~WS >> ~P::P::OfCharset(",")) >> P::End();
63     return LITERALS;
64 }
65 
66 }  // namespace ark::verifier::debug
67 
68 #endif  // !PANDA_VERIFIER_DEBUG_LITERAL_PARSER_H_
69