1 // Copyright 2018 The Amber Authors. 2 // 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 #ifndef SRC_PARSER_H_ 16 #define SRC_PARSER_H_ 17 18 #include <memory> 19 #include <string> 20 #include <utility> 21 22 #include "amber/result.h" 23 #include "src/script.h" 24 25 namespace amber { 26 27 /// Base class for an input parser. 28 class Parser { 29 public: 30 virtual ~Parser(); 31 32 /// Run the parser against |data|. The result is success if the parse 33 /// completes correctly. 34 virtual Result Parse(const std::string& data) = 0; 35 36 /// Retrieve the script which is generated by the parser. GetScript()37 std::unique_ptr<Script> GetScript() { return std::move(script_); } 38 39 protected: 40 explicit Parser(Delegate* delegate); 41 42 std::unique_ptr<Script> script_; 43 Delegate* delegate_ = nullptr; 44 }; 45 46 } // namespace amber 47 48 #endif // SRC_PARSER_H_ 49