diff --git a/spec/compiler/build_tables/conflict_manager_spec.cc b/spec/compiler/build_tables/conflict_manager_spec.cc index 62cd9f44..2a8c237e 100644 --- a/spec/compiler/build_tables/conflict_manager_spec.cc +++ b/spec/compiler/build_tables/conflict_manager_spec.cc @@ -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("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()); }); diff --git a/spec/compiler/name_symbols/name_symbols_spec.cc b/spec/compiler/name_symbols/name_symbols_spec.cc index abdd3550..3bc9b3b4 100644 --- a/spec/compiler/name_symbols/name_symbols_spec.cc +++ b/spec/compiler/name_symbols/name_symbols_spec.cc @@ -15,7 +15,7 @@ describe("assigning user-visible names to symbols", [&]() { make_shared("some_generated_string_name", SymbolTypeAuxiliary), make_shared("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 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")); diff --git a/src/compiler/build_tables/build_tables.cc b/src/compiler/build_tables/build_tables.cc index a7c6e262..6adaf274 100644 --- a/src/compiler/build_tables/build_tables.cc +++ b/src/compiler/build_tables/build_tables.cc @@ -1,6 +1,7 @@ #include "compiler/build_tables/build_tables.h" #include #include +#include #include #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 conflicts() { return conflict_manager.conflicts(); }; - + ParseTable parse_table; LexTable lex_table; }; diff --git a/src/compiler/build_tables/build_tables.h b/src/compiler/build_tables/build_tables.h index 2aad9838..7abe85dd 100644 --- a/src/compiler/build_tables/build_tables.h +++ b/src/compiler/build_tables/build_tables.h @@ -3,6 +3,8 @@ #include #include +#include +#include #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::vector> - build_tables(const PreparedGrammar &grammar, + build_tables(const PreparedGrammar &grammar, const PreparedGrammar &lex_grammar, const std::map &rule_names); } diff --git a/src/compiler/build_tables/conflict_manager.cc b/src/compiler/build_tables/conflict_manager.cc index a1bba240..03d8bb29 100644 --- a/src/compiler/build_tables/conflict_manager.cc +++ b/src/compiler/build_tables/conflict_manager.cc @@ -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 ConflictManager::conflicts() const { diff --git a/src/compiler/build_tables/get_metadata.cc b/src/compiler/build_tables/get_metadata.cc index 02cd5fdf..52d61553 100644 --- a/src/compiler/build_tables/get_metadata.cc +++ b/src/compiler/build_tables/get_metadata.cc @@ -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" diff --git a/src/compiler/build_tables/get_metadata.h b/src/compiler/build_tables/get_metadata.h index 08dec9cf..ed15374e 100644 --- a/src/compiler/build_tables/get_metadata.h +++ b/src/compiler/build_tables/get_metadata.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_ diff --git a/src/compiler/build_tables/rule_transitions.cc b/src/compiler/build_tables/rule_transitions.cc index 71cf287b..1425389c 100644 --- a/src/compiler/build_tables/rule_transitions.cc +++ b/src/compiler/build_tables/rule_transitions.cc @@ -94,7 +94,7 @@ namespace tree_sitter { map apply_to(const rules::Metadata *rule) { return this->apply(rule->rule); } - + map apply_to(const rules::String *rule) { rule_ptr result = make_shared(); for (char val : rule->value) diff --git a/src/compiler/compile.cc b/src/compiler/compile.cc index 8372cb62..1d6a6031 100644 --- a/src/compiler/compile.cc +++ b/src/compiler/compile.cc @@ -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; diff --git a/src/compiler/conflict.cc b/src/compiler/conflict.cc index 2e7a6bbe..ffe9fd0d 100644 --- a/src/compiler/conflict.cc +++ b/src/compiler/conflict.cc @@ -1,5 +1,5 @@ -#include "tree_sitter/compiler.h" #include +#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 << "#"; } diff --git a/src/compiler/name_symbols/name_symbols.cc b/src/compiler/name_symbols/name_symbols.cc index 1ea4a320..9d4032dd 100644 --- a/src/compiler/name_symbols/name_symbols.cc +++ b/src/compiler/name_symbols/name_symbols.cc @@ -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" }); diff --git a/src/compiler/prepare_grammar/expand_repeats.cc b/src/compiler/prepare_grammar/expand_repeats.cc index e78793f9..694e4971 100644 --- a/src/compiler/prepare_grammar/expand_repeats.cc +++ b/src/compiler/prepare_grammar/expand_repeats.cc @@ -1,6 +1,7 @@ #include "compiler/prepare_grammar/expand_repeats.h" #include #include +#include #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> aux_rules; }; diff --git a/src/compiler/rules/blank.cc b/src/compiler/rules/blank.cc index 8853bd11..06ab6d63 100644 --- a/src/compiler/rules/blank.cc +++ b/src/compiler/rules/blank.cc @@ -26,4 +26,4 @@ namespace tree_sitter { visitor->visit(this); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/built_in_symbols.cc b/src/compiler/rules/built_in_symbols.cc index 44142670..ee7a31ee 100644 --- a/src/compiler/rules/built_in_symbols.cc +++ b/src/compiler/rules/built_in_symbols.cc @@ -6,4 +6,4 @@ namespace tree_sitter { Symbol START() { return Symbol("start", SymbolTypeBuiltIn); } Symbol END_OF_INPUT() { return Symbol("end", SymbolTypeBuiltIn); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/character_range.cc b/src/compiler/rules/character_range.cc index 7b5e614e..ceded613 100644 --- a/src/compiler/rules/character_range.cc +++ b/src/compiler/rules/character_range.cc @@ -35,7 +35,7 @@ namespace tree_sitter { case MAX_CHAR: return ""; default: - return string() + char(input); + return string() + static_cast(input); } } diff --git a/src/compiler/rules/choice.cc b/src/compiler/rules/choice.cc index 32aaba16..576282bd 100644 --- a/src/compiler/rules/choice.cc +++ b/src/compiler/rules/choice.cc @@ -38,4 +38,4 @@ namespace tree_sitter { visitor->visit(this); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/metadata.cc b/src/compiler/rules/metadata.cc index b11be955..98f1f7b9 100644 --- a/src/compiler/rules/metadata.cc +++ b/src/compiler/rules/metadata.cc @@ -1,7 +1,7 @@ #include "compiler/rules/metadata.h" #include -#include "compiler/rules/visitor.h" #include +#include "compiler/rules/visitor.h" namespace tree_sitter { using std::hash; @@ -37,4 +37,4 @@ namespace tree_sitter { visitor->visit(this); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/rules.cc b/src/compiler/rules/rules.cc index 65637737..842b7d57 100644 --- a/src/compiler/rules/rules.cc +++ b/src/compiler/rules/rules.cc @@ -1,3 +1,6 @@ +#include +#include +#include #include "tree_sitter/compiler.h" #include "compiler/rules/rule.h" #include "compiler/rules/blank.h" diff --git a/src/compiler/rules/symbol.cc b/src/compiler/rules/symbol.cc index babc8100..9d68c42e 100644 --- a/src/compiler/rules/symbol.cc +++ b/src/compiler/rules/symbol.cc @@ -63,4 +63,4 @@ namespace tree_sitter { visitor->visit(this); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/visitor.cc b/src/compiler/rules/visitor.cc index 53dadcb3..d02828ee 100644 --- a/src/compiler/rules/visitor.cc +++ b/src/compiler/rules/visitor.cc @@ -32,4 +32,4 @@ namespace tree_sitter { return std::make_shared(apply(rule->rule), rule->value); } } -} \ No newline at end of file +} diff --git a/src/compiler/rules/visitor.h b/src/compiler/rules/visitor.h index 768ecdbd..c897dc14 100644 --- a/src/compiler/rules/visitor.h +++ b/src/compiler/rules/visitor.h @@ -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_; };