Trim whitespace
This commit is contained in:
parent
801f4bd0a8
commit
93df5579b4
15 changed files with 78 additions and 78 deletions
|
|
@ -29,20 +29,20 @@ namespace tree_sitter {
|
|||
bool apply_to(const rules::String *rule) { return true; }
|
||||
bool apply_to(const rules::Pattern *rule) { return true; }
|
||||
};
|
||||
|
||||
|
||||
class SymbolInliner : public rules::IdentityRuleFn {
|
||||
map<ISymbol, ISymbol> replacements;
|
||||
using rules::IdentityRuleFn::apply_to;
|
||||
|
||||
|
||||
int new_index_for_symbol(const ISymbol &symbol) {
|
||||
int result = symbol.index;
|
||||
for (const auto &pair : replacements)
|
||||
if (pair.first.index < symbol.index &&
|
||||
if (pair.first.index < symbol.index &&
|
||||
pair.first.is_auxiliary() == symbol.is_auxiliary())
|
||||
result--;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
rule_ptr apply_to(const ISymbol *rule) {
|
||||
auto replacement_pair = replacements.find(*rule);
|
||||
if (replacement_pair != replacements.end())
|
||||
|
|
@ -52,7 +52,7 @@ namespace tree_sitter {
|
|||
else
|
||||
return make_shared<ISymbol>(new_index_for_symbol(*rule), rule->options);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
SymbolInliner(const map<ISymbol, ISymbol> &replacements, size_t rule_count, size_t aux_rule_count) :
|
||||
replacements(replacements)
|
||||
|
|
@ -78,7 +78,7 @@ namespace tree_sitter {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
vector<pair<string, rule_ptr>> tokens;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,23 +15,23 @@ namespace tree_sitter {
|
|||
using std::exception;
|
||||
|
||||
GrammarError::GrammarError(string rule_name) : rule_name(rule_name) {}
|
||||
|
||||
|
||||
string GrammarError::message() const {
|
||||
return "Undefined rule '" + rule_name + "'";
|
||||
}
|
||||
|
||||
|
||||
namespace prepare_grammar {
|
||||
class InternSymbols : public rules::IdentityRuleFn {
|
||||
const Grammar grammar;
|
||||
using rules::IdentityRuleFn::apply_to;
|
||||
|
||||
|
||||
long index_of(string rule_name) {
|
||||
for (size_t i = 0; i < grammar.rules.size(); i++)
|
||||
if (grammar.rules[i].first == rule_name)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
rule_ptr apply_to(const rules::Symbol *rule) {
|
||||
long index = index_of(rule->name);
|
||||
if (index == -1)
|
||||
|
|
@ -44,7 +44,7 @@ namespace tree_sitter {
|
|||
|
||||
string missing_rule_name;
|
||||
};
|
||||
|
||||
|
||||
pair<PreparedGrammar, const GrammarError *> intern_symbols(const Grammar &grammar) {
|
||||
InternSymbols interner(grammar);
|
||||
vector<pair<string, rule_ptr>> rules;
|
||||
|
|
@ -58,7 +58,7 @@ namespace tree_sitter {
|
|||
};
|
||||
rules.push_back({ pair.first, new_rule });
|
||||
}
|
||||
|
||||
|
||||
return { PreparedGrammar(rules), nullptr };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace tree_sitter {
|
||||
class Grammar;
|
||||
class PreparedGrammar;
|
||||
|
||||
|
||||
class GrammarError {
|
||||
std::string rule_name;
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue