Tidy up get_metadata function
This commit is contained in:
parent
b23caf366f
commit
6415690738
2 changed files with 10 additions and 7 deletions
|
|
@ -9,6 +9,10 @@ int get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key) {
|
|||
class GetMetadata : public rules::RuleFn<int> {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue