1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef avro_Compiler_hh__ 20 #define avro_Compiler_hh__ 21 22 #include "Config.hh" 23 #include <cstdint> 24 #include <istream> 25 26 namespace avro { 27 28 class AVRO_DECL InputStream; 29 30 /// This class is used to implement an avro spec parser using a flex/bison 31 /// compiler. In order for the lexer to be reentrant, this class provides a 32 /// lexer object for each parse. The bison parser also uses this class to 33 /// build up an avro parse tree as the avro spec is parsed. 34 35 class AVRO_DECL ValidSchema; 36 37 /// Given a stream containing a JSON schema, compiles the schema to a 38 /// ValidSchema object. Throws if the schema cannot be compiled to a valid 39 /// schema 40 41 AVRO_DECL void compileJsonSchema(std::istream &is, ValidSchema &schema); 42 43 /// Non-throwing version of compileJsonSchema. 44 /// 45 /// \return True if no error, false if error (with the error string set) 46 /// 47 48 AVRO_DECL bool compileJsonSchema(std::istream &is, ValidSchema &schema, 49 std::string &error); 50 51 AVRO_DECL ValidSchema compileJsonSchemaFromStream(InputStream &is); 52 53 AVRO_DECL ValidSchema compileJsonSchemaFromMemory(const uint8_t *input, size_t len); 54 55 AVRO_DECL ValidSchema compileJsonSchemaFromString(const char *input); 56 57 AVRO_DECL ValidSchema compileJsonSchemaFromString(const std::string &input); 58 59 AVRO_DECL ValidSchema compileJsonSchemaFromFile(const char *filename); 60 61 } // namespace avro 62 63 #endif 64