tree-sitter/src/compiler/rules/rule.h

39 lines
1 KiB
C
Raw Normal View History

2014-03-09 22:05:17 -07:00
#ifndef COMPILER_RULES_RULE_H_
#define COMPILER_RULES_RULE_H_
2013-11-07 13:24:01 -08:00
#include <string>
#include <memory>
2013-11-07 13:24:01 -08:00
namespace tree_sitter {
namespace rules {
2013-12-19 23:16:13 -08:00
class Visitor;
2014-01-02 13:04:41 -08:00
class Rule;
typedef std::shared_ptr<Rule> rule_ptr;
2013-11-07 13:24:01 -08:00
class Rule {
public:
virtual bool operator==(const Rule& other) const = 0;
bool operator!=(const Rule& other) const;
2013-12-30 23:52:38 -08:00
virtual size_t hash_code() const = 0;
2014-01-02 13:04:41 -08:00
virtual rule_ptr copy() const = 0;
2013-11-07 13:24:01 -08:00
virtual std::string to_string() const = 0;
2013-12-19 23:16:13 -08:00
virtual void accept(Visitor &visitor) const = 0;
2013-11-07 13:24:01 -08:00
};
2014-03-09 19:49:35 -07:00
2013-11-12 08:17:19 -08:00
std::ostream& operator<<(std::ostream& stream, const Rule &rule);
std::ostream& operator<<(std::ostream& stream, const rule_ptr &rule);
2013-11-07 13:24:01 -08:00
}
}
2013-12-15 14:41:51 -08:00
namespace std {
template<>
2014-02-15 16:12:16 -08:00
struct hash<tree_sitter::rules::rule_ptr> {
size_t operator()(const tree_sitter::rules::rule_ptr &rule) const {
return typeid(*rule).hash_code() ^ rule->hash_code();
2013-12-15 14:41:51 -08:00
}
};
}
2014-03-09 22:05:17 -07:00
#endif // COMPILER_RULES_RULE_H_