cpplint
This commit is contained in:
parent
5145bba53d
commit
67243c7e2f
21 changed files with 40 additions and 33 deletions
|
|
@ -89,17 +89,17 @@ describe("resolving parse conflicts", []() {
|
|||
it("records a conflict", [&]() {
|
||||
manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Reduce(sym1, 1));
|
||||
manager->resolve_parse_action(sym1, ParseAction::Reduce(sym1, 1), ParseAction::Reduce(sym2, 1));
|
||||
|
||||
|
||||
AssertThat(manager->conflicts(), Equals(vector<Conflict>({
|
||||
Conflict("rule1: reduce rule2 / reduce rule1"),
|
||||
Conflict("rule1: reduce rule1 / reduce rule2")
|
||||
})));
|
||||
});
|
||||
|
||||
|
||||
it("favors the symbol listed earlier in the grammar", [&]() {
|
||||
should_update = manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Reduce(sym1, 1));
|
||||
AssertThat(should_update, IsTrue());
|
||||
|
||||
|
||||
should_update = manager->resolve_parse_action(sym1, ParseAction::Reduce(sym1, 1), ParseAction::Reduce(sym2, 1));
|
||||
AssertThat(should_update, IsFalse());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ describe("assigning user-visible names to symbols", [&]() {
|
|||
make_shared<Symbol>("some_generated_string_name", SymbolTypeAuxiliary),
|
||||
make_shared<Symbol>("some_generated_pattern_name", SymbolTypeAuxiliary), }) },
|
||||
}, {});
|
||||
|
||||
|
||||
PreparedGrammar lexical_grammar({
|
||||
{ "some_given_name", str("the-string") },
|
||||
}, {
|
||||
|
|
@ -24,7 +24,7 @@ describe("assigning user-visible names to symbols", [&]() {
|
|||
});
|
||||
|
||||
map<Symbol, string> result = name_symbols::name_symbols(syntactic_grammar, lexical_grammar);
|
||||
|
||||
|
||||
describe("for symbols that are not in the lexical grammar (syntactic rules)", [&]() {
|
||||
it("uses the symbol's normal name", [&]() {
|
||||
auto symbol = Symbol("some_syntactic_symbol");
|
||||
|
|
@ -48,7 +48,7 @@ describe("assigning user-visible names to symbols", [&]() {
|
|||
AssertThat(result[symbol], Equals("/the-pattern/"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("assigns names to the built-in symbols", [&]() {
|
||||
AssertThat(result[rules::END_OF_INPUT()], Equals("EOF"));
|
||||
AssertThat(result[rules::ERROR()], Equals("ERROR"));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "compiler/build_tables/build_tables.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include "compiler/prepared_grammar.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
|
|
@ -35,7 +36,7 @@ namespace tree_sitter {
|
|||
for (auto &transition : sym_transitions(item_set, grammar)) {
|
||||
const Symbol &symbol = transition.first;
|
||||
const ParseItemSet &item_set = transition.second;
|
||||
|
||||
|
||||
auto current_actions = parse_table.states[state_id].actions;
|
||||
auto current_action = current_actions.find(symbol);
|
||||
if (current_action == current_actions.end() ||
|
||||
|
|
@ -174,7 +175,7 @@ namespace tree_sitter {
|
|||
const vector<Conflict> conflicts() {
|
||||
return conflict_manager.conflicts();
|
||||
};
|
||||
|
||||
|
||||
ParseTable parse_table;
|
||||
LexTable lex_table;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/parse_table.h"
|
||||
#include "compiler/lex_table.h"
|
||||
|
|
@ -12,7 +14,7 @@ namespace tree_sitter {
|
|||
|
||||
namespace build_tables {
|
||||
std::pair<std::pair<ParseTable, LexTable>, std::vector<Conflict>>
|
||||
build_tables(const PreparedGrammar &grammar,
|
||||
build_tables(const PreparedGrammar &grammar,
|
||||
const PreparedGrammar &lex_grammar,
|
||||
const std::map<rules::Symbol, std::string> &rule_names);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace tree_sitter {
|
|||
const ParseAction &new_action) {
|
||||
if (new_action.type < old_action.type)
|
||||
return !resolve_parse_action(symbol, new_action, old_action);
|
||||
|
||||
|
||||
switch (old_action.type) {
|
||||
case ParseActionTypeError:
|
||||
return true;
|
||||
|
|
@ -88,9 +88,9 @@ namespace tree_sitter {
|
|||
size_t new_index = lex_grammar.index_of(new_action.symbol);
|
||||
return (new_index < old_index);
|
||||
}
|
||||
default:;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const vector<Conflict> ConflictManager::conflicts() const {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "get_metadata.h"
|
||||
#include "compiler/build_tables/get_metadata.h"
|
||||
#include "compiler/rules/seq.h"
|
||||
#include "compiler/rules/choice.h"
|
||||
#include "compiler/rules/repeat.h"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef COMPILER_BUILD_TABLES_CHECK_METADATA_
|
||||
#define COMPILER_BUILD_TABLES_CHECK_METADATA_
|
||||
#ifndef COMPILER_BUILD_TABLES_GET_METADATA_H_
|
||||
#define COMPILER_BUILD_TABLES_GET_METADATA_H_
|
||||
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rules/metadata.h"
|
||||
|
|
@ -10,4 +10,4 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
#endif // COMPILER_BUILD_TABLES_CHECK_METADATA_
|
||||
#endif // COMPILER_BUILD_TABLES_GET_METADATA_H_
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace tree_sitter {
|
|||
map<T, rule_ptr> apply_to(const rules::Metadata *rule) {
|
||||
return this->apply(rule->rule);
|
||||
}
|
||||
|
||||
|
||||
map<T, rule_ptr> apply_to(const rules::String *rule) {
|
||||
rule_ptr result = make_shared<rules::Blank>();
|
||||
for (char val : rule->value)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace tree_sitter {
|
|||
auto table_build_result = build_tables::build_tables(syntax_grammar, lexical_grammar, symbol_names);
|
||||
auto tables = table_build_result.first;
|
||||
auto conflicts = table_build_result.second;
|
||||
|
||||
|
||||
ParseTable &parse_table = tables.first;
|
||||
LexTable &lex_table = tables.second;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "tree_sitter/compiler.h"
|
||||
#include <string>
|
||||
#include "tree_sitter/compiler.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::string;
|
||||
|
|
@ -13,7 +13,7 @@ namespace tree_sitter {
|
|||
bool Conflict::operator<(const tree_sitter::Conflict &other) const {
|
||||
return other.description < description;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream &stream, const Conflict &conflict) {
|
||||
return stream << "#<conflict " + conflict.description + ">";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace tree_sitter {
|
|||
Symbol(pair.first, SymbolTypeAuxiliary),
|
||||
TokenName().apply(pair.second)
|
||||
});
|
||||
|
||||
|
||||
result.insert({ rules::END_OF_INPUT(), "EOF" });
|
||||
result.insert({ rules::ERROR(), "ERROR" });
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "compiler/prepare_grammar/expand_repeats.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "compiler/prepared_grammar.h"
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include "compiler/rules/seq.h"
|
||||
|
|
@ -26,7 +27,7 @@ namespace tree_sitter {
|
|||
namespace prepare_grammar {
|
||||
class ExpandRepeats : public rules::IdentityRuleFn {
|
||||
string rule_name;
|
||||
|
||||
|
||||
rule_ptr apply_to(const Repeat *rule) {
|
||||
rule_ptr inner_rule = apply(rule->content);
|
||||
string helper_rule_name = rule_name + string("_repeat") + to_string(aux_rules.size() + 1);
|
||||
|
|
@ -43,7 +44,7 @@ namespace tree_sitter {
|
|||
|
||||
public:
|
||||
ExpandRepeats(string rule_name) : rule_name(rule_name) {}
|
||||
|
||||
|
||||
vector<pair<string, rules::rule_ptr>> aux_rules;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -26,4 +26,4 @@ namespace tree_sitter {
|
|||
visitor->visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ namespace tree_sitter {
|
|||
Symbol START() { return Symbol("start", SymbolTypeBuiltIn); }
|
||||
Symbol END_OF_INPUT() { return Symbol("end", SymbolTypeBuiltIn); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace tree_sitter {
|
|||
case MAX_CHAR:
|
||||
return "<MAX>";
|
||||
default:
|
||||
return string() + char(input);
|
||||
return string() + static_cast<char>(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ namespace tree_sitter {
|
|||
visitor->visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "compiler/rules/metadata.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include <map>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::hash;
|
||||
|
|
@ -37,4 +37,4 @@ namespace tree_sitter {
|
|||
visitor->visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
|
|
|
|||
|
|
@ -63,4 +63,4 @@ namespace tree_sitter {
|
|||
visitor->visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ namespace tree_sitter {
|
|||
return std::make_shared<Metadata>(apply(rule->rule), rule->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace tree_sitter {
|
|||
rule->accept(this);
|
||||
return value_;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
virtual T default_apply(const Rule *rule) { return T(); }
|
||||
virtual T apply_to(const Blank *rule) { return default_apply((const Rule *)rule); }
|
||||
|
|
@ -58,7 +58,7 @@ namespace tree_sitter {
|
|||
void visit(const Seq *rule) { value_ = apply_to(rule); }
|
||||
void visit(const String *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Symbol *rule) { value_ = apply_to(rule); }
|
||||
|
||||
|
||||
private:
|
||||
T value_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue