From 64156907386c69bf28cc6732f4c0f275dae34e4b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 12 Oct 2014 13:04:11 -0700 Subject: [PATCH] Tidy up get_metadata function --- src/compiler/build_tables/get_metadata.cc | 7 ++++--- src/compiler/build_tables/get_metadata.h | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/build_tables/get_metadata.cc b/src/compiler/build_tables/get_metadata.cc index c172c623..da49d103 100644 --- a/src/compiler/build_tables/get_metadata.cc +++ b/src/compiler/build_tables/get_metadata.cc @@ -9,6 +9,10 @@ int get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key) { class GetMetadata : public rules::RuleFn { rules::MetadataKey metadata_key; + public: + explicit GetMetadata(rules::MetadataKey key) : metadata_key(key) {} + + protected: int apply_to(const rules::Metadata *rule) { int result = rule->value_for(metadata_key); return (result != 0) ? result : apply(rule->rule); @@ -18,9 +22,6 @@ int get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key) { // Remove this. It is currently needed to make the rule generated // by `LexTableBuilder::after_separators` have the right precedence. int apply_to(const rules::Seq *rule) { return apply(rule->left); } - - public: - explicit GetMetadata(rules::MetadataKey key) : metadata_key(key) {} }; return GetMetadata(key).apply(rule); diff --git a/src/compiler/build_tables/get_metadata.h b/src/compiler/build_tables/get_metadata.h index 6960b233..b876b62e 100644 --- a/src/compiler/build_tables/get_metadata.h +++ b/src/compiler/build_tables/get_metadata.h @@ -1,13 +1,15 @@ #ifndef COMPILER_BUILD_TABLES_GET_METADATA_H_ #define COMPILER_BUILD_TABLES_GET_METADATA_H_ -#include "compiler/rules/rule.h" #include "compiler/rules/metadata.h" +#include "tree_sitter/compiler.h" namespace tree_sitter { namespace build_tables { -int get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key); -} -} + +int get_metadata(const rules::rule_ptr &, rules::MetadataKey); + +} // namespace build_tables +} // namespace tree_sitter #endif // COMPILER_BUILD_TABLES_GET_METADATA_H_