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::shared_ptr<Ast> ParseOne(const std::string &src, std::list<std::string> &includeList); 29 30 std::shared_ptr<Ast> GetAst(); 31 32 private: 33 bool ProcessInclude(std::list<std::string> &includeList); 34 35 std::shared_ptr<AstObject> ParseTemplate(); 36 37 std::shared_ptr<AstObject> ParseNodeAndTerm(); 38 39 std::shared_ptr<AstObject> ParseNodeCopy(Token &name); 40 41 std::shared_ptr<AstObject> ParseNodeRef(Token &name); 42 43 std::shared_ptr<AstObject> ParseNodeDelete(Token &name); 44 45 std::shared_ptr<AstObject> ParseNodeInherit(Token &name); 46 47 std::shared_ptr<AstObject> ParseNode(Token &name, bool bracesStart = false); 48 49 std::shared_ptr<AstObject> ParseTerm(Token &name); 50 51 std::shared_ptr<AstObject> ParseNodeWithRef(Token name); 52 53 std::shared_ptr<AstObject> ParseArray(); 54 55 Lexer lexer_; 56 Token current_; 57 std::shared_ptr<Ast> ast_; 58 std::list<std::string> srcQueue_; 59 }; 60 61 } // namespace Hardware 62 } // namespace OHOS 63 #endif // HC_GEN_PARSER_H 64