tree-sitter/src/compiler/rules/visitor.cc

35 lines
1.1 KiB
C++
Raw Normal View History

2014-03-09 21:37:21 -07:00
#include "compiler/rules/visitor.h"
#include "compiler/rules/rule.h"
#include "compiler/rules/blank.h"
#include "compiler/rules/symbol.h"
2014-04-01 13:37:12 -07:00
#include "compiler/rules/character_set.h"
2014-03-09 21:37:21 -07:00
#include "compiler/rules/choice.h"
#include "compiler/rules/seq.h"
#include "compiler/rules/string.h"
#include "compiler/rules/metadata.h"
2014-03-09 21:37:21 -07:00
#include "compiler/rules/pattern.h"
#include "compiler/rules/repeat.h"
namespace tree_sitter {
namespace rules {
2014-04-09 13:14:46 -07:00
rule_ptr IdentityRuleFn::default_apply(const Rule *rule) {
return rule->copy();
2014-04-01 13:37:12 -07:00
}
2014-04-04 13:10:55 -07:00
2014-04-09 13:14:46 -07:00
rule_ptr IdentityRuleFn::apply_to(const Choice *rule) {
return Choice::Build({ apply(rule->left), apply(rule->right) });
2014-04-01 13:37:12 -07:00
}
2014-04-09 13:14:46 -07:00
rule_ptr IdentityRuleFn::apply_to(const Seq *rule) {
return Seq::Build({ apply(rule->left), apply(rule->right) });
2014-04-01 13:37:12 -07:00
}
2014-04-09 13:14:46 -07:00
rule_ptr IdentityRuleFn::apply_to(const Repeat *rule) {
return std::make_shared<Repeat>(apply(rule->content));
2014-04-01 13:37:12 -07:00
}
2014-04-09 13:14:46 -07:00
rule_ptr IdentityRuleFn::apply_to(const Metadata *rule) {
return std::make_shared<Metadata>(apply(rule->rule), rule->value);
}
}
}