From b23caf366f9bcad9c563f036c41427a14b8873bf Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 12 Oct 2014 13:02:39 -0700 Subject: [PATCH] Tidy up first_symbols function --- src/compiler/build_tables/first_symbols.cc | 17 +++++++++-------- src/compiler/build_tables/first_symbols.h | 7 +++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/build_tables/first_symbols.cc b/src/compiler/build_tables/first_symbols.cc index 81d4b637..421745b3 100644 --- a/src/compiler/build_tables/first_symbols.cc +++ b/src/compiler/build_tables/first_symbols.cc @@ -1,12 +1,12 @@ #include "compiler/build_tables/first_symbols.h" -#include "tree_sitter/compiler.h" -#include "compiler/prepared_grammar.h" #include "compiler/build_tables/rule_can_be_blank.h" -#include "compiler/rules/metadata.h" -#include "compiler/rules/visitor.h" -#include "compiler/rules/seq.h" +#include "compiler/prepared_grammar.h" #include "compiler/rules/choice.h" +#include "compiler/rules/metadata.h" +#include "compiler/rules/seq.h" #include "compiler/rules/symbol.h" +#include "compiler/rules/visitor.h" +#include "tree_sitter/compiler.h" namespace tree_sitter { namespace build_tables { @@ -21,6 +21,7 @@ class FirstSymbols : public rules::RuleFn> { public: explicit FirstSymbols(const SyntaxGrammar *grammar) : grammar(grammar) {} + protected: set apply_to(const Symbol *rule) { auto insertion_result = visited_symbols.insert(*rule); if (!insertion_result.second) @@ -41,9 +42,9 @@ class FirstSymbols : public rules::RuleFn> { set apply_to(const rules::Choice *rule) { set result; - for (const auto &el : rule->elements) { - auto &&next_syms = apply(el); - result.insert(next_syms.begin(), next_syms.end()); + for (const auto &element : rule->elements) { + auto &&element_symbols = apply(element); + result.insert(element_symbols.begin(), element_symbols.end()); } return result; } diff --git a/src/compiler/build_tables/first_symbols.h b/src/compiler/build_tables/first_symbols.h index 943bfe3e..09c32be5 100644 --- a/src/compiler/build_tables/first_symbols.h +++ b/src/compiler/build_tables/first_symbols.h @@ -2,8 +2,8 @@ #define COMPILER_BUILD_TABLES_FIRST_SYMBOLS_H_ #include -#include "compiler/build_tables/parse_item.h" #include "compiler/rules/symbol.h" +#include "tree_sitter/compiler.h" namespace tree_sitter { @@ -12,9 +12,8 @@ class SyntaxGrammar; namespace build_tables { /* - * Returns the set of terminal symbols that can appear at - * the beginning of a string derivable from a given rule, - * in a given grammar. + * 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, const SyntaxGrammar &grammar);