#ifndef tree_sitter_compiler_h #define tree_sitter_compiler_h #include #include #include #include #include namespace tree_sitter { namespace rules { class Rule; class Symbol; struct CharacterRange { char min; char max; CharacterRange(char); CharacterRange(char, char); bool operator==(const CharacterRange &) const; bool operator<(const CharacterRange &) const; std::string to_string() const; }; } } namespace std { template<> struct hash { size_t operator()(const tree_sitter::rules::CharacterRange &range) const { return (hash()(range.min) ^ hash()(range.max)); } }; } namespace tree_sitter { namespace rules { typedef std::shared_ptr rule_ptr; std::ostream& operator<<(std::ostream& stream, const rule_ptr &rule); rule_ptr blank(); rule_ptr character(const std::set &matches); rule_ptr character(const std::set &matches, bool); rule_ptr choice(const std::vector &rules); rule_ptr pattern(const std::string &value); rule_ptr repeat(const rule_ptr content); rule_ptr seq(const std::vector &rules); rule_ptr str(const std::string &value); rule_ptr sym(const std::string &name); rule_ptr _sym(const std::string &name); } } namespace tree_sitter { class Grammar { public: Grammar(std::string start_rule_name, const std::map &rules); bool operator==(const Grammar &other) const; const std::string start_rule_name; const std::map rules; }; std::ostream& operator<<(std::ostream &stream, const Grammar &grammar); std::string compile(const Grammar &grammar, std::string name); } #endif