From bd77ab1ac9a5625bbc5f531e73bdbcd2885c495e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Sep 2015 17:49:20 -0700 Subject: [PATCH] Move public rule functions out of rule namespace This way, there's only one public namespace: tree_sitter --- include/tree_sitter/compiler.h | 21 +++++-------- project.gyp | 2 +- .../parse_conflict_manager_spec.cc | 2 +- spec/compiler/helpers/containers.h | 4 +-- spec/fixtures/grammars/arithmetic.cc | 3 -- spec/fixtures/grammars/c.cc | 3 -- spec/fixtures/grammars/cpp.cc | 3 -- spec/fixtures/grammars/golang.cc | 3 -- spec/fixtures/grammars/helpers.cc | 2 +- spec/fixtures/grammars/helpers.h | 2 +- spec/fixtures/grammars/javascript.cc | 3 -- spec/fixtures/grammars/json.cc | 3 -- src/compiler/build_tables/build_lex_table.cc | 10 +++---- src/compiler/build_tables/first_symbols.cc | 3 +- src/compiler/build_tables/first_symbols.h | 2 +- .../build_tables/get_completion_status.cc | 12 ++++---- .../build_tables/get_completion_status.h | 4 +-- src/compiler/build_tables/get_metadata.cc | 2 +- src/compiler/build_tables/get_metadata.h | 2 +- src/compiler/build_tables/item.cc | 2 +- src/compiler/build_tables/item.h | 4 +-- src/compiler/build_tables/item_set_closure.cc | 1 - src/compiler/build_tables/lex_item.cc | 2 +- src/compiler/build_tables/lex_item.h | 4 +-- .../build_tables/parse_conflict_manager.cc | 4 +-- src/compiler/build_tables/parse_item.cc | 2 +- src/compiler/build_tables/parse_item.h | 4 +-- .../build_tables/rule_can_be_blank.cc | 5 ++-- src/compiler/build_tables/rule_can_be_blank.h | 5 ++-- src/compiler/build_tables/rule_transitions.cc | 3 +- src/compiler/build_tables/rule_transitions.h | 6 ++-- src/compiler/grammar.cc | 5 ++-- src/compiler/lexical_grammar.cc | 2 +- src/compiler/lexical_grammar.h | 8 ++--- src/compiler/parse_table.cc | 9 +++--- src/compiler/parse_table.h | 8 ++--- .../prepare_grammar/expand_repeats.cc | 4 +-- src/compiler/prepare_grammar/expand_tokens.cc | 1 - .../prepare_grammar/extract_tokens.cc | 5 ++-- .../prepare_grammar/intern_symbols.cc | 4 +-- .../prepare_grammar/interned_grammar.h | 4 +-- src/compiler/prepare_grammar/is_token.cc | 2 +- src/compiler/prepare_grammar/is_token.h | 2 +- src/compiler/prepare_grammar/parse_regex.cc | 18 +++++------ src/compiler/prepare_grammar/parse_regex.h | 2 +- .../prepare_grammar/token_description.cc | 2 +- .../prepare_grammar/token_description.h | 2 +- src/compiler/{rules => }/rule.cc | 4 +-- src/compiler/{rules => }/rule.h | 12 ++++---- src/compiler/rules/blank.cc | 5 ++++ src/compiler/rules/blank.h | 3 +- src/compiler/rules/character_set.h | 2 +- src/compiler/rules/choice.h | 2 +- src/compiler/rules/metadata.h | 4 +-- src/compiler/rules/named_symbol.h | 2 +- src/compiler/rules/pattern.cc | 2 +- src/compiler/rules/pattern.h | 2 +- src/compiler/rules/repeat.h | 2 +- src/compiler/rules/rules.cc | 30 +++++++++---------- src/compiler/rules/seq.h | 2 +- src/compiler/rules/string.h | 2 +- src/compiler/rules/symbol.h | 2 +- src/compiler/rules/visitor.cc | 2 +- src/compiler/rules/visitor.h | 2 +- src/compiler/syntax_grammar.cc | 2 +- src/compiler/syntax_grammar.h | 6 ++-- 66 files changed, 127 insertions(+), 167 deletions(-) rename src/compiler/{rules => }/rule.cc (86%) rename src/compiler/{rules => }/rule.h (83%) diff --git a/include/tree_sitter/compiler.h b/include/tree_sitter/compiler.h index 8128da49..a28d67c8 100644 --- a/include/tree_sitter/compiler.h +++ b/include/tree_sitter/compiler.h @@ -9,13 +9,11 @@ namespace tree_sitter { -namespace rules { - class Rule; typedef std::shared_ptr rule_ptr; enum Associativity { - AssociativityNone = 0, + AssociativityNone, AssociativityLeft, AssociativityRight, }; @@ -32,21 +30,17 @@ rule_ptr prec(int precedence, const rule_ptr &); rule_ptr prec(int precedence, const rule_ptr &, Associativity); rule_ptr token(const rule_ptr &rule); -std::ostream &operator<<(std::ostream &stream, const rules::rule_ptr &rule); - -} // namespace rules - class Grammar { - const std::vector> rules_; - std::set ubiquitous_tokens_; + const std::vector> rules_; + std::set ubiquitous_tokens_; std::set> expected_conflicts_; public: - explicit Grammar(const std::vector> &); - Grammar &ubiquitous_tokens(const std::set &); + explicit Grammar(const std::vector> &); + Grammar &ubiquitous_tokens(const std::set &); Grammar &expected_conflicts(const std::set> &); - const std::vector> &rules() const; - const std::set &ubiquitous_tokens() const; + const std::vector> &rules() const; + const std::set &ubiquitous_tokens() const; const std::set> &expected_conflicts() const; }; @@ -71,6 +65,7 @@ std::pair compile(const Grammar &, std::ostream &operator<<(std::ostream &stream, const Grammar &grammar); std::ostream &operator<<(std::ostream &stream, const GrammarError *error); +std::ostream &operator<<(std::ostream &stream, const rule_ptr &rule); } // namespace tree_sitter diff --git a/project.gyp b/project.gyp index 58cb9fd0..2a7139a3 100644 --- a/project.gyp +++ b/project.gyp @@ -40,6 +40,7 @@ 'src/compiler/prepare_grammar/prepare_grammar.cc', 'src/compiler/prepare_grammar/token_description.cc', 'src/compiler/syntax_grammar.cc', + 'src/compiler/rule.cc', 'src/compiler/rules/blank.cc', 'src/compiler/rules/built_in_symbols.cc', 'src/compiler/rules/character_range.cc', @@ -49,7 +50,6 @@ 'src/compiler/rules/named_symbol.cc', 'src/compiler/rules/pattern.cc', 'src/compiler/rules/repeat.cc', - 'src/compiler/rules/rule.cc', 'src/compiler/rules/rules.cc', 'src/compiler/rules/seq.cc', 'src/compiler/rules/string.cc', diff --git a/spec/compiler/build_tables/parse_conflict_manager_spec.cc b/spec/compiler/build_tables/parse_conflict_manager_spec.cc index 226eb6ab..924c67d7 100644 --- a/spec/compiler/build_tables/parse_conflict_manager_spec.cc +++ b/spec/compiler/build_tables/parse_conflict_manager_spec.cc @@ -129,7 +129,7 @@ describe("ParseConflictManager", []() { describe("when the precedences are equal and the reduce's rule has no associativity", [&]() { it("reports an unresolved conflict", [&]() { ParseAction shift = ParseAction::Shift(2, { 0 }); - ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityUnspecified, 0); + ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityNone, 0); result = conflict_manager->resolve(reduce, shift, lookahead_sym); AssertThat(result.first, IsFalse()); diff --git a/spec/compiler/helpers/containers.h b/spec/compiler/helpers/containers.h index 6c1ecb37..86c6069b 100644 --- a/spec/compiler/helpers/containers.h +++ b/spec/compiler/helpers/containers.h @@ -6,14 +6,14 @@ #include #include #include "tree_sitter/compiler.h" -#include "compiler/rules/rule.h" +#include "compiler/rule.h" using std::map; using std::vector; using std::string; using std::initializer_list; using std::pair; -using tree_sitter::rules::rule_ptr; +using tree_sitter::rule_ptr; template class rule_map : public map { diff --git a/spec/fixtures/grammars/arithmetic.cc b/spec/fixtures/grammars/arithmetic.cc index da723931..d76971ed 100644 --- a/spec/fixtures/grammars/arithmetic.cc +++ b/spec/fixtures/grammars/arithmetic.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - extern const Grammar arithmetic = Grammar({ { "program", sym("_expression") }, { "_expression", choice({ diff --git a/spec/fixtures/grammars/c.cc b/spec/fixtures/grammars/c.cc index 943e0772..6cceb2e5 100644 --- a/spec/fixtures/grammars/c.cc +++ b/spec/fixtures/grammars/c.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - // http://slps.github.io/zoo/c/iso-9899-tc3.html extern const Grammar c = Grammar({ diff --git a/spec/fixtures/grammars/cpp.cc b/spec/fixtures/grammars/cpp.cc index eec7f22f..ebba789b 100644 --- a/spec/fixtures/grammars/cpp.cc +++ b/spec/fixtures/grammars/cpp.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - // http://slps.github.io/zoo/cpp/iso-n2723.html extern const Grammar cpp = diff --git a/spec/fixtures/grammars/golang.cc b/spec/fixtures/grammars/golang.cc index e98870f3..0ed77df1 100644 --- a/spec/fixtures/grammars/golang.cc +++ b/spec/fixtures/grammars/golang.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - static rule_ptr terminated(rule_ptr rule) { return seq({ rule, choice({ sym("_line_break"), diff --git a/spec/fixtures/grammars/helpers.cc b/spec/fixtures/grammars/helpers.cc index 2fd8b20d..69ce9987 100644 --- a/spec/fixtures/grammars/helpers.cc +++ b/spec/fixtures/grammars/helpers.cc @@ -2,7 +2,7 @@ namespace tree_sitter_examples { -using namespace tree_sitter::rules; +using namespace tree_sitter; rule_ptr repeat1(rule_ptr element) { return seq({ element, repeat(element) }); diff --git a/spec/fixtures/grammars/helpers.h b/spec/fixtures/grammars/helpers.h index ec3454b3..a241387d 100644 --- a/spec/fixtures/grammars/helpers.h +++ b/spec/fixtures/grammars/helpers.h @@ -5,7 +5,7 @@ namespace tree_sitter_examples { -using namespace tree_sitter::rules; +using namespace tree_sitter; rule_ptr repeat1(rule_ptr element); rule_ptr comma_sep1(rule_ptr element); diff --git a/spec/fixtures/grammars/javascript.cc b/spec/fixtures/grammars/javascript.cc index bcebc43c..82655fd9 100644 --- a/spec/fixtures/grammars/javascript.cc +++ b/spec/fixtures/grammars/javascript.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - static rule_ptr terminated(rule_ptr rule) { return seq({ rule, choice({ sym("_line_break"), diff --git a/spec/fixtures/grammars/json.cc b/spec/fixtures/grammars/json.cc index f21445c4..9737f094 100644 --- a/spec/fixtures/grammars/json.cc +++ b/spec/fixtures/grammars/json.cc @@ -3,9 +3,6 @@ namespace tree_sitter_examples { -using tree_sitter::Grammar; -using namespace tree_sitter::rules; - extern const Grammar json = Grammar({ { "_value", choice({ sym("object"), diff --git a/src/compiler/build_tables/build_lex_table.cc b/src/compiler/build_tables/build_lex_table.cc index 4349f530..3be9ee3a 100644 --- a/src/compiler/build_tables/build_lex_table.cc +++ b/src/compiler/build_tables/build_lex_table.cc @@ -126,7 +126,7 @@ class LexTableBuilder { lex_table.state(state_id).is_token_start = true; } - rules::rule_ptr after_separators(rules::rule_ptr rule) { + rule_ptr after_separators(rule_ptr rule) { return rules::Seq::build({ make_shared( separator_rule(), map({ @@ -136,11 +136,11 @@ class LexTableBuilder { }); } - rules::rule_ptr separator_rule() const { - vector separators; + rule_ptr separator_rule() const { + vector separators; for (const auto &rule : lex_grammar.separators) - separators.push_back(rules::repeat(rule)); - return rules::choice(separators); + separators.push_back(rules::Repeat::build(rule)); + return rules::Choice::build(separators); } set precedence_values_for_item_set(const LexItemSet &item_set) const { diff --git a/src/compiler/build_tables/first_symbols.cc b/src/compiler/build_tables/first_symbols.cc index f90d7886..ffb8555e 100644 --- a/src/compiler/build_tables/first_symbols.cc +++ b/src/compiler/build_tables/first_symbols.cc @@ -59,8 +59,7 @@ class FirstSymbols : public rules::RuleFn> { } }; -set first_symbols(const rules::rule_ptr &rule, - const SyntaxGrammar &grammar) { +set first_symbols(const rule_ptr &rule, const SyntaxGrammar &grammar) { return FirstSymbols(&grammar).apply(rule); } diff --git a/src/compiler/build_tables/first_symbols.h b/src/compiler/build_tables/first_symbols.h index 09c32be5..5d993d75 100644 --- a/src/compiler/build_tables/first_symbols.h +++ b/src/compiler/build_tables/first_symbols.h @@ -15,7 +15,7 @@ namespace build_tables { * Returns the set of symbols that can appear at the beginning of a sentential * form derivable from a given rule in a given grammar. */ -std::set first_symbols(const rules::rule_ptr &rule, +std::set first_symbols(const rule_ptr &rule, const SyntaxGrammar &grammar); } // namespace build_tables diff --git a/src/compiler/build_tables/get_completion_status.cc b/src/compiler/build_tables/get_completion_status.cc index d7c60c01..0f7a1b35 100644 --- a/src/compiler/build_tables/get_completion_status.cc +++ b/src/compiler/build_tables/get_completion_status.cc @@ -15,7 +15,7 @@ class GetCompletionStatus : public rules::RuleFn { if (status.is_done) return status; } - return { false, 0, rules::AssociativityNone }; + return { false, 0, AssociativityNone }; } CompletionStatus apply_to(const rules::Metadata *rule) { @@ -23,17 +23,17 @@ class GetCompletionStatus : public rules::RuleFn { if (result.is_done && !result.associativity) { result.precedence = rule->value_for(rules::PRECEDENCE); result.associativity = - (rules::Associativity)(rule->value_for(rules::ASSOCIATIVITY)); + (Associativity)(rule->value_for(rules::ASSOCIATIVITY)); } return result; } CompletionStatus apply_to(const rules::Repeat *rule) { - return { true, 0, rules::AssociativityNone }; + return { true, 0, AssociativityNone }; } CompletionStatus apply_to(const rules::Blank *rule) { - return { true, 0, rules::AssociativityNone }; + return { true, 0, AssociativityNone }; } CompletionStatus apply_to(const rules::Seq *rule) { @@ -41,11 +41,11 @@ class GetCompletionStatus : public rules::RuleFn { if (left_status.is_done) return apply(rule->right); else - return { false, 0, rules::AssociativityNone }; + return { false, 0, AssociativityNone }; } }; -CompletionStatus get_completion_status(const rules::rule_ptr &rule) { +CompletionStatus get_completion_status(const rule_ptr &rule) { return GetCompletionStatus().apply(rule); } diff --git a/src/compiler/build_tables/get_completion_status.h b/src/compiler/build_tables/get_completion_status.h index 75adf05e..fb341484 100644 --- a/src/compiler/build_tables/get_completion_status.h +++ b/src/compiler/build_tables/get_completion_status.h @@ -9,10 +9,10 @@ namespace build_tables { struct CompletionStatus { bool is_done; int precedence; - rules::Associativity associativity; + Associativity associativity; }; -CompletionStatus get_completion_status(const rules::rule_ptr &); +CompletionStatus get_completion_status(const rule_ptr &); } // namespace build_tables } // namespace tree_sitter diff --git a/src/compiler/build_tables/get_metadata.cc b/src/compiler/build_tables/get_metadata.cc index 34a154ea..11f60349 100644 --- a/src/compiler/build_tables/get_metadata.cc +++ b/src/compiler/build_tables/get_metadata.cc @@ -19,7 +19,7 @@ std::ostream &operator<<(std::ostream &stream, const MetadataRange &range) { << to_string(range.max) << string("}"); } -MetadataRange get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key) { +MetadataRange get_metadata(const rule_ptr &rule, rules::MetadataKey key) { class GetMetadata : public rules::RuleFn> { rules::MetadataKey metadata_key; diff --git a/src/compiler/build_tables/get_metadata.h b/src/compiler/build_tables/get_metadata.h index 133338ed..fa3ecd02 100644 --- a/src/compiler/build_tables/get_metadata.h +++ b/src/compiler/build_tables/get_metadata.h @@ -21,7 +21,7 @@ struct MetadataRange { std::ostream &operator<<(std::ostream &stream, const MetadataRange &range); -MetadataRange get_metadata(const rules::rule_ptr &, rules::MetadataKey); +MetadataRange get_metadata(const rule_ptr &, rules::MetadataKey); } // namespace build_tables } // namespace tree_sitter diff --git a/src/compiler/build_tables/item.cc b/src/compiler/build_tables/item.cc index e49df624..2a31c664 100644 --- a/src/compiler/build_tables/item.cc +++ b/src/compiler/build_tables/item.cc @@ -4,7 +4,7 @@ namespace tree_sitter { namespace build_tables { -Item::Item(const rules::Symbol &lhs, const rules::rule_ptr rule) +Item::Item(const rules::Symbol &lhs, const rule_ptr rule) : lhs(lhs), rule(rule) {} } // namespace build_tables diff --git a/src/compiler/build_tables/item.h b/src/compiler/build_tables/item.h index 5ee6a7e1..ae9e2bea 100644 --- a/src/compiler/build_tables/item.h +++ b/src/compiler/build_tables/item.h @@ -9,10 +9,10 @@ namespace build_tables { class Item { public: - Item(const rules::Symbol &lhs, rules::rule_ptr rule); + Item(const rules::Symbol &lhs, rule_ptr rule); rules::Symbol lhs; - rules::rule_ptr rule; + rule_ptr rule; }; } // namespace build_tables diff --git a/src/compiler/build_tables/item_set_closure.cc b/src/compiler/build_tables/item_set_closure.cc index ca5a08c0..d586362f 100644 --- a/src/compiler/build_tables/item_set_closure.cc +++ b/src/compiler/build_tables/item_set_closure.cc @@ -16,7 +16,6 @@ using std::set; using std::vector; using std::pair; using rules::Symbol; -using rules::rule_ptr; const ParseItemSet item_set_closure(const ParseItem &starting_item, const set &starting_lookahead_symbols, diff --git a/src/compiler/build_tables/lex_item.cc b/src/compiler/build_tables/lex_item.cc index 8a57fcc1..9db5a03d 100644 --- a/src/compiler/build_tables/lex_item.cc +++ b/src/compiler/build_tables/lex_item.cc @@ -11,7 +11,7 @@ namespace build_tables { using std::string; using std::ostream; -LexItem::LexItem(const rules::Symbol &lhs, const rules::rule_ptr rule) +LexItem::LexItem(const rules::Symbol &lhs, const rule_ptr rule) : Item(lhs, rule) {} bool LexItem::operator==(const LexItem &other) const { diff --git a/src/compiler/build_tables/lex_item.h b/src/compiler/build_tables/lex_item.h index c2bd1e08..1de0f886 100644 --- a/src/compiler/build_tables/lex_item.h +++ b/src/compiler/build_tables/lex_item.h @@ -10,7 +10,7 @@ namespace build_tables { class LexItem : public Item { public: - LexItem(const rules::Symbol &lhs, rules::rule_ptr rule); + LexItem(const rules::Symbol &lhs, rule_ptr rule); bool operator==(const LexItem &other) const; bool is_token_start() const; }; @@ -28,7 +28,7 @@ template <> struct hash { size_t operator()(const tree_sitter::build_tables::Item &item) const { return hash()(item.lhs) ^ - hash()(item.rule); + hash()(item.rule); } }; diff --git a/src/compiler/build_tables/parse_conflict_manager.cc b/src/compiler/build_tables/parse_conflict_manager.cc index 29345ad5..7209e980 100644 --- a/src/compiler/build_tables/parse_conflict_manager.cc +++ b/src/compiler/build_tables/parse_conflict_manager.cc @@ -40,9 +40,9 @@ pair ParseConflictManager::resolve( return { true, ConflictTypeResolved }; else if (min_precedence == max_precedence) { switch (new_action.associativity) { - case rules::AssociativityLeft: + case AssociativityLeft: return { true, ConflictTypeResolved }; - case rules::AssociativityRight: + case AssociativityRight: return { false, ConflictTypeResolved }; default: return { false, ConflictTypeUnresolved }; diff --git a/src/compiler/build_tables/parse_item.cc b/src/compiler/build_tables/parse_item.cc index 5826734f..61b95361 100644 --- a/src/compiler/build_tables/parse_item.cc +++ b/src/compiler/build_tables/parse_item.cc @@ -8,7 +8,7 @@ using std::string; using std::vector; using std::ostream; -ParseItem::ParseItem(const rules::Symbol &lhs, const rules::rule_ptr rule, +ParseItem::ParseItem(const rules::Symbol &lhs, const rule_ptr rule, const vector &consumed_symbols) : Item(lhs, rule), consumed_symbols(consumed_symbols) {} diff --git a/src/compiler/build_tables/parse_item.h b/src/compiler/build_tables/parse_item.h index 83c073d6..45a3daed 100644 --- a/src/compiler/build_tables/parse_item.h +++ b/src/compiler/build_tables/parse_item.h @@ -12,7 +12,7 @@ namespace build_tables { class ParseItem : public Item { public: - ParseItem(const rules::Symbol &lhs, rules::rule_ptr rule, + ParseItem(const rules::Symbol &lhs, rule_ptr rule, const std::vector &consumed_symbols); bool operator==(const ParseItem &other) const; bool operator<(const ParseItem &other) const; @@ -32,7 +32,7 @@ template <> struct hash { size_t operator()(const tree_sitter::build_tables::ParseItem &item) const { return hash()(item.lhs) ^ - hash()(item.rule) ^ + hash()(item.rule) ^ hash()(item.consumed_symbols.size()); } }; diff --git a/src/compiler/build_tables/rule_can_be_blank.cc b/src/compiler/build_tables/rule_can_be_blank.cc index 88a3460d..3e1276af 100644 --- a/src/compiler/build_tables/rule_can_be_blank.cc +++ b/src/compiler/build_tables/rule_can_be_blank.cc @@ -62,12 +62,11 @@ class CanBeBlankRecursive : public CanBeBlank { } }; -bool rule_can_be_blank(const rules::rule_ptr &rule) { +bool rule_can_be_blank(const rule_ptr &rule) { return CanBeBlank().apply(rule); } -bool rule_can_be_blank(const rules::rule_ptr &rule, - const SyntaxGrammar &grammar) { +bool rule_can_be_blank(const rule_ptr &rule, const SyntaxGrammar &grammar) { return CanBeBlankRecursive(&grammar).apply(rule); } diff --git a/src/compiler/build_tables/rule_can_be_blank.h b/src/compiler/build_tables/rule_can_be_blank.h index f7d0d7b3..5e7434fe 100644 --- a/src/compiler/build_tables/rule_can_be_blank.h +++ b/src/compiler/build_tables/rule_can_be_blank.h @@ -9,9 +9,8 @@ class SyntaxGrammar; namespace build_tables { -bool rule_can_be_blank(const rules::rule_ptr &rule); -bool rule_can_be_blank(const rules::rule_ptr &rule, - const SyntaxGrammar &grammar); +bool rule_can_be_blank(const rule_ptr &rule); +bool rule_can_be_blank(const rule_ptr &rule, const SyntaxGrammar &grammar); } // namespace build_tables } // namespace tree_sitter diff --git a/src/compiler/build_tables/rule_transitions.cc b/src/compiler/build_tables/rule_transitions.cc index 597aecd8..319624da 100644 --- a/src/compiler/build_tables/rule_transitions.cc +++ b/src/compiler/build_tables/rule_transitions.cc @@ -18,7 +18,6 @@ using std::make_shared; using rules::CharacterSet; using rules::Choice; using rules::Symbol; -using rules::rule_ptr; template void merge_transitions(map *, const map &); @@ -46,7 +45,7 @@ void merge_transitions(map *left, template class RuleTransitions : public rules::RuleFn> { private: - map apply_to_primitive(const rules::Rule *rule) { + map apply_to_primitive(const Rule *rule) { auto primitive = dynamic_cast(rule); if (primitive) return map({ { *primitive, make_shared() } }); diff --git a/src/compiler/build_tables/rule_transitions.h b/src/compiler/build_tables/rule_transitions.h index 38cae0ea..789f1e55 100644 --- a/src/compiler/build_tables/rule_transitions.h +++ b/src/compiler/build_tables/rule_transitions.h @@ -8,11 +8,9 @@ namespace tree_sitter { namespace build_tables { -std::map char_transitions( - const rules::rule_ptr &rule); +std::map char_transitions(const rule_ptr &rule); -std::map sym_transitions( - const rules::rule_ptr &rule); +std::map sym_transitions(const rule_ptr &rule); } // namespace build_tables } // namespace tree_sitter diff --git a/src/compiler/grammar.cc b/src/compiler/grammar.cc index 4fae3163..06d27289 100644 --- a/src/compiler/grammar.cc +++ b/src/compiler/grammar.cc @@ -1,5 +1,5 @@ #include "tree_sitter/compiler.h" -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { @@ -8,9 +8,8 @@ using std::pair; using std::set; using std::string; using std::vector; -using rules::rule_ptr; -Grammar::Grammar(const vector> &rules) +Grammar::Grammar(const vector> &rules) : rules_(rules), ubiquitous_tokens_({}) {} const vector> &Grammar::rules() const { diff --git a/src/compiler/lexical_grammar.cc b/src/compiler/lexical_grammar.cc index a9159f6d..65fa9483 100644 --- a/src/compiler/lexical_grammar.cc +++ b/src/compiler/lexical_grammar.cc @@ -11,7 +11,7 @@ using std::pair; using std::vector; using std::set; -const rules::rule_ptr &LexicalGrammar::rule(const rules::Symbol &symbol) const { +const rule_ptr &LexicalGrammar::rule(const rules::Symbol &symbol) const { return symbol.is_auxiliary() ? aux_rules[symbol.index].second : rules[symbol.index].second; } diff --git a/src/compiler/lexical_grammar.h b/src/compiler/lexical_grammar.h index f1b4e183..bd11d41e 100644 --- a/src/compiler/lexical_grammar.h +++ b/src/compiler/lexical_grammar.h @@ -12,11 +12,11 @@ namespace tree_sitter { class LexicalGrammar { public: const std::string &rule_name(const rules::Symbol &symbol) const; - const rules::rule_ptr &rule(const rules::Symbol &symbol) const; + const rule_ptr &rule(const rules::Symbol &symbol) const; - std::vector> rules; - std::vector> aux_rules; - std::vector separators; + std::vector> rules; + std::vector> aux_rules; + std::vector separators; }; } // namespace tree_sitter diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index 9970be46..9890ff71 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -13,7 +13,7 @@ using rules::Symbol; ParseAction::ParseAction(ParseActionType type, ParseStateId state_index, Symbol symbol, size_t consumed_symbol_count, set precedence_values, - rules::Associativity associativity, int production_id) + Associativity associativity, int production_id) : type(type), symbol(symbol), state_index(state_index), @@ -27,7 +27,7 @@ ParseAction::ParseAction() symbol(Symbol(-1)), state_index(-1), consumed_symbol_count(0), - associativity(rules::AssociativityUnspecified) {} + associativity(AssociativityNone) {} ParseAction ParseAction::Error() { return ParseAction(); @@ -42,7 +42,7 @@ ParseAction ParseAction::Accept() { ParseAction ParseAction::Shift(ParseStateId state_index, set precedence_values) { return ParseAction(ParseActionTypeShift, state_index, Symbol(-1), 0, - precedence_values, rules::AssociativityUnspecified, -1); + precedence_values, AssociativityNone, -1); } ParseAction ParseAction::ShiftExtra() { @@ -59,8 +59,7 @@ ParseAction ParseAction::ReduceExtra(Symbol symbol) { } ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count, - int precedence, - rules::Associativity associativity, + int precedence, Associativity associativity, int production_id) { return ParseAction(ParseActionTypeReduce, 0, symbol, consumed_symbol_count, { precedence }, associativity, production_id); diff --git a/src/compiler/parse_table.h b/src/compiler/parse_table.h index ae8822a8..d13de3b6 100644 --- a/src/compiler/parse_table.h +++ b/src/compiler/parse_table.h @@ -26,8 +26,7 @@ typedef enum { class ParseAction { ParseAction(ParseActionType type, ParseStateId state_index, rules::Symbol symbol, size_t consumed_symbol_count, - std::set precedence_values, rules::Associativity, - int production_id); + std::set precedence_values, Associativity, int production_id); public: ParseAction(); @@ -36,8 +35,7 @@ class ParseAction { static ParseAction Shift(ParseStateId state_index, std::set precedence_values); static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count, - int precedence, rules::Associativity, - int production_id); + int precedence, Associativity, int production_id); static ParseAction ShiftExtra(); static ParseAction ReduceExtra(rules::Symbol symbol); bool operator==(const ParseAction &) const; @@ -48,7 +46,7 @@ class ParseAction { ParseStateId state_index; size_t consumed_symbol_count; std::set precedence_values; - rules::Associativity associativity; + Associativity associativity; int production_id; }; diff --git a/src/compiler/prepare_grammar/expand_repeats.cc b/src/compiler/prepare_grammar/expand_repeats.cc index ca578a7e..a08cf1a0 100644 --- a/src/compiler/prepare_grammar/expand_repeats.cc +++ b/src/compiler/prepare_grammar/expand_repeats.cc @@ -18,11 +18,9 @@ using std::vector; using std::pair; using std::to_string; using std::make_shared; -using rules::rule_ptr; using rules::Blank; using rules::Choice; using rules::Repeat; -using rules::Rule; using rules::Seq; using rules::Symbol; @@ -64,7 +62,7 @@ class ExpandRepeats : public rules::IdentityRuleFn { return apply(rule); } - vector> aux_rules; + vector> aux_rules; }; SyntaxGrammar expand_repeats(const SyntaxGrammar &grammar) { diff --git a/src/compiler/prepare_grammar/expand_tokens.cc b/src/compiler/prepare_grammar/expand_tokens.cc index b71f1d18..aaeb13ca 100644 --- a/src/compiler/prepare_grammar/expand_tokens.cc +++ b/src/compiler/prepare_grammar/expand_tokens.cc @@ -19,7 +19,6 @@ using std::string; using std::vector; using std::pair; using std::make_shared; -using rules::rule_ptr; using rules::String; using rules::Pattern; diff --git a/src/compiler/prepare_grammar/extract_tokens.cc b/src/compiler/prepare_grammar/extract_tokens.cc index ef94ea96..cfefea64 100644 --- a/src/compiler/prepare_grammar/extract_tokens.cc +++ b/src/compiler/prepare_grammar/extract_tokens.cc @@ -26,7 +26,6 @@ using std::set; using std::string; using std::tuple; using std::vector; -using rules::rule_ptr; using rules::Symbol; using rules::SymbolOptionToken; using rules::SymbolOptionAuxToken; @@ -62,7 +61,7 @@ class SymbolReplacer : public rules::IdentityRuleFn { }; class TokenExtractor : public rules::IdentityRuleFn { - rule_ptr apply_to_token(const rules::Rule *input) { + rule_ptr apply_to_token(const Rule *input) { auto rule = input->copy(); for (size_t i = 0; i < tokens.size(); i++) if (tokens[i].second->operator==(*rule)) { @@ -75,7 +74,7 @@ class TokenExtractor : public rules::IdentityRuleFn { return make_shared(index, SymbolOptionAuxToken); } - rule_ptr default_apply(const rules::Rule *rule) { + rule_ptr default_apply(const Rule *rule) { auto result = rule->copy(); if (is_token(result)) return apply_to_token(rule); diff --git a/src/compiler/prepare_grammar/intern_symbols.cc b/src/compiler/prepare_grammar/intern_symbols.cc index f611a63a..8cabff7c 100644 --- a/src/compiler/prepare_grammar/intern_symbols.cc +++ b/src/compiler/prepare_grammar/intern_symbols.cc @@ -4,6 +4,7 @@ #include #include "tree_sitter/compiler.h" #include "compiler/rules/visitor.h" +#include "compiler/rules/blank.h" #include "compiler/rules/named_symbol.h" #include "compiler/rules/symbol.h" @@ -11,7 +12,6 @@ namespace tree_sitter { namespace prepare_grammar { using std::string; -using rules::rule_ptr; using std::vector; using std::set; using std::pair; @@ -24,7 +24,7 @@ class InternSymbols : public rules::IdentityRuleFn { auto result = symbol_for_rule_name(rule->name); if (!result.get()) { missing_rule_name = rule->name; - return rules::blank(); + return rules::Blank::build(); } return result; } diff --git a/src/compiler/prepare_grammar/interned_grammar.h b/src/compiler/prepare_grammar/interned_grammar.h index a9ed9919..11398976 100644 --- a/src/compiler/prepare_grammar/interned_grammar.h +++ b/src/compiler/prepare_grammar/interned_grammar.h @@ -12,8 +12,8 @@ namespace tree_sitter { namespace prepare_grammar { struct InternedGrammar { - std::vector> rules; - std::set ubiquitous_tokens; + std::vector> rules; + std::set ubiquitous_tokens; std::set> expected_conflicts; }; diff --git a/src/compiler/prepare_grammar/is_token.cc b/src/compiler/prepare_grammar/is_token.cc index 488d49d0..37bb4399 100644 --- a/src/compiler/prepare_grammar/is_token.cc +++ b/src/compiler/prepare_grammar/is_token.cc @@ -20,7 +20,7 @@ class IsToken : public rules::RuleFn { } }; -bool is_token(const rules::rule_ptr &rule) { +bool is_token(const rule_ptr &rule) { return IsToken().apply(rule); } diff --git a/src/compiler/prepare_grammar/is_token.h b/src/compiler/prepare_grammar/is_token.h index 0a40f10d..1e7164f4 100644 --- a/src/compiler/prepare_grammar/is_token.h +++ b/src/compiler/prepare_grammar/is_token.h @@ -6,7 +6,7 @@ namespace tree_sitter { namespace prepare_grammar { -bool is_token(const rules::rule_ptr &); +bool is_token(const rule_ptr &); } // namespace prepare_grammar } // namespace tree_sitter diff --git a/src/compiler/prepare_grammar/parse_regex.cc b/src/compiler/prepare_grammar/parse_regex.cc index 823f7bb5..c05de141 100644 --- a/src/compiler/prepare_grammar/parse_regex.cc +++ b/src/compiler/prepare_grammar/parse_regex.cc @@ -17,13 +17,11 @@ using std::string; using std::vector; using std::pair; using std::make_shared; -using rules::rule_ptr; using rules::CharacterSet; using rules::Seq; using rules::Blank; using rules::Choice; using rules::Repeat; -using rules::blank; class PatternParser { public: @@ -45,7 +43,7 @@ class PatternParser { } auto pair = term(nested); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; choices.push_back(pair.first); } while (has_more_input()); auto rule = @@ -55,7 +53,7 @@ class PatternParser { private: pair term(bool nested) { - rule_ptr result = blank(); + rule_ptr result = Blank::build(); do { if (peek() == '|') break; @@ -63,7 +61,7 @@ class PatternParser { break; auto pair = factor(); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; result = Seq::build({ result, pair.first }); } while (has_more_input()); return { result, nullptr }; @@ -72,7 +70,7 @@ class PatternParser { pair factor() { auto pair = atom(); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; rule_ptr result = pair.first; if (has_more_input()) { switch (peek()) { @@ -99,7 +97,7 @@ class PatternParser { next(); auto pair = rule(true); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; if (peek() != ')') return error("unmatched open paren"); next(); @@ -109,7 +107,7 @@ class PatternParser { next(); auto pair = char_set(); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; if (peek() != ']') return error("unmatched open square bracket"); next(); @@ -128,7 +126,7 @@ class PatternParser { default: { auto pair = single_char(); if (pair.second) - return { blank(), pair.second }; + return { Blank::build(), pair.second }; return { pair.first.copy(), nullptr }; } } @@ -220,7 +218,7 @@ class PatternParser { } pair error(string msg) { - return { blank(), new GrammarError(GrammarErrorTypeRegex, msg) }; + return { Blank::build(), new GrammarError(GrammarErrorTypeRegex, msg) }; } string input; diff --git a/src/compiler/prepare_grammar/parse_regex.h b/src/compiler/prepare_grammar/parse_regex.h index f1c12970..2d5d86f5 100644 --- a/src/compiler/prepare_grammar/parse_regex.h +++ b/src/compiler/prepare_grammar/parse_regex.h @@ -8,7 +8,7 @@ namespace tree_sitter { namespace prepare_grammar { -std::pair parse_regex(const std::string &); +std::pair parse_regex(const std::string &); } // namespace prepare_grammar } // namespace tree_sitter diff --git a/src/compiler/prepare_grammar/token_description.cc b/src/compiler/prepare_grammar/token_description.cc index 19877708..d0294546 100644 --- a/src/compiler/prepare_grammar/token_description.cc +++ b/src/compiler/prepare_grammar/token_description.cc @@ -38,7 +38,7 @@ class TokenDescription : public rules::RuleFn { } }; -std::string token_description(const rules::rule_ptr &rule) { +std::string token_description(const rule_ptr &rule) { return TokenDescription().apply(rule); } diff --git a/src/compiler/prepare_grammar/token_description.h b/src/compiler/prepare_grammar/token_description.h index bd6a87cb..0c15c949 100644 --- a/src/compiler/prepare_grammar/token_description.h +++ b/src/compiler/prepare_grammar/token_description.h @@ -7,7 +7,7 @@ namespace tree_sitter { namespace prepare_grammar { -std::string token_description(const rules::rule_ptr &); +std::string token_description(const rule_ptr &); } // namespace prepare_grammar } // namespace tree_sitter diff --git a/src/compiler/rules/rule.cc b/src/compiler/rule.cc similarity index 86% rename from src/compiler/rules/rule.cc rename to src/compiler/rule.cc index 99282985..828e26d0 100644 --- a/src/compiler/rules/rule.cc +++ b/src/compiler/rule.cc @@ -1,8 +1,7 @@ -#include "compiler/rules/rule.h" +#include "compiler/rule.h" #include namespace tree_sitter { -namespace rules { using std::ostream; using std::string; @@ -25,5 +24,4 @@ ostream &operator<<(ostream &stream, const rule_ptr &rule) { Rule::~Rule() {} -} // namespace rules } // namespace tree_sitter diff --git a/src/compiler/rules/rule.h b/src/compiler/rule.h similarity index 83% rename from src/compiler/rules/rule.h rename to src/compiler/rule.h index 02e63d55..e42dd523 100644 --- a/src/compiler/rules/rule.h +++ b/src/compiler/rule.h @@ -5,11 +5,12 @@ #include namespace tree_sitter { + namespace rules { - class Visitor; -class Rule; +} // namespace rules +class Rule; typedef std::shared_ptr rule_ptr; class Rule { @@ -19,21 +20,20 @@ class Rule { virtual size_t hash_code() const = 0; virtual rule_ptr copy() const = 0; virtual std::string to_string() const = 0; - virtual void accept(Visitor *visitor) const = 0; + virtual void accept(rules::Visitor *visitor) const = 0; virtual ~Rule(); }; std::ostream &operator<<(std::ostream &stream, const Rule &rule); std::ostream &operator<<(std::ostream &stream, const rule_ptr &rule); -} // namespace rules } // namespace tree_sitter namespace std { template <> -struct hash { - size_t operator()(const tree_sitter::rules::rule_ptr &rule) const { +struct hash { + size_t operator()(const tree_sitter::rule_ptr &rule) const { return typeid(*rule).hash_code() ^ rule->hash_code(); } }; diff --git a/src/compiler/rules/blank.cc b/src/compiler/rules/blank.cc index 4281eba6..b5eee146 100644 --- a/src/compiler/rules/blank.cc +++ b/src/compiler/rules/blank.cc @@ -1,5 +1,6 @@ #include "compiler/rules/blank.h" #include +#include #include "compiler/rules/visitor.h" namespace tree_sitter { @@ -7,6 +8,10 @@ namespace rules { Blank::Blank() {} +rule_ptr Blank::build() { + return std::make_shared(); +} + bool Blank::operator==(const Rule &rule) const { return dynamic_cast(&rule) != nullptr; } diff --git a/src/compiler/rules/blank.h b/src/compiler/rules/blank.h index 2ddc8e2e..e67d213d 100644 --- a/src/compiler/rules/blank.h +++ b/src/compiler/rules/blank.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_BLANK_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { @@ -10,6 +10,7 @@ namespace rules { class Blank : public Rule { public: Blank(); + static rule_ptr build(); bool operator==(const Rule &other) const; size_t hash_code() const; diff --git a/src/compiler/rules/character_set.h b/src/compiler/rules/character_set.h index 0e19173b..f1469d72 100644 --- a/src/compiler/rules/character_set.h +++ b/src/compiler/rules/character_set.h @@ -6,7 +6,7 @@ #include #include #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" #include "compiler/rules/character_range.h" namespace tree_sitter { diff --git a/src/compiler/rules/choice.h b/src/compiler/rules/choice.h index 761ce8a7..1139ae6a 100644 --- a/src/compiler/rules/choice.h +++ b/src/compiler/rules/choice.h @@ -3,7 +3,7 @@ #include #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/metadata.h b/src/compiler/rules/metadata.h index 2933e679..48b856cc 100644 --- a/src/compiler/rules/metadata.h +++ b/src/compiler/rules/metadata.h @@ -4,7 +4,7 @@ #include #include #include "tree_sitter/compiler.h" -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { @@ -16,8 +16,6 @@ enum MetadataKey { ASSOCIATIVITY, }; -const Associativity AssociativityUnspecified = (Associativity)0; - class Metadata : public Rule { public: Metadata(rule_ptr rule, std::map value); diff --git a/src/compiler/rules/named_symbol.h b/src/compiler/rules/named_symbol.h index 08b8c508..2d265d0f 100644 --- a/src/compiler/rules/named_symbol.h +++ b/src/compiler/rules/named_symbol.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_NAMED_SYMBOL_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/pattern.cc b/src/compiler/rules/pattern.cc index 1d6fff39..83d44698 100644 --- a/src/compiler/rules/pattern.cc +++ b/src/compiler/rules/pattern.cc @@ -11,7 +11,7 @@ using std::hash; Pattern::Pattern(const string &string) : value(string) {} -bool Pattern::operator==(tree_sitter::rules::Rule const &other) const { +bool Pattern::operator==(tree_sitter::Rule const &other) const { auto pattern = dynamic_cast(&other); return pattern && (pattern->value == value); } diff --git a/src/compiler/rules/pattern.h b/src/compiler/rules/pattern.h index de50f851..305f7024 100644 --- a/src/compiler/rules/pattern.h +++ b/src/compiler/rules/pattern.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_PATTERN_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/repeat.h b/src/compiler/rules/repeat.h index fd0862ea..35e4531a 100644 --- a/src/compiler/rules/repeat.h +++ b/src/compiler/rules/repeat.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_REPEAT_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/rules.cc b/src/compiler/rules/rules.cc index 89f9bf64..6484d8a2 100644 --- a/src/compiler/rules/rules.cc +++ b/src/compiler/rules/rules.cc @@ -3,7 +3,7 @@ #include #include #include "tree_sitter/compiler.h" -#include "compiler/rules/rule.h" +#include "compiler/rule.h" #include "compiler/rules/blank.h" #include "compiler/rules/named_symbol.h" #include "compiler/rules/choice.h" @@ -16,7 +16,6 @@ #include "compiler/rules/built_in_symbols.h" namespace tree_sitter { -namespace rules { using std::make_shared; using std::string; @@ -24,45 +23,45 @@ using std::set; using std::vector; using std::map; -static rule_ptr metadata(rule_ptr rule, map values) { - return std::make_shared(rule, values); +static rule_ptr metadata(rule_ptr rule, map values) { + return std::make_shared(rule, values); } rule_ptr blank() { - return make_shared(); + return rules::Blank::build(); } rule_ptr choice(const vector &rules) { - return Choice::build(rules); + return rules::Choice::build(rules); } rule_ptr repeat(const rule_ptr &content) { - return Repeat::build(content); + return rules::Repeat::build(content); } rule_ptr seq(const vector &rules) { - return Seq::build(rules); + return rules::Seq::build(rules); } rule_ptr sym(const string &name) { - return make_shared(name); + return make_shared(name); } rule_ptr pattern(const string &value) { - return make_shared(value); + return make_shared(value); } rule_ptr str(const string &value) { - return token(prec(1, make_shared(value))); + return token(prec(1, make_shared(value))); } rule_ptr err(const rule_ptr &rule) { - return choice({ rule, ERROR().copy() }); + return choice({ rule, rules::ERROR().copy() }); } rule_ptr prec(int precedence, const rule_ptr &rule, Associativity associativity) { - return metadata( - rule, { { PRECEDENCE, precedence }, { ASSOCIATIVITY, associativity } }); + return metadata(rule, { { rules::PRECEDENCE, precedence }, + { rules::ASSOCIATIVITY, associativity } }); } rule_ptr prec(int precedence, const rule_ptr &rule) { @@ -70,8 +69,7 @@ rule_ptr prec(int precedence, const rule_ptr &rule) { } rule_ptr token(const rule_ptr &rule) { - return metadata(rule, { { IS_TOKEN, 1 } }); + return metadata(rule, { { rules::IS_TOKEN, 1 } }); } -} // namespace rules } // namespace tree_sitter diff --git a/src/compiler/rules/seq.h b/src/compiler/rules/seq.h index 29238848..b331cf77 100644 --- a/src/compiler/rules/seq.h +++ b/src/compiler/rules/seq.h @@ -3,7 +3,7 @@ #include #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/string.h b/src/compiler/rules/string.h index 6a6dc534..4398b560 100644 --- a/src/compiler/rules/string.h +++ b/src/compiler/rules/string.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_STRING_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/symbol.h b/src/compiler/rules/symbol.h index 25023cd9..a1c62b54 100644 --- a/src/compiler/rules/symbol.h +++ b/src/compiler/rules/symbol.h @@ -2,7 +2,7 @@ #define COMPILER_RULES_SYMBOL_H_ #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/rules/visitor.cc b/src/compiler/rules/visitor.cc index 2df87033..db3600ce 100644 --- a/src/compiler/rules/visitor.cc +++ b/src/compiler/rules/visitor.cc @@ -1,6 +1,6 @@ #include "compiler/rules/visitor.h" #include -#include "compiler/rules/rule.h" +#include "compiler/rule.h" #include "compiler/rules/blank.h" #include "compiler/rules/character_set.h" #include "compiler/rules/choice.h" diff --git a/src/compiler/rules/visitor.h b/src/compiler/rules/visitor.h index b1331b48..baece1a9 100644 --- a/src/compiler/rules/visitor.h +++ b/src/compiler/rules/visitor.h @@ -1,7 +1,7 @@ #ifndef COMPILER_RULES_VISITOR_H_ #define COMPILER_RULES_VISITOR_H_ -#include "compiler/rules/rule.h" +#include "compiler/rule.h" namespace tree_sitter { namespace rules { diff --git a/src/compiler/syntax_grammar.cc b/src/compiler/syntax_grammar.cc index 8f827647..959a879f 100644 --- a/src/compiler/syntax_grammar.cc +++ b/src/compiler/syntax_grammar.cc @@ -8,7 +8,7 @@ namespace tree_sitter { using std::string; -const rules::rule_ptr &SyntaxGrammar::rule(const rules::Symbol &symbol) const { +const rule_ptr &SyntaxGrammar::rule(const rules::Symbol &symbol) const { return symbol.is_auxiliary() ? aux_rules[symbol.index].second : rules[symbol.index].second; } diff --git a/src/compiler/syntax_grammar.h b/src/compiler/syntax_grammar.h index 42f2e6fc..ad636a1e 100644 --- a/src/compiler/syntax_grammar.h +++ b/src/compiler/syntax_grammar.h @@ -13,10 +13,10 @@ namespace tree_sitter { class SyntaxGrammar { public: const std::string &rule_name(const rules::Symbol &symbol) const; - const rules::rule_ptr &rule(const rules::Symbol &symbol) const; + const rule_ptr &rule(const rules::Symbol &symbol) const; - std::vector> rules; - std::vector> aux_rules; + std::vector> rules; + std::vector> aux_rules; std::set ubiquitous_tokens; std::set> expected_conflicts; };