2015-01-12 23:01:52 -08:00
|
|
|
#include "compiler/syntax_grammar.h"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include "compiler/rules/symbol.h"
|
2015-01-11 23:21:58 -08:00
|
|
|
#include "compiler/rules/built_in_symbols.h"
|
2015-01-12 23:01:52 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
|
|
|
|
|
|
|
|
|
using std::string;
|
2015-01-11 23:21:58 -08:00
|
|
|
using std::to_string;
|
2015-01-12 23:01:52 -08:00
|
|
|
using std::pair;
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::set;
|
|
|
|
|
|
2015-10-17 22:54:56 -07:00
|
|
|
static const vector<Production> NO_PRODUCTIONS;
|
2015-01-12 23:01:52 -08:00
|
|
|
|
2015-10-01 17:10:39 -07:00
|
|
|
SyntaxVariable::SyntaxVariable(const string &name, VariableType type,
|
|
|
|
|
const vector<Production> &productions)
|
|
|
|
|
: name(name), productions(productions), type(type) {}
|
|
|
|
|
|
|
|
|
|
ProductionStep::ProductionStep(const rules::Symbol &symbol, int precedence,
|
2015-10-13 11:23:02 -07:00
|
|
|
rules::Associativity associativity)
|
2015-12-17 12:48:55 -08:00
|
|
|
: symbol(symbol), precedence(precedence), associativity(associativity) {}
|
2015-10-01 17:10:39 -07:00
|
|
|
|
|
|
|
|
bool ProductionStep::operator==(const ProductionStep &other) const {
|
2015-01-11 23:21:58 -08:00
|
|
|
return symbol == other.symbol && precedence == other.precedence &&
|
2015-12-09 14:23:19 -08:00
|
|
|
associativity == other.associativity;
|
2015-01-12 23:01:52 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-01 17:10:39 -07:00
|
|
|
const vector<Production> &SyntaxGrammar::productions(
|
|
|
|
|
const rules::Symbol &symbol) const {
|
2015-10-17 22:54:56 -07:00
|
|
|
if (symbol.is_built_in() || symbol.is_token) {
|
2015-01-11 23:21:58 -08:00
|
|
|
return NO_PRODUCTIONS;
|
2015-10-01 17:10:39 -07:00
|
|
|
} else {
|
|
|
|
|
return variables[symbol.index].productions;
|
2015-01-11 23:21:58 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 23:01:52 -08:00
|
|
|
} // namespace tree_sitter
|