2014-04-28 20:43:27 -07:00
|
|
|
#ifndef COMPILER_RULES_SYMBOL_H_
|
|
|
|
|
#define COMPILER_RULES_SYMBOL_H_
|
2014-04-22 23:38:26 -07:00
|
|
|
|
2014-07-20 21:43:27 -07:00
|
|
|
namespace tree_sitter {
|
|
|
|
|
namespace rules {
|
|
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
struct Symbol {
|
|
|
|
|
using Index = int;
|
|
|
|
|
enum Type {
|
2016-11-30 09:34:47 -08:00
|
|
|
External,
|
2016-12-20 17:06:20 -08:00
|
|
|
Terminal,
|
2016-12-02 22:03:48 -08:00
|
|
|
NonTerminal,
|
2017-03-17 12:52:01 -07:00
|
|
|
};
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
inline bool operator==(const Symbol &other) const {
|
|
|
|
|
return index == other.index && type == other.type;
|
|
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
inline bool operator!=(const Symbol &other) const {
|
|
|
|
|
return !operator==(other);
|
|
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
inline bool operator<(const Symbol &other) const {
|
|
|
|
|
if (type < other.type) return true;
|
|
|
|
|
if (type > other.type) return false;
|
|
|
|
|
return index < other.index;
|
|
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2016-11-14 10:25:26 -08:00
|
|
|
Index index;
|
2016-11-30 09:34:47 -08:00
|
|
|
Type type;
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
static Symbol terminal(Index index) {
|
|
|
|
|
return Symbol{index, Type::Terminal};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Symbol external(Index index) {
|
|
|
|
|
return Symbol{index, Type::External};
|
|
|
|
|
}
|
2014-04-22 23:38:26 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
static Symbol non_terminal(Index index) {
|
|
|
|
|
return Symbol{index, Type::NonTerminal};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_non_terminal() const {
|
|
|
|
|
return type == Type::NonTerminal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_terminal() const {
|
|
|
|
|
return type == Type::Terminal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_external() const {
|
|
|
|
|
return type == Type::External;
|
|
|
|
|
}
|
2014-07-20 21:43:27 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
bool is_built_in() const {
|
|
|
|
|
return index < 0;
|
2014-07-20 21:43:27 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
inline Symbol END_OF_INPUT() {
|
|
|
|
|
return Symbol{-1, Symbol::Terminal};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Symbol START() {
|
|
|
|
|
return Symbol{-2, Symbol::NonTerminal};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Symbol NONE() {
|
|
|
|
|
return Symbol{-3, Symbol::Type(-1)};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rules
|
|
|
|
|
} // namespace tree_sitter
|
2014-04-22 23:38:26 -07:00
|
|
|
|
2017-03-17 12:52:01 -07:00
|
|
|
#endif // COMPILER_RULES_SYMBOL_H_
|