Move public rule functions out of rule namespace
This way, there's only one public namespace: tree_sitter
This commit is contained in:
parent
e386c634aa
commit
bd77ab1ac9
66 changed files with 127 additions and 167 deletions
|
|
@ -9,13 +9,11 @@
|
|||
|
||||
namespace tree_sitter {
|
||||
|
||||
namespace rules {
|
||||
|
||||
class Rule;
|
||||
typedef std::shared_ptr<Rule> rule_ptr;
|
||||
|
||||
enum Associativity {
|
||||
AssociativityNone = 0,
|
||||
AssociativityNone,
|
||||
AssociativityLeft,
|
||||
AssociativityRight,
|
||||
};
|
||||
|
|
@ -32,21 +30,17 @@ rule_ptr prec(int precedence, const rule_ptr &);
|
|||
rule_ptr prec(int precedence, const rule_ptr &, Associativity);
|
||||
rule_ptr token(const rule_ptr &rule);
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const rules::rule_ptr &rule);
|
||||
|
||||
} // namespace rules
|
||||
|
||||
class Grammar {
|
||||
const std::vector<std::pair<std::string, rules::rule_ptr>> rules_;
|
||||
std::set<rules::rule_ptr> ubiquitous_tokens_;
|
||||
const std::vector<std::pair<std::string, rule_ptr>> rules_;
|
||||
std::set<rule_ptr> ubiquitous_tokens_;
|
||||
std::set<std::set<std::string>> expected_conflicts_;
|
||||
|
||||
public:
|
||||
explicit Grammar(const std::vector<std::pair<std::string, rules::rule_ptr>> &);
|
||||
Grammar &ubiquitous_tokens(const std::set<rules::rule_ptr> &);
|
||||
explicit Grammar(const std::vector<std::pair<std::string, rule_ptr>> &);
|
||||
Grammar &ubiquitous_tokens(const std::set<rule_ptr> &);
|
||||
Grammar &expected_conflicts(const std::set<std::set<std::string>> &);
|
||||
const std::vector<std::pair<std::string, rules::rule_ptr>> &rules() const;
|
||||
const std::set<rules::rule_ptr> &ubiquitous_tokens() const;
|
||||
const std::vector<std::pair<std::string, rule_ptr>> &rules() const;
|
||||
const std::set<rule_ptr> &ubiquitous_tokens() const;
|
||||
const std::set<std::set<std::string>> &expected_conflicts() const;
|
||||
};
|
||||
|
||||
|
|
@ -71,6 +65,7 @@ std::pair<std::string, const GrammarError *> compile(const Grammar &,
|
|||
|
||||
std::ostream &operator<<(std::ostream &stream, const Grammar &grammar);
|
||||
std::ostream &operator<<(std::ostream &stream, const GrammarError *error);
|
||||
std::ostream &operator<<(std::ostream &stream, const rule_ptr &rule);
|
||||
|
||||
} // namespace tree_sitter
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
'src/compiler/prepare_grammar/prepare_grammar.cc',
|
||||
'src/compiler/prepare_grammar/token_description.cc',
|
||||
'src/compiler/syntax_grammar.cc',
|
||||
'src/compiler/rule.cc',
|
||||
'src/compiler/rules/blank.cc',
|
||||
'src/compiler/rules/built_in_symbols.cc',
|
||||
'src/compiler/rules/character_range.cc',
|
||||
|
|
@ -49,7 +50,6 @@
|
|||
'src/compiler/rules/named_symbol.cc',
|
||||
'src/compiler/rules/pattern.cc',
|
||||
'src/compiler/rules/repeat.cc',
|
||||
'src/compiler/rules/rule.cc',
|
||||
'src/compiler/rules/rules.cc',
|
||||
'src/compiler/rules/seq.cc',
|
||||
'src/compiler/rules/string.cc',
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ describe("ParseConflictManager", []() {
|
|||
describe("when the precedences are equal and the reduce's rule has no associativity", [&]() {
|
||||
it("reports an unresolved conflict", [&]() {
|
||||
ParseAction shift = ParseAction::Shift(2, { 0 });
|
||||
ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityUnspecified, 0);
|
||||
ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityNone, 0);
|
||||
|
||||
result = conflict_manager->resolve(reduce, shift, lookahead_sym);
|
||||
AssertThat(result.first, IsFalse());
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
#include <string>
|
||||
#include <initializer_list>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::initializer_list;
|
||||
using std::pair;
|
||||
using tree_sitter::rules::rule_ptr;
|
||||
using tree_sitter::rule_ptr;
|
||||
|
||||
template<typename K>
|
||||
class rule_map : public map<K, rule_ptr> {
|
||||
|
|
|
|||
3
spec/fixtures/grammars/arithmetic.cc
vendored
3
spec/fixtures/grammars/arithmetic.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
extern const Grammar arithmetic = Grammar({
|
||||
{ "program", sym("_expression") },
|
||||
{ "_expression", choice({
|
||||
|
|
|
|||
3
spec/fixtures/grammars/c.cc
vendored
3
spec/fixtures/grammars/c.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
// http://slps.github.io/zoo/c/iso-9899-tc3.html
|
||||
|
||||
extern const Grammar c = Grammar({
|
||||
|
|
|
|||
3
spec/fixtures/grammars/cpp.cc
vendored
3
spec/fixtures/grammars/cpp.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
// http://slps.github.io/zoo/cpp/iso-n2723.html
|
||||
|
||||
extern const Grammar cpp =
|
||||
|
|
|
|||
3
spec/fixtures/grammars/golang.cc
vendored
3
spec/fixtures/grammars/golang.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
static rule_ptr terminated(rule_ptr rule) {
|
||||
return seq({ rule, choice({
|
||||
sym("_line_break"),
|
||||
|
|
|
|||
2
spec/fixtures/grammars/helpers.cc
vendored
2
spec/fixtures/grammars/helpers.cc
vendored
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using namespace tree_sitter::rules;
|
||||
using namespace tree_sitter;
|
||||
|
||||
rule_ptr repeat1(rule_ptr element) {
|
||||
return seq({ element, repeat(element) });
|
||||
|
|
|
|||
2
spec/fixtures/grammars/helpers.h
vendored
2
spec/fixtures/grammars/helpers.h
vendored
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using namespace tree_sitter::rules;
|
||||
using namespace tree_sitter;
|
||||
|
||||
rule_ptr repeat1(rule_ptr element);
|
||||
rule_ptr comma_sep1(rule_ptr element);
|
||||
|
|
|
|||
3
spec/fixtures/grammars/javascript.cc
vendored
3
spec/fixtures/grammars/javascript.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
static rule_ptr terminated(rule_ptr rule) {
|
||||
return seq({ rule, choice({
|
||||
sym("_line_break"),
|
||||
|
|
|
|||
3
spec/fixtures/grammars/json.cc
vendored
3
spec/fixtures/grammars/json.cc
vendored
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace tree_sitter_examples {
|
||||
|
||||
using tree_sitter::Grammar;
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
extern const Grammar json = Grammar({
|
||||
{ "_value", choice({
|
||||
sym("object"),
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class LexTableBuilder {
|
|||
lex_table.state(state_id).is_token_start = true;
|
||||
}
|
||||
|
||||
rules::rule_ptr after_separators(rules::rule_ptr rule) {
|
||||
rule_ptr after_separators(rule_ptr rule) {
|
||||
return rules::Seq::build({
|
||||
make_shared<rules::Metadata>(
|
||||
separator_rule(), map<rules::MetadataKey, int>({
|
||||
|
|
@ -136,11 +136,11 @@ class LexTableBuilder {
|
|||
});
|
||||
}
|
||||
|
||||
rules::rule_ptr separator_rule() const {
|
||||
vector<rules::rule_ptr> separators;
|
||||
rule_ptr separator_rule() const {
|
||||
vector<rule_ptr> separators;
|
||||
for (const auto &rule : lex_grammar.separators)
|
||||
separators.push_back(rules::repeat(rule));
|
||||
return rules::choice(separators);
|
||||
separators.push_back(rules::Repeat::build(rule));
|
||||
return rules::Choice::build(separators);
|
||||
}
|
||||
|
||||
set<int> precedence_values_for_item_set(const LexItemSet &item_set) const {
|
||||
|
|
|
|||
|
|
@ -59,8 +59,7 @@ class FirstSymbols : public rules::RuleFn<set<Symbol>> {
|
|||
}
|
||||
};
|
||||
|
||||
set<Symbol> first_symbols(const rules::rule_ptr &rule,
|
||||
const SyntaxGrammar &grammar) {
|
||||
set<Symbol> first_symbols(const rule_ptr &rule, const SyntaxGrammar &grammar) {
|
||||
return FirstSymbols(&grammar).apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace build_tables {
|
|||
* Returns the set of symbols that can appear at the beginning of a sentential
|
||||
* form derivable from a given rule in a given grammar.
|
||||
*/
|
||||
std::set<rules::Symbol> first_symbols(const rules::rule_ptr &rule,
|
||||
std::set<rules::Symbol> first_symbols(const rule_ptr &rule,
|
||||
const SyntaxGrammar &grammar);
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class GetCompletionStatus : public rules::RuleFn<CompletionStatus> {
|
|||
if (status.is_done)
|
||||
return status;
|
||||
}
|
||||
return { false, 0, rules::AssociativityNone };
|
||||
return { false, 0, AssociativityNone };
|
||||
}
|
||||
|
||||
CompletionStatus apply_to(const rules::Metadata *rule) {
|
||||
|
|
@ -23,17 +23,17 @@ class GetCompletionStatus : public rules::RuleFn<CompletionStatus> {
|
|||
if (result.is_done && !result.associativity) {
|
||||
result.precedence = rule->value_for(rules::PRECEDENCE);
|
||||
result.associativity =
|
||||
(rules::Associativity)(rule->value_for(rules::ASSOCIATIVITY));
|
||||
(Associativity)(rule->value_for(rules::ASSOCIATIVITY));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CompletionStatus apply_to(const rules::Repeat *rule) {
|
||||
return { true, 0, rules::AssociativityNone };
|
||||
return { true, 0, AssociativityNone };
|
||||
}
|
||||
|
||||
CompletionStatus apply_to(const rules::Blank *rule) {
|
||||
return { true, 0, rules::AssociativityNone };
|
||||
return { true, 0, AssociativityNone };
|
||||
}
|
||||
|
||||
CompletionStatus apply_to(const rules::Seq *rule) {
|
||||
|
|
@ -41,11 +41,11 @@ class GetCompletionStatus : public rules::RuleFn<CompletionStatus> {
|
|||
if (left_status.is_done)
|
||||
return apply(rule->right);
|
||||
else
|
||||
return { false, 0, rules::AssociativityNone };
|
||||
return { false, 0, AssociativityNone };
|
||||
}
|
||||
};
|
||||
|
||||
CompletionStatus get_completion_status(const rules::rule_ptr &rule) {
|
||||
CompletionStatus get_completion_status(const rule_ptr &rule) {
|
||||
return GetCompletionStatus().apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ namespace build_tables {
|
|||
struct CompletionStatus {
|
||||
bool is_done;
|
||||
int precedence;
|
||||
rules::Associativity associativity;
|
||||
Associativity associativity;
|
||||
};
|
||||
|
||||
CompletionStatus get_completion_status(const rules::rule_ptr &);
|
||||
CompletionStatus get_completion_status(const rule_ptr &);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ std::ostream &operator<<(std::ostream &stream, const MetadataRange &range) {
|
|||
<< to_string(range.max) << string("}");
|
||||
}
|
||||
|
||||
MetadataRange get_metadata(const rules::rule_ptr &rule, rules::MetadataKey key) {
|
||||
MetadataRange get_metadata(const rule_ptr &rule, rules::MetadataKey key) {
|
||||
class GetMetadata : public rules::RuleFn<pair<MetadataRange, bool>> {
|
||||
rules::MetadataKey metadata_key;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct MetadataRange {
|
|||
|
||||
std::ostream &operator<<(std::ostream &stream, const MetadataRange &range);
|
||||
|
||||
MetadataRange get_metadata(const rules::rule_ptr &, rules::MetadataKey);
|
||||
MetadataRange get_metadata(const rule_ptr &, rules::MetadataKey);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
namespace tree_sitter {
|
||||
namespace build_tables {
|
||||
|
||||
Item::Item(const rules::Symbol &lhs, const rules::rule_ptr rule)
|
||||
Item::Item(const rules::Symbol &lhs, const rule_ptr rule)
|
||||
: lhs(lhs), rule(rule) {}
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ namespace build_tables {
|
|||
|
||||
class Item {
|
||||
public:
|
||||
Item(const rules::Symbol &lhs, rules::rule_ptr rule);
|
||||
Item(const rules::Symbol &lhs, rule_ptr rule);
|
||||
|
||||
rules::Symbol lhs;
|
||||
rules::rule_ptr rule;
|
||||
rule_ptr rule;
|
||||
};
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ using std::set;
|
|||
using std::vector;
|
||||
using std::pair;
|
||||
using rules::Symbol;
|
||||
using rules::rule_ptr;
|
||||
|
||||
const ParseItemSet item_set_closure(const ParseItem &starting_item,
|
||||
const set<Symbol> &starting_lookahead_symbols,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace build_tables {
|
|||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
LexItem::LexItem(const rules::Symbol &lhs, const rules::rule_ptr rule)
|
||||
LexItem::LexItem(const rules::Symbol &lhs, const rule_ptr rule)
|
||||
: Item(lhs, rule) {}
|
||||
|
||||
bool LexItem::operator==(const LexItem &other) const {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace build_tables {
|
|||
|
||||
class LexItem : public Item {
|
||||
public:
|
||||
LexItem(const rules::Symbol &lhs, rules::rule_ptr rule);
|
||||
LexItem(const rules::Symbol &lhs, rule_ptr rule);
|
||||
bool operator==(const LexItem &other) const;
|
||||
bool is_token_start() const;
|
||||
};
|
||||
|
|
@ -28,7 +28,7 @@ template <>
|
|||
struct hash<tree_sitter::build_tables::LexItem> {
|
||||
size_t operator()(const tree_sitter::build_tables::Item &item) const {
|
||||
return hash<tree_sitter::rules::Symbol>()(item.lhs) ^
|
||||
hash<tree_sitter::rules::rule_ptr>()(item.rule);
|
||||
hash<tree_sitter::rule_ptr>()(item.rule);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ pair<bool, ConflictType> ParseConflictManager::resolve(
|
|||
return { true, ConflictTypeResolved };
|
||||
else if (min_precedence == max_precedence) {
|
||||
switch (new_action.associativity) {
|
||||
case rules::AssociativityLeft:
|
||||
case AssociativityLeft:
|
||||
return { true, ConflictTypeResolved };
|
||||
case rules::AssociativityRight:
|
||||
case AssociativityRight:
|
||||
return { false, ConflictTypeResolved };
|
||||
default:
|
||||
return { false, ConflictTypeUnresolved };
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::ostream;
|
||||
|
||||
ParseItem::ParseItem(const rules::Symbol &lhs, const rules::rule_ptr rule,
|
||||
ParseItem::ParseItem(const rules::Symbol &lhs, const rule_ptr rule,
|
||||
const vector<rules::Symbol> &consumed_symbols)
|
||||
: Item(lhs, rule), consumed_symbols(consumed_symbols) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace build_tables {
|
|||
|
||||
class ParseItem : public Item {
|
||||
public:
|
||||
ParseItem(const rules::Symbol &lhs, rules::rule_ptr rule,
|
||||
ParseItem(const rules::Symbol &lhs, rule_ptr rule,
|
||||
const std::vector<rules::Symbol> &consumed_symbols);
|
||||
bool operator==(const ParseItem &other) const;
|
||||
bool operator<(const ParseItem &other) const;
|
||||
|
|
@ -32,7 +32,7 @@ template <>
|
|||
struct hash<tree_sitter::build_tables::ParseItem> {
|
||||
size_t operator()(const tree_sitter::build_tables::ParseItem &item) const {
|
||||
return hash<tree_sitter::rules::Symbol>()(item.lhs) ^
|
||||
hash<tree_sitter::rules::rule_ptr>()(item.rule) ^
|
||||
hash<tree_sitter::rule_ptr>()(item.rule) ^
|
||||
hash<size_t>()(item.consumed_symbols.size());
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,12 +62,11 @@ class CanBeBlankRecursive : public CanBeBlank {
|
|||
}
|
||||
};
|
||||
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule) {
|
||||
bool rule_can_be_blank(const rule_ptr &rule) {
|
||||
return CanBeBlank().apply(rule);
|
||||
}
|
||||
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule,
|
||||
const SyntaxGrammar &grammar) {
|
||||
bool rule_can_be_blank(const rule_ptr &rule, const SyntaxGrammar &grammar) {
|
||||
return CanBeBlankRecursive(&grammar).apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,8 @@ class SyntaxGrammar;
|
|||
|
||||
namespace build_tables {
|
||||
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule);
|
||||
bool rule_can_be_blank(const rules::rule_ptr &rule,
|
||||
const SyntaxGrammar &grammar);
|
||||
bool rule_can_be_blank(const rule_ptr &rule);
|
||||
bool rule_can_be_blank(const rule_ptr &rule, const SyntaxGrammar &grammar);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ using std::make_shared;
|
|||
using rules::CharacterSet;
|
||||
using rules::Choice;
|
||||
using rules::Symbol;
|
||||
using rules::rule_ptr;
|
||||
|
||||
template <typename T>
|
||||
void merge_transitions(map<T, rule_ptr> *, const map<T, rule_ptr> &);
|
||||
|
|
@ -46,7 +45,7 @@ void merge_transitions(map<Symbol, rule_ptr> *left,
|
|||
template <typename T>
|
||||
class RuleTransitions : public rules::RuleFn<map<T, rule_ptr>> {
|
||||
private:
|
||||
map<T, rule_ptr> apply_to_primitive(const rules::Rule *rule) {
|
||||
map<T, rule_ptr> apply_to_primitive(const Rule *rule) {
|
||||
auto primitive = dynamic_cast<const T *>(rule);
|
||||
if (primitive)
|
||||
return map<T, rule_ptr>({ { *primitive, make_shared<rules::Blank>() } });
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@
|
|||
namespace tree_sitter {
|
||||
namespace build_tables {
|
||||
|
||||
std::map<rules::CharacterSet, rules::rule_ptr> char_transitions(
|
||||
const rules::rule_ptr &rule);
|
||||
std::map<rules::CharacterSet, rule_ptr> char_transitions(const rule_ptr &rule);
|
||||
|
||||
std::map<rules::Symbol, rules::rule_ptr> sym_transitions(
|
||||
const rules::rule_ptr &rule);
|
||||
std::map<rules::Symbol, rule_ptr> sym_transitions(const rule_ptr &rule);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
||||
|
|
@ -8,9 +8,8 @@ using std::pair;
|
|||
using std::set;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using rules::rule_ptr;
|
||||
|
||||
Grammar::Grammar(const vector<pair<string, rules::rule_ptr>> &rules)
|
||||
Grammar::Grammar(const vector<pair<string, rule_ptr>> &rules)
|
||||
: rules_(rules), ubiquitous_tokens_({}) {}
|
||||
|
||||
const vector<pair<string, rule_ptr>> &Grammar::rules() const {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using std::pair;
|
|||
using std::vector;
|
||||
using std::set;
|
||||
|
||||
const rules::rule_ptr &LexicalGrammar::rule(const rules::Symbol &symbol) const {
|
||||
const rule_ptr &LexicalGrammar::rule(const rules::Symbol &symbol) const {
|
||||
return symbol.is_auxiliary() ? aux_rules[symbol.index].second
|
||||
: rules[symbol.index].second;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ namespace tree_sitter {
|
|||
class LexicalGrammar {
|
||||
public:
|
||||
const std::string &rule_name(const rules::Symbol &symbol) const;
|
||||
const rules::rule_ptr &rule(const rules::Symbol &symbol) const;
|
||||
const rule_ptr &rule(const rules::Symbol &symbol) const;
|
||||
|
||||
std::vector<std::pair<std::string, rules::rule_ptr>> rules;
|
||||
std::vector<std::pair<std::string, rules::rule_ptr>> aux_rules;
|
||||
std::vector<rules::rule_ptr> separators;
|
||||
std::vector<std::pair<std::string, rule_ptr>> rules;
|
||||
std::vector<std::pair<std::string, rule_ptr>> aux_rules;
|
||||
std::vector<rule_ptr> separators;
|
||||
};
|
||||
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using rules::Symbol;
|
|||
ParseAction::ParseAction(ParseActionType type, ParseStateId state_index,
|
||||
Symbol symbol, size_t consumed_symbol_count,
|
||||
set<int> precedence_values,
|
||||
rules::Associativity associativity, int production_id)
|
||||
Associativity associativity, int production_id)
|
||||
: type(type),
|
||||
symbol(symbol),
|
||||
state_index(state_index),
|
||||
|
|
@ -27,7 +27,7 @@ ParseAction::ParseAction()
|
|||
symbol(Symbol(-1)),
|
||||
state_index(-1),
|
||||
consumed_symbol_count(0),
|
||||
associativity(rules::AssociativityUnspecified) {}
|
||||
associativity(AssociativityNone) {}
|
||||
|
||||
ParseAction ParseAction::Error() {
|
||||
return ParseAction();
|
||||
|
|
@ -42,7 +42,7 @@ ParseAction ParseAction::Accept() {
|
|||
ParseAction ParseAction::Shift(ParseStateId state_index,
|
||||
set<int> precedence_values) {
|
||||
return ParseAction(ParseActionTypeShift, state_index, Symbol(-1), 0,
|
||||
precedence_values, rules::AssociativityUnspecified, -1);
|
||||
precedence_values, AssociativityNone, -1);
|
||||
}
|
||||
|
||||
ParseAction ParseAction::ShiftExtra() {
|
||||
|
|
@ -59,8 +59,7 @@ ParseAction ParseAction::ReduceExtra(Symbol symbol) {
|
|||
}
|
||||
|
||||
ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count,
|
||||
int precedence,
|
||||
rules::Associativity associativity,
|
||||
int precedence, Associativity associativity,
|
||||
int production_id) {
|
||||
return ParseAction(ParseActionTypeReduce, 0, symbol, consumed_symbol_count,
|
||||
{ precedence }, associativity, production_id);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ typedef enum {
|
|||
class ParseAction {
|
||||
ParseAction(ParseActionType type, ParseStateId state_index,
|
||||
rules::Symbol symbol, size_t consumed_symbol_count,
|
||||
std::set<int> precedence_values, rules::Associativity,
|
||||
int production_id);
|
||||
std::set<int> precedence_values, Associativity, int production_id);
|
||||
|
||||
public:
|
||||
ParseAction();
|
||||
|
|
@ -36,8 +35,7 @@ class ParseAction {
|
|||
static ParseAction Shift(ParseStateId state_index,
|
||||
std::set<int> precedence_values);
|
||||
static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count,
|
||||
int precedence, rules::Associativity,
|
||||
int production_id);
|
||||
int precedence, Associativity, int production_id);
|
||||
static ParseAction ShiftExtra();
|
||||
static ParseAction ReduceExtra(rules::Symbol symbol);
|
||||
bool operator==(const ParseAction &) const;
|
||||
|
|
@ -48,7 +46,7 @@ class ParseAction {
|
|||
ParseStateId state_index;
|
||||
size_t consumed_symbol_count;
|
||||
std::set<int> precedence_values;
|
||||
rules::Associativity associativity;
|
||||
Associativity associativity;
|
||||
int production_id;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ using std::vector;
|
|||
using std::pair;
|
||||
using std::to_string;
|
||||
using std::make_shared;
|
||||
using rules::rule_ptr;
|
||||
using rules::Blank;
|
||||
using rules::Choice;
|
||||
using rules::Repeat;
|
||||
using rules::Rule;
|
||||
using rules::Seq;
|
||||
using rules::Symbol;
|
||||
|
||||
|
|
@ -64,7 +62,7 @@ class ExpandRepeats : public rules::IdentityRuleFn {
|
|||
return apply(rule);
|
||||
}
|
||||
|
||||
vector<pair<string, rules::rule_ptr>> aux_rules;
|
||||
vector<pair<string, rule_ptr>> aux_rules;
|
||||
};
|
||||
|
||||
SyntaxGrammar expand_repeats(const SyntaxGrammar &grammar) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::pair;
|
||||
using std::make_shared;
|
||||
using rules::rule_ptr;
|
||||
using rules::String;
|
||||
using rules::Pattern;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ using std::set;
|
|||
using std::string;
|
||||
using std::tuple;
|
||||
using std::vector;
|
||||
using rules::rule_ptr;
|
||||
using rules::Symbol;
|
||||
using rules::SymbolOptionToken;
|
||||
using rules::SymbolOptionAuxToken;
|
||||
|
|
@ -62,7 +61,7 @@ class SymbolReplacer : public rules::IdentityRuleFn {
|
|||
};
|
||||
|
||||
class TokenExtractor : public rules::IdentityRuleFn {
|
||||
rule_ptr apply_to_token(const rules::Rule *input) {
|
||||
rule_ptr apply_to_token(const Rule *input) {
|
||||
auto rule = input->copy();
|
||||
for (size_t i = 0; i < tokens.size(); i++)
|
||||
if (tokens[i].second->operator==(*rule)) {
|
||||
|
|
@ -75,7 +74,7 @@ class TokenExtractor : public rules::IdentityRuleFn {
|
|||
return make_shared<Symbol>(index, SymbolOptionAuxToken);
|
||||
}
|
||||
|
||||
rule_ptr default_apply(const rules::Rule *rule) {
|
||||
rule_ptr default_apply(const Rule *rule) {
|
||||
auto result = rule->copy();
|
||||
if (is_token(result))
|
||||
return apply_to_token(rule);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <set>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/visitor.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
#include "compiler/rules/named_symbol.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
||||
|
|
@ -11,7 +12,6 @@ namespace tree_sitter {
|
|||
namespace prepare_grammar {
|
||||
|
||||
using std::string;
|
||||
using rules::rule_ptr;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using std::pair;
|
||||
|
|
@ -24,7 +24,7 @@ class InternSymbols : public rules::IdentityRuleFn {
|
|||
auto result = symbol_for_rule_name(rule->name);
|
||||
if (!result.get()) {
|
||||
missing_rule_name = rule->name;
|
||||
return rules::blank();
|
||||
return rules::Blank::build();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ namespace tree_sitter {
|
|||
namespace prepare_grammar {
|
||||
|
||||
struct InternedGrammar {
|
||||
std::vector<std::pair<std::string, rules::rule_ptr>> rules;
|
||||
std::set<rules::rule_ptr> ubiquitous_tokens;
|
||||
std::vector<std::pair<std::string, rule_ptr>> rules;
|
||||
std::set<rule_ptr> ubiquitous_tokens;
|
||||
std::set<std::set<rules::Symbol>> expected_conflicts;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class IsToken : public rules::RuleFn<bool> {
|
|||
}
|
||||
};
|
||||
|
||||
bool is_token(const rules::rule_ptr &rule) {
|
||||
bool is_token(const rule_ptr &rule) {
|
||||
return IsToken().apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
namespace tree_sitter {
|
||||
namespace prepare_grammar {
|
||||
|
||||
bool is_token(const rules::rule_ptr &);
|
||||
bool is_token(const rule_ptr &);
|
||||
|
||||
} // namespace prepare_grammar
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -17,13 +17,11 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::pair;
|
||||
using std::make_shared;
|
||||
using rules::rule_ptr;
|
||||
using rules::CharacterSet;
|
||||
using rules::Seq;
|
||||
using rules::Blank;
|
||||
using rules::Choice;
|
||||
using rules::Repeat;
|
||||
using rules::blank;
|
||||
|
||||
class PatternParser {
|
||||
public:
|
||||
|
|
@ -45,7 +43,7 @@ class PatternParser {
|
|||
}
|
||||
auto pair = term(nested);
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
choices.push_back(pair.first);
|
||||
} while (has_more_input());
|
||||
auto rule =
|
||||
|
|
@ -55,7 +53,7 @@ class PatternParser {
|
|||
|
||||
private:
|
||||
pair<rule_ptr, const GrammarError *> term(bool nested) {
|
||||
rule_ptr result = blank();
|
||||
rule_ptr result = Blank::build();
|
||||
do {
|
||||
if (peek() == '|')
|
||||
break;
|
||||
|
|
@ -63,7 +61,7 @@ class PatternParser {
|
|||
break;
|
||||
auto pair = factor();
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
result = Seq::build({ result, pair.first });
|
||||
} while (has_more_input());
|
||||
return { result, nullptr };
|
||||
|
|
@ -72,7 +70,7 @@ class PatternParser {
|
|||
pair<rule_ptr, const GrammarError *> factor() {
|
||||
auto pair = atom();
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
rule_ptr result = pair.first;
|
||||
if (has_more_input()) {
|
||||
switch (peek()) {
|
||||
|
|
@ -99,7 +97,7 @@ class PatternParser {
|
|||
next();
|
||||
auto pair = rule(true);
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
if (peek() != ')')
|
||||
return error("unmatched open paren");
|
||||
next();
|
||||
|
|
@ -109,7 +107,7 @@ class PatternParser {
|
|||
next();
|
||||
auto pair = char_set();
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
if (peek() != ']')
|
||||
return error("unmatched open square bracket");
|
||||
next();
|
||||
|
|
@ -128,7 +126,7 @@ class PatternParser {
|
|||
default: {
|
||||
auto pair = single_char();
|
||||
if (pair.second)
|
||||
return { blank(), pair.second };
|
||||
return { Blank::build(), pair.second };
|
||||
return { pair.first.copy(), nullptr };
|
||||
}
|
||||
}
|
||||
|
|
@ -220,7 +218,7 @@ class PatternParser {
|
|||
}
|
||||
|
||||
pair<rule_ptr, const GrammarError *> error(string msg) {
|
||||
return { blank(), new GrammarError(GrammarErrorTypeRegex, msg) };
|
||||
return { Blank::build(), new GrammarError(GrammarErrorTypeRegex, msg) };
|
||||
}
|
||||
|
||||
string input;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
namespace tree_sitter {
|
||||
namespace prepare_grammar {
|
||||
|
||||
std::pair<rules::rule_ptr, const GrammarError *> parse_regex(const std::string &);
|
||||
std::pair<rule_ptr, const GrammarError *> parse_regex(const std::string &);
|
||||
|
||||
} // namespace prepare_grammar
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TokenDescription : public rules::RuleFn<string> {
|
|||
}
|
||||
};
|
||||
|
||||
std::string token_description(const rules::rule_ptr &rule) {
|
||||
std::string token_description(const rule_ptr &rule) {
|
||||
return TokenDescription().apply(rule);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace tree_sitter {
|
||||
namespace prepare_grammar {
|
||||
|
||||
std::string token_description(const rules::rule_ptr &);
|
||||
std::string token_description(const rule_ptr &);
|
||||
|
||||
} // namespace prepare_grammar
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
#include <set>
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
|
|
@ -25,5 +24,4 @@ ostream &operator<<(ostream &stream, const rule_ptr &rule) {
|
|||
|
||||
Rule::~Rule() {}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
@ -5,11 +5,12 @@
|
|||
#include <memory>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
||||
namespace rules {
|
||||
|
||||
class Visitor;
|
||||
class Rule;
|
||||
} // namespace rules
|
||||
|
||||
class Rule;
|
||||
typedef std::shared_ptr<Rule> rule_ptr;
|
||||
|
||||
class Rule {
|
||||
|
|
@ -19,21 +20,20 @@ class Rule {
|
|||
virtual size_t hash_code() const = 0;
|
||||
virtual rule_ptr copy() const = 0;
|
||||
virtual std::string to_string() const = 0;
|
||||
virtual void accept(Visitor *visitor) const = 0;
|
||||
virtual void accept(rules::Visitor *visitor) const = 0;
|
||||
virtual ~Rule();
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const Rule &rule);
|
||||
std::ostream &operator<<(std::ostream &stream, const rule_ptr &rule);
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<tree_sitter::rules::rule_ptr> {
|
||||
size_t operator()(const tree_sitter::rules::rule_ptr &rule) const {
|
||||
struct hash<tree_sitter::rule_ptr> {
|
||||
size_t operator()(const tree_sitter::rule_ptr &rule) const {
|
||||
return typeid(*rule).hash_code() ^ rule->hash_code();
|
||||
}
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/rules/blank.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "compiler/rules/visitor.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
@ -7,6 +8,10 @@ namespace rules {
|
|||
|
||||
Blank::Blank() {}
|
||||
|
||||
rule_ptr Blank::build() {
|
||||
return std::make_shared<Blank>();
|
||||
}
|
||||
|
||||
bool Blank::operator==(const Rule &rule) const {
|
||||
return dynamic_cast<const Blank *>(&rule) != nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_BLANK_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
@ -10,6 +10,7 @@ namespace rules {
|
|||
class Blank : public Rule {
|
||||
public:
|
||||
Blank();
|
||||
static rule_ptr build();
|
||||
|
||||
bool operator==(const Rule &other) const;
|
||||
size_t hash_code() const;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
#include "compiler/rules/character_range.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
@ -16,8 +16,6 @@ enum MetadataKey {
|
|||
ASSOCIATIVITY,
|
||||
};
|
||||
|
||||
const Associativity AssociativityUnspecified = (Associativity)0;
|
||||
|
||||
class Metadata : public Rule {
|
||||
public:
|
||||
Metadata(rule_ptr rule, std::map<MetadataKey, int> value);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_NAMED_SYMBOL_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using std::hash;
|
|||
|
||||
Pattern::Pattern(const string &string) : value(string) {}
|
||||
|
||||
bool Pattern::operator==(tree_sitter::rules::Rule const &other) const {
|
||||
bool Pattern::operator==(tree_sitter::Rule const &other) const {
|
||||
auto pattern = dynamic_cast<const Pattern *>(&other);
|
||||
return pattern && (pattern->value == value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_PATTERN_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_REPEAT_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
#include "compiler/rules/named_symbol.h"
|
||||
#include "compiler/rules/choice.h"
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
#include "compiler/rules/built_in_symbols.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
||||
using std::make_shared;
|
||||
using std::string;
|
||||
|
|
@ -24,45 +23,45 @@ using std::set;
|
|||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
static rule_ptr metadata(rule_ptr rule, map<MetadataKey, int> values) {
|
||||
return std::make_shared<Metadata>(rule, values);
|
||||
static rule_ptr metadata(rule_ptr rule, map<rules::MetadataKey, int> values) {
|
||||
return std::make_shared<rules::Metadata>(rule, values);
|
||||
}
|
||||
|
||||
rule_ptr blank() {
|
||||
return make_shared<Blank>();
|
||||
return rules::Blank::build();
|
||||
}
|
||||
|
||||
rule_ptr choice(const vector<rule_ptr> &rules) {
|
||||
return Choice::build(rules);
|
||||
return rules::Choice::build(rules);
|
||||
}
|
||||
|
||||
rule_ptr repeat(const rule_ptr &content) {
|
||||
return Repeat::build(content);
|
||||
return rules::Repeat::build(content);
|
||||
}
|
||||
|
||||
rule_ptr seq(const vector<rule_ptr> &rules) {
|
||||
return Seq::build(rules);
|
||||
return rules::Seq::build(rules);
|
||||
}
|
||||
|
||||
rule_ptr sym(const string &name) {
|
||||
return make_shared<NamedSymbol>(name);
|
||||
return make_shared<rules::NamedSymbol>(name);
|
||||
}
|
||||
|
||||
rule_ptr pattern(const string &value) {
|
||||
return make_shared<Pattern>(value);
|
||||
return make_shared<rules::Pattern>(value);
|
||||
}
|
||||
|
||||
rule_ptr str(const string &value) {
|
||||
return token(prec(1, make_shared<String>(value)));
|
||||
return token(prec(1, make_shared<rules::String>(value)));
|
||||
}
|
||||
|
||||
rule_ptr err(const rule_ptr &rule) {
|
||||
return choice({ rule, ERROR().copy() });
|
||||
return choice({ rule, rules::ERROR().copy() });
|
||||
}
|
||||
|
||||
rule_ptr prec(int precedence, const rule_ptr &rule, Associativity associativity) {
|
||||
return metadata(
|
||||
rule, { { PRECEDENCE, precedence }, { ASSOCIATIVITY, associativity } });
|
||||
return metadata(rule, { { rules::PRECEDENCE, precedence },
|
||||
{ rules::ASSOCIATIVITY, associativity } });
|
||||
}
|
||||
|
||||
rule_ptr prec(int precedence, const rule_ptr &rule) {
|
||||
|
|
@ -70,8 +69,7 @@ rule_ptr prec(int precedence, const rule_ptr &rule) {
|
|||
}
|
||||
|
||||
rule_ptr token(const rule_ptr &rule) {
|
||||
return metadata(rule, { { IS_TOKEN, 1 } });
|
||||
return metadata(rule, { { rules::IS_TOKEN, 1 } });
|
||||
}
|
||||
|
||||
} // namespace rules
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_STRING_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_RULES_SYMBOL_H_
|
||||
|
||||
#include <string>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "compiler/rules/visitor.h"
|
||||
#include <vector>
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
#include "compiler/rules/blank.h"
|
||||
#include "compiler/rules/character_set.h"
|
||||
#include "compiler/rules/choice.h"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COMPILER_RULES_VISITOR_H_
|
||||
#define COMPILER_RULES_VISITOR_H_
|
||||
|
||||
#include "compiler/rules/rule.h"
|
||||
#include "compiler/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace tree_sitter {
|
|||
|
||||
using std::string;
|
||||
|
||||
const rules::rule_ptr &SyntaxGrammar::rule(const rules::Symbol &symbol) const {
|
||||
const rule_ptr &SyntaxGrammar::rule(const rules::Symbol &symbol) const {
|
||||
return symbol.is_auxiliary() ? aux_rules[symbol.index].second
|
||||
: rules[symbol.index].second;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ namespace tree_sitter {
|
|||
class SyntaxGrammar {
|
||||
public:
|
||||
const std::string &rule_name(const rules::Symbol &symbol) const;
|
||||
const rules::rule_ptr &rule(const rules::Symbol &symbol) const;
|
||||
const rule_ptr &rule(const rules::Symbol &symbol) const;
|
||||
|
||||
std::vector<std::pair<std::string, rules::rule_ptr>> rules;
|
||||
std::vector<std::pair<std::string, rules::rule_ptr>> aux_rules;
|
||||
std::vector<std::pair<std::string, rule_ptr>> rules;
|
||||
std::vector<std::pair<std::string, rule_ptr>> aux_rules;
|
||||
std::set<rules::Symbol> ubiquitous_tokens;
|
||||
std::set<std::set<rules::Symbol>> expected_conflicts;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue