/* This file is part of TON Blockchain Library. TON Blockchain Library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. TON Blockchain Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . Copyright 2017-2019 Telegram Systems LLP */ #pragma once #include "tl_core.h" #include "tl_simple_parser.h" #include #include #include #include #include namespace td { namespace tl { class tl_config { std::vector types; std::map id_to_type; std::map name_to_type; std::vector functions; std::map id_to_function; std::map name_to_function; public: void add_type(tl_type *type); tl_type *get_type(std::int32_t type_id) const; tl_type *get_type(const std::string &type_name); void add_function(tl_combinator *function); tl_combinator *get_function(std::int32_t function_id); tl_combinator *get_function(const std::string &function_name); std::size_t get_type_count() const; tl_type *get_type_by_num(std::size_t num) const; std::size_t get_function_count() const; tl_combinator *get_function_by_num(std::size_t num) const; }; class tl_config_parser { tl_simple_parser p; int schema_version; tl_config config; static int get_schema_version(std::int32_t version_id); tl_tree *read_num_const(); tl_tree *read_num_var(int *var_count); tl_tree *read_type_var(int *var_count); tl_tree *read_array(int *var_count); tl_tree *read_type(int *var_count); tl_tree *read_type_expr(int *var_count); tl_tree *read_nat_expr(int *var_count); tl_tree *read_expr(int *var_count); std::vector read_args_list(int *var_count); tl_combinator *read_combinator(); tl_type *read_type(); template T try_parse(const T &res) const; std::int32_t try_parse_int(); std::int64_t try_parse_long(); std::string try_parse_string(); public: tl_config_parser(const char *s, std::size_t len) : p(s, len), schema_version(-1) { } tl_config parse_config(); }; } // namespace tl } // namespace td