1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HC_GEN_PARSER_H 10 #define HC_GEN_PARSER_H 11 12 #include <memory> 13 14 #include "ast.h" 15 #include "lexer.h" 16 17 namespace OHOS { 18 namespace Hardware { 19 20 class Parser { 21 public: 22 Parser() = default; 23 24 ~Parser() = default; 25 26 bool Parse(); 27 28 std::list<std::shared_ptr<Ast>> ParseOne(const std::string &src); 29 30 std::shared_ptr<AstObject> ParseOneContent(const std::string &src, std::list<std::string> &includeList); 31 32 std::shared_ptr<Ast> GetAst(); 33 34 private: 35 bool ProcessInclude(std::list<std::string> &includeList); 36 37 bool CheckCycleInclude(const std::string &includeSrc); 38 39 std::shared_ptr<AstObject> ParseTemplate(); 40 41 std::shared_ptr<AstObject> ParseNodeAndTerm(); 42 43 std::shared_ptr<AstObject> ParseNodeCopy(Token &name); 44 45 std::shared_ptr<AstObject> ParseNodeRef(Token &name); 46 47 std::shared_ptr<AstObject> ParseNodeDelete(Token &name); 48 49 std::shared_ptr<AstObject> ParseNodeInherit(Token &name); 50 51 std::shared_ptr<AstObject> ParseNode(Token &name, bool bracesStart = false); 52 53 std::shared_ptr<AstObject> ParseTerm(Token &name); 54 55 std::shared_ptr<AstObject> ParseNodeWithRef(Token name); 56 57 std::shared_ptr<AstObject> ParseArray(); 58 59 void CleanError(); 60 61 Lexer lexer_; 62 Token current_; 63 std::shared_ptr<Ast> ast_; 64 std::list<std::string> srcQueue_; 65 uint32_t errno_ = NOERR; 66 }; 67 68 } // namespace Hardware 69 } // namespace OHOS 70 #endif // HC_GEN_PARSER_H 71