2013-11-10 14:24:25 -08:00
|
|
|
#ifndef __TreeSitter__grammar__
|
|
|
|
|
#define __TreeSitter__grammar__
|
|
|
|
|
|
2014-02-12 08:30:50 -08:00
|
|
|
#include <map>
|
2013-12-15 14:41:51 -08:00
|
|
|
#include <vector>
|
2013-11-10 14:24:25 -08:00
|
|
|
#include "rules.h"
|
|
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
|
|
|
|
class Grammar {
|
2014-01-03 01:02:24 -08:00
|
|
|
typedef std::initializer_list<std::pair<const std::string, const rules::rule_ptr>> rule_map_init_list;
|
2014-02-12 08:30:50 -08:00
|
|
|
typedef std::map<const std::string, const rules::rule_ptr> rule_map;
|
2014-01-28 13:27:30 -08:00
|
|
|
|
2013-11-10 14:24:25 -08:00
|
|
|
public:
|
2013-11-13 20:22:06 -08:00
|
|
|
Grammar(const rule_map_init_list &rules);
|
2014-02-12 08:30:50 -08:00
|
|
|
Grammar(std::string start_rule_name, const rule_map &rules);
|
|
|
|
|
Grammar(std::string start_rule_name, const rule_map &rules, const rule_map &aux_rules);
|
2014-01-28 13:27:30 -08:00
|
|
|
|
2013-11-12 18:37:02 -08:00
|
|
|
const std::string start_rule_name;
|
2013-12-15 14:41:51 -08:00
|
|
|
std::vector<std::string> rule_names() const;
|
2014-01-03 01:02:24 -08:00
|
|
|
bool operator==(const Grammar &other) const;
|
2014-01-04 15:01:06 -08:00
|
|
|
bool has_definition(const rules::Symbol &symbol) const;
|
2014-01-28 13:27:30 -08:00
|
|
|
const rules::rule_ptr rule(const rules::Symbol &symbol) const;
|
2013-12-28 23:26:20 -08:00
|
|
|
|
2014-01-28 13:27:30 -08:00
|
|
|
rule_map rules;
|
|
|
|
|
rule_map aux_rules;
|
2013-11-10 14:24:25 -08:00
|
|
|
};
|
2014-01-03 01:02:24 -08:00
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream &stream, const Grammar &grammar);
|
2013-11-10 14:24:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|