Remove all uses of 'using namespace'
This commit is contained in:
parent
de5deeeb69
commit
a4120f36d4
30 changed files with 95 additions and 60 deletions
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace tree_sitter {
|
||||
using std::set;
|
||||
using namespace rules;
|
||||
using rules::Symbol;
|
||||
|
||||
namespace build_tables {
|
||||
set<Symbol> set_union(const set<Symbol> &left, const set<Symbol> &right) {
|
||||
|
|
@ -17,10 +17,10 @@ namespace tree_sitter {
|
|||
return result;
|
||||
}
|
||||
|
||||
class FirstSet : public RuleFn<set<Symbol>> {
|
||||
class FirstSet : public rules::RuleFn<set<Symbol>> {
|
||||
const PreparedGrammar grammar;
|
||||
public:
|
||||
FirstSet(const PreparedGrammar &grammar) : grammar(grammar) {}
|
||||
explicit FirstSet(const PreparedGrammar &grammar) : grammar(grammar) {}
|
||||
|
||||
void visit(const Symbol *rule) {
|
||||
if (grammar.has_definition(*rule)) {
|
||||
|
|
@ -30,11 +30,11 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
void visit(const Choice *rule) {
|
||||
void visit(const rules::Choice *rule) {
|
||||
value = set_union(apply(rule->left), apply(rule->right));
|
||||
}
|
||||
|
||||
void visit(const Seq *rule) {
|
||||
void visit(const rules::Seq *rule) {
|
||||
auto result = apply(rule->left);
|
||||
if (rule_can_be_blank(rule->left, grammar)) {
|
||||
result = set_union(result, apply(rule->right));
|
||||
|
|
@ -43,7 +43,7 @@ namespace tree_sitter {
|
|||
}
|
||||
};
|
||||
|
||||
set<Symbol> first_set(const rule_ptr &rule, const PreparedGrammar &grammar) {
|
||||
set<Symbol> first_set(const rules::rule_ptr &rule, const PreparedGrammar &grammar) {
|
||||
return FirstSet(grammar).apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/build_tables/item_set_closure.h"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/build_tables/follow_sets.h"
|
||||
#include "compiler/build_tables/item.h"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/build_tables/item_set_transitions.h"
|
||||
#include <set>
|
||||
#include "compiler/build_tables/item_set_closure.h"
|
||||
#include "compiler/build_tables/rule_transitions.h"
|
||||
#include "compiler/build_tables/merge_transitions.h"
|
||||
|
|
|
|||
|
|
@ -8,28 +8,26 @@
|
|||
#include "compiler/rules/blank.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using namespace rules;
|
||||
|
||||
namespace build_tables {
|
||||
class CanBeBlank : public RuleFn<bool> {
|
||||
class CanBeBlank : public rules::RuleFn<bool> {
|
||||
protected:
|
||||
void default_visit(const Rule *) {
|
||||
void default_visit(const rules::Rule *) {
|
||||
value = false;
|
||||
}
|
||||
|
||||
virtual void visit(const Blank *) {
|
||||
virtual void visit(const rules::Blank *) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
virtual void visit(const Repeat *rule) {
|
||||
virtual void visit(const rules::Repeat *rule) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
virtual void visit(const Choice *rule) {
|
||||
virtual void visit(const rules::Choice *rule) {
|
||||
value = apply(rule->left) || apply(rule->right);
|
||||
}
|
||||
|
||||
virtual void visit(const Seq *rule) {
|
||||
virtual void visit(const rules::Seq *rule) {
|
||||
value = apply(rule->left) && apply(rule->right);
|
||||
}
|
||||
};
|
||||
|
|
@ -41,16 +39,16 @@ namespace tree_sitter {
|
|||
public:
|
||||
CanBeBlankRecursive(const PreparedGrammar &grammar) : grammar(grammar) {}
|
||||
|
||||
void visit(const Symbol *rule) {
|
||||
void visit(const rules::Symbol *rule) {
|
||||
value = grammar.has_definition(*rule) && apply(grammar.rule(*rule));
|
||||
}
|
||||
};
|
||||
|
||||
bool rule_can_be_blank(const rule_ptr &rule) {
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule) {
|
||||
return CanBeBlank().apply(rule);
|
||||
}
|
||||
|
||||
bool rule_can_be_blank(const rule_ptr &rule, const PreparedGrammar &grammar) {
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule, const PreparedGrammar &grammar) {
|
||||
return CanBeBlankRecursive(grammar).apply(rule);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/build_tables/rule_transitions.h"
|
||||
#include <set>
|
||||
#include "compiler/build_tables/rule_can_be_blank.h"
|
||||
#include "compiler/build_tables/merge_transitions.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
|
|
@ -14,7 +15,9 @@ namespace tree_sitter {
|
|||
using std::map;
|
||||
using std::set;
|
||||
using std::make_shared;
|
||||
using namespace rules;
|
||||
using rules::rule_ptr;
|
||||
using rules::Symbol;
|
||||
using rules::CharacterSet;
|
||||
|
||||
namespace build_tables {
|
||||
template<typename T>
|
||||
|
|
@ -23,7 +26,7 @@ namespace tree_sitter {
|
|||
template<>
|
||||
map<CharacterSet, rule_ptr> merge_transitions(const map<CharacterSet, rule_ptr> &left, const map<CharacterSet, rule_ptr> &right) {
|
||||
auto transitions = merge_char_transitions<rule_ptr>(left, right, [](rule_ptr left, rule_ptr right) {
|
||||
return make_shared<Choice>(left, right);
|
||||
return make_shared<rules::Choice>(left, right);
|
||||
});
|
||||
return *static_cast<map<CharacterSet, rule_ptr> *>(&transitions);
|
||||
}
|
||||
|
|
@ -31,7 +34,7 @@ namespace tree_sitter {
|
|||
template<>
|
||||
map<Symbol, rule_ptr> merge_transitions(const map<Symbol, rule_ptr> &left, const map<Symbol, rule_ptr> &right) {
|
||||
auto transitions = merge_sym_transitions<rule_ptr>(left, right, [](rule_ptr left, rule_ptr right) {
|
||||
return make_shared<Choice>(left, right);
|
||||
return make_shared<rules::Choice>(left, right);
|
||||
});
|
||||
return *static_cast<map<Symbol, rule_ptr> *>(&transitions);
|
||||
}
|
||||
|
|
@ -45,11 +48,11 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
class RuleTransitions : public RuleFn<map<T, rule_ptr>> {
|
||||
void visit_atom(const Rule *rule) {
|
||||
class RuleTransitions : public rules::RuleFn<map<T, rule_ptr>> {
|
||||
void visit_atom(const rules::Rule *rule) {
|
||||
auto atom = dynamic_cast<const T *>(rule);
|
||||
if (atom)
|
||||
this->value = map<T, rule_ptr>({{ *atom, make_shared<Blank>() }});
|
||||
this->value = map<T, rule_ptr>({{ *atom, make_shared<rules::Blank>() }});
|
||||
}
|
||||
|
||||
void visit(const CharacterSet *rule) {
|
||||
|
|
@ -60,34 +63,34 @@ namespace tree_sitter {
|
|||
visit_atom(rule);
|
||||
}
|
||||
|
||||
void visit(const Choice *rule) {
|
||||
void visit(const rules::Choice *rule) {
|
||||
this->value = merge_transitions<T>(this->apply(rule->left),
|
||||
this->apply(rule->right));
|
||||
}
|
||||
|
||||
void visit(const Seq *rule) {
|
||||
void visit(const rules::Seq *rule) {
|
||||
auto result = map_transitions(this->apply(rule->left), [&](const rule_ptr left_rule) {
|
||||
return Seq::Build({ left_rule, rule->right });
|
||||
return rules::Seq::Build({ left_rule, rule->right });
|
||||
});
|
||||
if (rule_can_be_blank(rule->left))
|
||||
result = merge_transitions<T>(result, this->apply(rule->right));
|
||||
this->value = result;
|
||||
}
|
||||
|
||||
void visit(const Repeat *rule) {
|
||||
void visit(const rules::Repeat *rule) {
|
||||
this->value = map_transitions(this->apply(rule->content), [&](const rule_ptr &value) {
|
||||
return Seq::Build({ value, make_shared<Choice>(rule->copy(), make_shared<Blank>()) });
|
||||
return rules::Seq::Build({ value, make_shared<rules::Choice>(rule->copy(), make_shared<rules::Blank>()) });
|
||||
});
|
||||
}
|
||||
|
||||
void visit(const String *rule) {
|
||||
rule_ptr result = make_shared<Blank>();
|
||||
void visit(const rules::String *rule) {
|
||||
rule_ptr result = make_shared<rules::Blank>();
|
||||
for (char val : rule->value)
|
||||
result = Seq::Build({ result, make_shared<CharacterSet>(set<CharacterRange>({ val })) });
|
||||
result = rules::Seq::Build({ result, make_shared<CharacterSet>(set<rules::CharacterRange>({ val })) });
|
||||
this->value = this->apply(result);
|
||||
}
|
||||
|
||||
void visit(const Pattern *rule) {
|
||||
void visit(const rules::Pattern *rule) {
|
||||
this->value = this->apply(rule->to_rule_tree());
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "compiler/generate_code/c_code.h"
|
||||
#include "compiler/generate_code/helpers.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_GENERATE_CODE_C_CODE_H_
|
||||
#define COMPILER_GENERATE_CODE_C_CODE_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/parse_table.h"
|
||||
#include "compiler/lex_table.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/parse_table.h"
|
||||
#include <string>
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::string;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
#define COMPILER_PARSE_TABLE_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "compiler/lex_table.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/prepare_grammar/expand_repeats.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "compiler/prepared_grammar.h"
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include "compiler/rules/seq.h"
|
||||
|
|
@ -13,32 +14,32 @@ namespace tree_sitter {
|
|||
using std::to_string;
|
||||
using std::map;
|
||||
using std::make_shared;
|
||||
using namespace rules;
|
||||
using rules::rule_ptr;
|
||||
|
||||
namespace prepare_grammar {
|
||||
class ExpandRepeats : public RuleFn<rule_ptr> {
|
||||
class ExpandRepeats : public rules::RuleFn<rule_ptr> {
|
||||
rule_ptr make_repeat_helper(string name, const rule_ptr &rule) {
|
||||
return Choice::Build({
|
||||
Seq::Build({ rule, make_shared<Symbol>(name, SymbolTypeAuxiliary) }),
|
||||
make_shared<Blank>() });
|
||||
return rules::Choice::Build({
|
||||
rules::Seq::Build({ rule, make_shared<rules::Symbol>(name, rules::SymbolTypeAuxiliary) }),
|
||||
make_shared<rules::Blank>() });
|
||||
}
|
||||
|
||||
void visit(const Repeat *rule) {
|
||||
void visit(const rules::Repeat *rule) {
|
||||
rule_ptr inner_rule = apply(rule->content);
|
||||
string helper_rule_name = string("repeat_helper") + to_string(aux_rules.size() + 1);
|
||||
aux_rules.insert({ helper_rule_name, make_repeat_helper(helper_rule_name, inner_rule) });
|
||||
value = make_shared<Symbol>(helper_rule_name, SymbolTypeAuxiliary);
|
||||
value = make_shared<rules::Symbol>(helper_rule_name, rules::SymbolTypeAuxiliary);
|
||||
}
|
||||
|
||||
void visit(const Seq *rule) {
|
||||
value = Seq::Build({ apply(rule->left), apply(rule->right) });
|
||||
void visit(const rules::Seq *rule) {
|
||||
value = rules::Seq::Build({ apply(rule->left), apply(rule->right) });
|
||||
}
|
||||
|
||||
void visit(const Choice *rule) {
|
||||
value = Choice::Build({ apply(rule->left), apply(rule->right) });
|
||||
void visit(const rules::Choice *rule) {
|
||||
value = rules::Choice::Build({ apply(rule->left), apply(rule->right) });
|
||||
}
|
||||
|
||||
void default_visit(const Rule *rule) {
|
||||
void default_visit(const rules::Rule *rule) {
|
||||
value = rule->copy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/prepare_grammar/extract_tokens.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/prepared_grammar.h"
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
|
@ -17,24 +18,24 @@ namespace tree_sitter {
|
|||
using std::to_string;
|
||||
using std::map;
|
||||
using std::make_shared;
|
||||
using namespace rules;
|
||||
using rules::rule_ptr;
|
||||
|
||||
namespace prepare_grammar {
|
||||
class IsToken : public RuleFn<bool> {
|
||||
void default_visit(const Rule *rule) {
|
||||
class IsToken : public rules::RuleFn<bool> {
|
||||
void default_visit(const rules::Rule *rule) {
|
||||
value = false;
|
||||
}
|
||||
|
||||
void visit(const String *rule) {
|
||||
void visit(const rules::String *rule) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
void visit(const Pattern *rule) {
|
||||
void visit(const rules::Pattern *rule) {
|
||||
value = true;
|
||||
}
|
||||
};
|
||||
|
||||
class TokenExtractor : public RuleFn<rule_ptr> {
|
||||
class TokenExtractor : public rules::RuleFn<rule_ptr> {
|
||||
string add_token(const rule_ptr &rule) {
|
||||
for (auto pair : tokens)
|
||||
if (*pair.second == *rule)
|
||||
|
|
@ -44,25 +45,25 @@ namespace tree_sitter {
|
|||
return name;
|
||||
}
|
||||
|
||||
void default_visit(const Rule *rule) {
|
||||
void default_visit(const rules::Rule *rule) {
|
||||
auto result = rule->copy();
|
||||
if (IsToken().apply(result)) {
|
||||
value = make_shared<Symbol>(add_token(result), SymbolTypeAuxiliary);
|
||||
value = make_shared<rules::Symbol>(add_token(result), rules::SymbolTypeAuxiliary);
|
||||
} else {
|
||||
value = result;
|
||||
}
|
||||
}
|
||||
|
||||
void visit(const Choice *rule) {
|
||||
value = Choice::Build({ apply(rule->left), apply(rule->right) });
|
||||
void visit(const rules::Choice *rule) {
|
||||
value = rules::Choice::Build({ apply(rule->left), apply(rule->right) });
|
||||
}
|
||||
|
||||
void visit(const Seq *rule) {
|
||||
value = Seq::Build({ apply(rule->left), apply(rule->right) });
|
||||
void visit(const rules::Seq *rule) {
|
||||
value = rules::Seq::Build({ apply(rule->left), apply(rule->right) });
|
||||
}
|
||||
|
||||
void visit(const Repeat *rule) {
|
||||
value = make_shared<Repeat>(apply(rule->content));
|
||||
void visit(const rules::Repeat *rule) {
|
||||
value = make_shared<rules::Repeat>(apply(rule->content));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#include "compiler/prepared_grammar.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef COMPILER_PREPARED_GRAMMAR_H_
|
||||
#define COMPILER_PREPARED_GRAMMAR_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/blank.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_BLANK_H_
|
||||
#define COMPILER_RULES_BLANK_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/character_range.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#include "compiler/rules/character_set.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
using std::string;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <initializer_list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rules/character_range.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/choice.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_CHOICE_H_
|
||||
#define COMPILER_RULES_CHOICE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/rules/pattern.h"
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include "compiler/rules/choice.h"
|
||||
#include "compiler/rules/seq.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_PATTERN_H_
|
||||
#define COMPILER_RULES_PATTERN_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/repeat.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_REPEAT_H_
|
||||
#define COMPILER_RULES_REPEAT_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/seq.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_SEQ_H_
|
||||
#define COMPILER_RULES_SEQ_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/rules/string.h"
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_STRING_H_
|
||||
#define COMPILER_RULES_STRING_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/rules/symbol.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COMPILER_RULES_SYMBOL_H_
|
||||
#define COMPILER_RULES_SYMBOL_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue