Auto-format: no single-line functions
This commit is contained in:
parent
e89ec7c85e
commit
c18351772a
24 changed files with 243 additions and 77 deletions
|
|
@ -11,13 +11,21 @@ bool Blank::operator==(const Rule &rule) const {
|
|||
return dynamic_cast<const Blank *>(&rule) != nullptr;
|
||||
}
|
||||
|
||||
size_t Blank::hash_code() const { return 0; }
|
||||
size_t Blank::hash_code() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rule_ptr Blank::copy() const { return std::make_shared<Blank>(); }
|
||||
rule_ptr Blank::copy() const {
|
||||
return std::make_shared<Blank>();
|
||||
}
|
||||
|
||||
std::string Blank::to_string() const { return "(blank)"; }
|
||||
std::string Blank::to_string() const {
|
||||
return "(blank)";
|
||||
}
|
||||
|
||||
void Blank::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Blank::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -3,10 +3,21 @@
|
|||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
||||
Symbol END_OF_INPUT() { return Symbol(-1, SymbolOptionToken); }
|
||||
Symbol ERROR() { return Symbol(-2, SymbolOptionToken); }
|
||||
Symbol START() { return Symbol(-3); }
|
||||
Symbol DOCUMENT() { return Symbol(-4); }
|
||||
Symbol END_OF_INPUT() {
|
||||
return Symbol(-1, SymbolOptionToken);
|
||||
}
|
||||
|
||||
Symbol ERROR() {
|
||||
return Symbol(-2, SymbolOptionToken);
|
||||
}
|
||||
|
||||
Symbol START() {
|
||||
return Symbol(-3);
|
||||
}
|
||||
|
||||
Symbol DOCUMENT() {
|
||||
return Symbol(-4);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -140,9 +140,13 @@ CharacterSet &CharacterSet::exclude(uint32_t min, uint32_t max) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
CharacterSet &CharacterSet::include(uint32_t c) { return include(c, c); }
|
||||
CharacterSet &CharacterSet::include(uint32_t c) {
|
||||
return include(c, c);
|
||||
}
|
||||
|
||||
CharacterSet &CharacterSet::exclude(uint32_t c) { return exclude(c, c); }
|
||||
CharacterSet &CharacterSet::exclude(uint32_t c) {
|
||||
return exclude(c, c);
|
||||
}
|
||||
|
||||
bool CharacterSet::is_empty() const {
|
||||
return !includes_all && included_chars.empty();
|
||||
|
|
@ -186,7 +190,9 @@ vector<CharacterRange> CharacterSet::excluded_ranges() const {
|
|||
return consolidate_ranges(excluded_chars);
|
||||
}
|
||||
|
||||
void CharacterSet::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void CharacterSet::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -57,7 +57,9 @@ size_t Choice::hash_code() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
rule_ptr Choice::copy() const { return std::make_shared<Choice>(*this); }
|
||||
rule_ptr Choice::copy() const {
|
||||
return std::make_shared<Choice>(*this);
|
||||
}
|
||||
|
||||
string Choice::to_string() const {
|
||||
string result = "(choice";
|
||||
|
|
@ -66,7 +68,9 @@ string Choice::to_string() const {
|
|||
return result + ")";
|
||||
}
|
||||
|
||||
void Choice::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Choice::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ std::string Metadata::to_string() const {
|
|||
return "(metadata " + rule->to_string() + ")";
|
||||
}
|
||||
|
||||
void Metadata::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Metadata::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -15,15 +15,21 @@ bool NamedSymbol::operator==(const Rule &rule) const {
|
|||
return other && other->name == name;
|
||||
}
|
||||
|
||||
size_t NamedSymbol::hash_code() const { return hash<string>()(name); }
|
||||
size_t NamedSymbol::hash_code() const {
|
||||
return hash<string>()(name);
|
||||
}
|
||||
|
||||
rule_ptr NamedSymbol::copy() const {
|
||||
return std::make_shared<NamedSymbol>(*this);
|
||||
}
|
||||
|
||||
string NamedSymbol::to_string() const { return string("(sym '") + name + "')"; }
|
||||
string NamedSymbol::to_string() const {
|
||||
return string("(sym '") + name + "')";
|
||||
}
|
||||
|
||||
void NamedSymbol::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void NamedSymbol::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -16,15 +16,21 @@ bool Pattern::operator==(tree_sitter::rules::Rule const &other) const {
|
|||
return pattern && (pattern->value == value);
|
||||
}
|
||||
|
||||
size_t Pattern::hash_code() const { return hash<string>()(value); }
|
||||
size_t Pattern::hash_code() const {
|
||||
return hash<string>()(value);
|
||||
}
|
||||
|
||||
rule_ptr Pattern::copy() const { return std::make_shared<Pattern>(*this); }
|
||||
rule_ptr Pattern::copy() const {
|
||||
return std::make_shared<Pattern>(*this);
|
||||
}
|
||||
|
||||
string Pattern::to_string() const {
|
||||
return string("(pattern '") + util::escape_string(value) + "')";
|
||||
}
|
||||
|
||||
void Pattern::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Pattern::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -25,15 +25,21 @@ bool Repeat::operator==(const Rule &rule) const {
|
|||
return other && (*other->content == *content);
|
||||
}
|
||||
|
||||
size_t Repeat::hash_code() const { return content->hash_code(); }
|
||||
size_t Repeat::hash_code() const {
|
||||
return content->hash_code();
|
||||
}
|
||||
|
||||
rule_ptr Repeat::copy() const { return make_shared<Repeat>(*this); }
|
||||
rule_ptr Repeat::copy() const {
|
||||
return make_shared<Repeat>(*this);
|
||||
}
|
||||
|
||||
string Repeat::to_string() const {
|
||||
return string("(repeat ") + content->to_string() + ")";
|
||||
}
|
||||
|
||||
void Repeat::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Repeat::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -28,23 +28,37 @@ static rule_ptr metadata(rule_ptr rule, map<MetadataKey, int> values) {
|
|||
return std::make_shared<Metadata>(rule, values);
|
||||
}
|
||||
|
||||
rule_ptr blank() { return make_shared<Blank>(); }
|
||||
rule_ptr blank() {
|
||||
return make_shared<Blank>();
|
||||
}
|
||||
|
||||
rule_ptr choice(const vector<rule_ptr> &rules) { return Choice::build(rules); }
|
||||
rule_ptr choice(const vector<rule_ptr> &rules) {
|
||||
return Choice::build(rules);
|
||||
}
|
||||
|
||||
rule_ptr repeat(const rule_ptr &content) { return Repeat::build(content); }
|
||||
rule_ptr repeat(const rule_ptr &content) {
|
||||
return Repeat::build(content);
|
||||
}
|
||||
|
||||
rule_ptr seq(const vector<rule_ptr> &rules) { return Seq::build(rules); }
|
||||
rule_ptr seq(const vector<rule_ptr> &rules) {
|
||||
return Seq::build(rules);
|
||||
}
|
||||
|
||||
rule_ptr sym(const string &name) { return make_shared<NamedSymbol>(name); }
|
||||
rule_ptr sym(const string &name) {
|
||||
return make_shared<NamedSymbol>(name);
|
||||
}
|
||||
|
||||
rule_ptr pattern(const string &value) { return make_shared<Pattern>(value); }
|
||||
rule_ptr pattern(const string &value) {
|
||||
return make_shared<Pattern>(value);
|
||||
}
|
||||
|
||||
rule_ptr str(const string &value) {
|
||||
return token(prec(1, make_shared<String>(value)));
|
||||
}
|
||||
|
||||
rule_ptr err(const rule_ptr &rule) { return choice({ rule, ERROR().copy() }); }
|
||||
rule_ptr err(const rule_ptr &rule) {
|
||||
return choice({ rule, ERROR().copy() });
|
||||
}
|
||||
|
||||
rule_ptr prec(int precedence, const rule_ptr &rule, Associativity associativity) {
|
||||
return metadata(
|
||||
|
|
|
|||
|
|
@ -25,15 +25,21 @@ bool Seq::operator==(const Rule &rule) const {
|
|||
return other && (*other->left == *left) && (*other->right == *right);
|
||||
}
|
||||
|
||||
size_t Seq::hash_code() const { return left->hash_code() ^ right->hash_code(); }
|
||||
size_t Seq::hash_code() const {
|
||||
return left->hash_code() ^ right->hash_code();
|
||||
}
|
||||
|
||||
rule_ptr Seq::copy() const { return std::make_shared<Seq>(*this); }
|
||||
rule_ptr Seq::copy() const {
|
||||
return std::make_shared<Seq>(*this);
|
||||
}
|
||||
|
||||
string Seq::to_string() const {
|
||||
return string("(seq ") + left->to_string() + " " + right->to_string() + ")";
|
||||
}
|
||||
|
||||
void Seq::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Seq::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -15,13 +15,21 @@ bool String::operator==(const Rule &rule) const {
|
|||
return other && (other->value == value);
|
||||
}
|
||||
|
||||
size_t String::hash_code() const { return hash<string>()(value); }
|
||||
size_t String::hash_code() const {
|
||||
return hash<string>()(value);
|
||||
}
|
||||
|
||||
rule_ptr String::copy() const { return std::make_shared<String>(*this); }
|
||||
rule_ptr String::copy() const {
|
||||
return std::make_shared<String>(*this);
|
||||
}
|
||||
|
||||
string String::to_string() const { return string("(string '") + value + "')"; }
|
||||
string String::to_string() const {
|
||||
return string("(string '") + value + "')";
|
||||
}
|
||||
|
||||
void String::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void String::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ size_t Symbol::hash_code() const {
|
|||
return hash<int>()(index) ^ hash<int16_t>()(options);
|
||||
}
|
||||
|
||||
rule_ptr Symbol::copy() const { return std::make_shared<Symbol>(*this); }
|
||||
rule_ptr Symbol::copy() const {
|
||||
return std::make_shared<Symbol>(*this);
|
||||
}
|
||||
|
||||
string Symbol::to_string() const {
|
||||
string name = (options & SymbolOptionAuxiliary) ? "aux_" : "";
|
||||
|
|
@ -47,13 +49,21 @@ bool Symbol::operator<(const Symbol &other) const {
|
|||
return (index < other.index);
|
||||
}
|
||||
|
||||
bool Symbol::is_token() const { return options & SymbolOptionToken; }
|
||||
bool Symbol::is_token() const {
|
||||
return options & SymbolOptionToken;
|
||||
}
|
||||
|
||||
bool Symbol::is_built_in() const { return index < 0; }
|
||||
bool Symbol::is_built_in() const {
|
||||
return index < 0;
|
||||
}
|
||||
|
||||
bool Symbol::is_auxiliary() const { return options & SymbolOptionAuxiliary; }
|
||||
bool Symbol::is_auxiliary() const {
|
||||
return options & SymbolOptionAuxiliary;
|
||||
}
|
||||
|
||||
void Symbol::accept(Visitor *visitor) const { visitor->visit(this); }
|
||||
void Symbol::accept(Visitor *visitor) const {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -42,49 +42,89 @@ class RuleFn : private Visitor {
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual T default_apply(const Rule *rule) { return T(); }
|
||||
virtual T default_apply(const Rule *rule) {
|
||||
return T();
|
||||
}
|
||||
|
||||
virtual T apply_to(const Blank *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const CharacterSet *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Choice *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Metadata *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Pattern *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Repeat *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Seq *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const String *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const NamedSymbol *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
virtual T apply_to(const Symbol *rule) {
|
||||
return default_apply((const Rule *)rule);
|
||||
}
|
||||
|
||||
void visit(const Blank *rule) { value_ = apply_to(rule); }
|
||||
void visit(const CharacterSet *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Choice *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Metadata *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Pattern *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Repeat *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Seq *rule) { value_ = apply_to(rule); }
|
||||
void visit(const String *rule) { value_ = apply_to(rule); }
|
||||
void visit(const NamedSymbol *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Symbol *rule) { value_ = apply_to(rule); }
|
||||
void visit(const Blank *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const CharacterSet *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Choice *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Metadata *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Pattern *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Repeat *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Seq *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const String *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const NamedSymbol *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
void visit(const Symbol *rule) {
|
||||
value_ = apply_to(rule);
|
||||
}
|
||||
|
||||
private:
|
||||
T value_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue