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_VKSCRIPT_PARSER_H_ 16 #define SRC_VKSCRIPT_PARSER_H_ 17 18 #include <memory> 19 #include <string> 20 #include <utility> 21 22 #include "amber/result.h" 23 #include "src/parser.h" 24 #include "src/script.h" 25 #include "src/tokenizer.h" 26 #include "src/vkscript/section_parser.h" 27 28 namespace amber { 29 namespace vkscript { 30 31 /// Parser for the `VkScript` data format. 32 class Parser : public amber::Parser { 33 public: 34 Parser(); 35 explicit Parser(Delegate* delegate); 36 ~Parser() override; 37 38 // amber::Parser 39 Result Parse(const std::string& data) override; 40 SkipValidationForTest()41 void SkipValidationForTest() { skip_validation_for_test_ = true; } 42 43 private: 44 bool skip_validation_for_test_ = false; 45 46 std::string make_error(const Tokenizer& tokenizer, const std::string& err); 47 Result GenerateDefaultPipeline(const SectionParser& section_parser); 48 Result ProcessSection(const SectionParser::Section& section); 49 Result ProcessShaderBlock(const SectionParser::Section& section); 50 Result ProcessRequireBlock(const SectionParser::Section& section); 51 Result ProcessIndicesBlock(const SectionParser::Section& section); 52 Result ProcessVertexDataBlock(const SectionParser::Section& section); 53 Result ProcessTestBlock(const SectionParser::Section& section); 54 }; 55 56 } // namespace vkscript 57 } // namespace amber 58 59 #endif // SRC_VKSCRIPT_PARSER_H_ 60