// // Copyright RIME Developers // Distributed under the BSD License // #ifndef RIME_CONFIG_COMPILER_H_ #define RIME_CONFIG_COMPILER_H_ #include #include #include #include namespace rime { struct ConfigResource : ConfigItemRef { string resource_id; an data; bool loaded = false; ConfigResource(const string& _id, an _data) : ConfigItemRef(nullptr), resource_id(_id), data(_data) {} an GetItem() const override { return data->root; } void SetItem(an item) override { data->root = item; } }; struct Reference { string resource_id; string local_path; bool optional; string repr() const; }; std::ostream& operator<<(std::ostream& stream, const Reference& reference); class ConfigCompilerPlugin; class ResourceResolver; struct Dependency; struct ConfigDependencyGraph; class ConfigCompiler { public: static constexpr const char* INCLUDE_DIRECTIVE = "__include"; static constexpr const char* PATCH_DIRECTIVE = "__patch"; static constexpr const char* APPEND_DIRECTIVE = "__append"; static constexpr const char* MERGE_DIRECTIVE = "__merge"; ConfigCompiler(ResourceResolver* resource_resolver, ConfigCompilerPlugin* plugin); virtual ~ConfigCompiler(); Reference CreateReference(const string& qualified_path); void AddDependency(an dependency); void Push(an resource); void Push(an config_list, size_t index); void Push(an config_map, const string& key); bool Parse(const string& key, const an& item); void Pop(); void EnumerateResources( function resource)> process_resource); an GetCompiledResource(const string& resource_id) const; an Compile(const string& file_name); bool Link(an target); bool blocking(const string& full_path) const; bool pending(const string& full_path) const; bool resolved(const string& full_path) const; vector> GetDependencies(const string& path); bool ResolveDependencies(const string& path); private: ResourceResolver* resource_resolver_; ConfigCompilerPlugin* plugin_; the graph_; }; } // namespace rime #endif // RIME_CONFIG_COMPILER_H_