2013-11-05 22:15:19 -08:00
|
|
|
#ifndef __TreeSitter__Rule__
|
|
|
|
|
#define __TreeSitter__Rule__
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2013-11-06 08:18:40 -08:00
|
|
|
template<class value> class TransitionMap;
|
|
|
|
|
|
2013-11-05 22:15:19 -08:00
|
|
|
namespace rules {
|
|
|
|
|
class Rule {
|
|
|
|
|
public:
|
|
|
|
|
virtual TransitionMap<Rule> transitions() const = 0;
|
|
|
|
|
virtual Rule * copy() const = 0;
|
|
|
|
|
virtual bool operator==(const Rule& other) const = 0;
|
|
|
|
|
virtual std::string to_string() const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-06 13:37:01 -08:00
|
|
|
typedef std::shared_ptr<const Rule> rule_ptr;
|
|
|
|
|
|
2013-11-05 22:15:19 -08:00
|
|
|
class Blank : public Rule {
|
|
|
|
|
public:
|
|
|
|
|
Blank();
|
|
|
|
|
TransitionMap<Rule> transitions() const;
|
|
|
|
|
Blank * copy() const;
|
|
|
|
|
bool operator==(const Rule& other) const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Symbol : public Rule {
|
|
|
|
|
public:
|
|
|
|
|
Symbol(int id);
|
|
|
|
|
TransitionMap<Rule> transitions() const;
|
|
|
|
|
Symbol * copy() const;
|
|
|
|
|
bool operator==(const Rule& other) const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
private:
|
|
|
|
|
int id;
|
|
|
|
|
};
|
2013-11-07 08:22:56 -08:00
|
|
|
|
|
|
|
|
class Char : public Rule {
|
|
|
|
|
public:
|
|
|
|
|
Char(char value);
|
|
|
|
|
TransitionMap<Rule> transitions() const;
|
|
|
|
|
Char * copy() const;
|
|
|
|
|
bool operator==(const Rule& other) const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
private:
|
|
|
|
|
char value;
|
|
|
|
|
};
|
2013-11-05 22:15:19 -08:00
|
|
|
|
|
|
|
|
class Choice : public Rule {
|
|
|
|
|
public:
|
|
|
|
|
Choice(const Rule &left, const Rule &right);
|
|
|
|
|
Choice(const Rule *left, const Rule *right);
|
|
|
|
|
Choice(std::shared_ptr<const Rule> left, std::shared_ptr<const Rule> right);
|
|
|
|
|
TransitionMap<Rule> transitions() const;
|
|
|
|
|
Choice * copy() const;
|
|
|
|
|
bool operator==(const Rule& other) const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
private:
|
2013-11-06 13:37:01 -08:00
|
|
|
rule_ptr left;
|
|
|
|
|
rule_ptr right;
|
2013-11-05 22:15:19 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Seq : public Rule {
|
|
|
|
|
public:
|
|
|
|
|
Seq(const Rule &left, const Rule &right);
|
|
|
|
|
Seq(const Rule *left, const Rule *right);
|
|
|
|
|
Seq(std::shared_ptr<const Rule> left, std::shared_ptr<const Rule> right);
|
|
|
|
|
TransitionMap<Rule> transitions() const;
|
|
|
|
|
Seq * copy() const;
|
|
|
|
|
bool operator==(const Rule& other) const;
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
private:
|
2013-11-06 13:37:01 -08:00
|
|
|
rule_ptr left;
|
|
|
|
|
rule_ptr right;
|
2013-11-05 22:15:19 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|