Clean up using statements
This commit is contained in:
parent
a8588cd4d3
commit
812f27f43a
11 changed files with 66 additions and 67 deletions
|
|
@ -48,7 +48,7 @@ namespace tree_sitter {
|
|||
}
|
||||
};
|
||||
|
||||
set<rules::Symbol> first_set(const rules::rule_ptr &rule, const Grammar &grammar) {
|
||||
set<Symbol> first_set(const rule_ptr &rule, const Grammar &grammar) {
|
||||
return FirstSetVisitor::apply(rule, grammar);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ namespace tree_sitter {
|
|||
using std::ostream;
|
||||
using std::vector;
|
||||
using rules::Symbol;
|
||||
using rules::rule_ptr;
|
||||
|
||||
namespace build_tables {
|
||||
Item::Item(const Symbol &lhs, const rules::rule_ptr rule) :
|
||||
Item::Item(const Symbol &lhs, const rule_ptr rule) :
|
||||
lhs(lhs),
|
||||
rule(rule) {};
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ namespace tree_sitter {
|
|||
return false;
|
||||
}
|
||||
|
||||
LexItem::LexItem(const Symbol &lhs, const rules::rule_ptr rule) : Item(lhs, rule) {}
|
||||
LexItem::LexItem(const Symbol &lhs, const rule_ptr rule) : Item(lhs, rule) {}
|
||||
|
||||
bool LexItem::operator==(const LexItem &other) const {
|
||||
bool lhs_eq = other.lhs == lhs;
|
||||
|
|
@ -66,7 +67,7 @@ namespace tree_sitter {
|
|||
return lhs_eq && rules_eq;
|
||||
}
|
||||
|
||||
ParseItem::ParseItem(const Symbol &lhs, const rules::rule_ptr rule, const vector<bool> &consumed_symbols, const rules::Symbol &lookahead_sym) :
|
||||
ParseItem::ParseItem(const Symbol &lhs, const rule_ptr rule, const vector<bool> &consumed_symbols, const Symbol &lookahead_sym) :
|
||||
Item(lhs, rule),
|
||||
consumed_symbols(consumed_symbols),
|
||||
lookahead_sym(lookahead_sym) {}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ namespace tree_sitter {
|
|||
using std::pair;
|
||||
using std::string;
|
||||
using std::map;
|
||||
using rules::Symbol;
|
||||
using rules::CharacterSet;
|
||||
|
||||
namespace build_tables {
|
||||
static int NOT_FOUND = -1;
|
||||
static rules::Symbol START("start", true);
|
||||
static rules::Symbol END_OF_INPUT("end", true);
|
||||
static Symbol START("start", true);
|
||||
static Symbol END_OF_INPUT("end", true);
|
||||
|
||||
class TableBuilder {
|
||||
const Grammar grammar;
|
||||
|
|
@ -35,7 +37,7 @@ namespace tree_sitter {
|
|||
|
||||
void add_shift_actions(const ParseItemSet &item_set, size_t state_index) {
|
||||
for (auto transition : sym_transitions(item_set, grammar)) {
|
||||
rules::Symbol symbol = transition.first;
|
||||
Symbol symbol = transition.first;
|
||||
ParseItemSet item_set = transition.second;
|
||||
size_t new_state_index = add_parse_state(item_set);
|
||||
parse_table.add_action(state_index, symbol, ParseAction::Shift(new_state_index));
|
||||
|
|
@ -44,7 +46,7 @@ namespace tree_sitter {
|
|||
|
||||
void add_advance_actions(const LexItemSet &item_set, size_t state_index) {
|
||||
for (auto transition : char_transitions(item_set, grammar)) {
|
||||
rules::CharacterSet rule = transition.first;
|
||||
CharacterSet rule = transition.first;
|
||||
LexItemSet item_set = transition.second;
|
||||
size_t new_state_index = add_lex_state(item_set);
|
||||
lex_table.add_action(state_index, rule, LexAction::Advance(new_state_index));
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using std::pair;
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using std::pair;
|
||||
|
||||
namespace generate_code {
|
||||
static void str_replace(string &input, const string &search, const string &replace) {
|
||||
size_t pos = 0;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#include "grammar.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
using std::initializer_list;
|
||||
using std::ostream;
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
using std::initializer_list;
|
||||
using std::ostream;
|
||||
|
||||
Grammar::Grammar(const initializer_list<pair<const string, const rules::rule_ptr>> &rules) :
|
||||
rules(rules),
|
||||
start_rule_name(rules.begin()->first) {}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
#include "lex_table.h"
|
||||
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using std::set;
|
||||
using tree_sitter::rules::Symbol;
|
||||
using tree_sitter::rules::CharacterSet;
|
||||
|
||||
namespace tree_sitter {
|
||||
// Action
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using std::set;
|
||||
using rules::Symbol;
|
||||
using rules::CharacterSet;
|
||||
|
||||
LexAction::LexAction(LexActionType type, size_t state_index, Symbol symbol) :
|
||||
type(type),
|
||||
state_index(state_index),
|
||||
|
|
@ -52,15 +51,13 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
// State
|
||||
set<CharacterSet> LexState::expected_inputs() const {
|
||||
set<CharacterSet> result;
|
||||
for (auto pair : actions)
|
||||
for (auto &pair : actions)
|
||||
result.insert(pair.first);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Table
|
||||
size_t LexTable::add_state() {
|
||||
states.push_back(LexState());
|
||||
return states.size() - 1;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
#include "parse_table.h"
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
using std::to_string;
|
||||
using std::set;
|
||||
using std::vector;
|
||||
using tree_sitter::rules::Symbol;
|
||||
|
||||
namespace tree_sitter {
|
||||
// Action
|
||||
ParseAction::ParseAction(ParseActionType type, size_t state_index, rules::Symbol symbol, const vector<bool> &child_flags) :
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
using std::to_string;
|
||||
using std::set;
|
||||
using std::vector;
|
||||
using rules::Symbol;
|
||||
|
||||
ParseAction::ParseAction(ParseActionType type, size_t state_index, Symbol symbol, const vector<bool> &child_flags) :
|
||||
type(type),
|
||||
state_index(state_index),
|
||||
symbol(symbol),
|
||||
|
|
@ -59,11 +58,10 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
// State
|
||||
ParseState::ParseState() : lex_state_index(-1) {}
|
||||
|
||||
set<rules::Symbol> ParseState::expected_inputs() const {
|
||||
set<rules::Symbol> result;
|
||||
set<Symbol> ParseState::expected_inputs() const {
|
||||
set<Symbol> result;
|
||||
for (auto pair : actions)
|
||||
result.insert(pair.first);
|
||||
return result;
|
||||
|
|
@ -88,13 +86,12 @@ namespace tree_sitter {
|
|||
return stream;
|
||||
}
|
||||
|
||||
// Table
|
||||
size_t ParseTable::add_state() {
|
||||
states.push_back(ParseState());
|
||||
return states.size() - 1;
|
||||
}
|
||||
|
||||
void ParseTable::add_action(size_t state_index, rules::Symbol symbol, ParseAction action) {
|
||||
void ParseTable::add_action(size_t state_index, Symbol symbol, ParseAction action) {
|
||||
symbols.insert(symbol);
|
||||
states[state_index].actions[symbol].insert(action);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#include "expand_repeats.h"
|
||||
#include <map>
|
||||
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using namespace rules;
|
||||
|
||||
namespace prepare_grammar {
|
||||
class RepeatExpander : rules::Visitor {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
#include "search_for_symbols.h"
|
||||
#include <map>
|
||||
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::map;
|
||||
using namespace rules;
|
||||
|
||||
namespace prepare_grammar {
|
||||
class TokenExtractor : Visitor {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#include "./extract_tokens.h"
|
||||
#include "./expand_repeats.h"
|
||||
|
||||
using std::pair;
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::pair;
|
||||
|
||||
namespace prepare_grammar {
|
||||
pair<Grammar, Grammar> perform(const Grammar &input_grammar) {
|
||||
auto grammars = prepare_grammar::extract_tokens(input_grammar);
|
||||
|
|
|
|||
|
|
@ -1,38 +1,40 @@
|
|||
#include "search_for_symbols.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using namespace rules;
|
||||
|
||||
namespace prepare_grammar {
|
||||
class SymbolSearcher : rules::Visitor {
|
||||
class SymbolSearcher : Visitor {
|
||||
public:
|
||||
bool value;
|
||||
|
||||
bool apply(const rules::rule_ptr rule) {
|
||||
bool apply(const rule_ptr rule) {
|
||||
rule->accept(*this);
|
||||
return value;
|
||||
}
|
||||
|
||||
void default_visit(const rules::Rule *rule) {
|
||||
void default_visit(const Rule *rule) {
|
||||
value = false;
|
||||
}
|
||||
|
||||
void visit(const rules::Symbol *symbol) {
|
||||
void visit(const Symbol *symbol) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
void visit(const rules::Choice *choice) {
|
||||
void visit(const Choice *choice) {
|
||||
value = apply(choice->left) || apply(choice->right);
|
||||
}
|
||||
|
||||
void visit(const rules::Seq *seq) {
|
||||
void visit(const Seq *seq) {
|
||||
value = apply(seq->left) || apply(seq->right);
|
||||
}
|
||||
|
||||
void visit(const rules::Repeat *rule) {
|
||||
void visit(const Repeat *rule) {
|
||||
value = apply(rule->content);
|
||||
}
|
||||
};
|
||||
|
||||
bool search_for_symbols(const rules::rule_ptr &rule) {
|
||||
bool search_for_symbols(const rule_ptr &rule) {
|
||||
return SymbolSearcher().apply(rule);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue