Don't use std::set in public compiler header
Just use vectors
This commit is contained in:
parent
252fa7b631
commit
67241e3052
5 changed files with 15 additions and 19 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#define TREE_SITTER_COMPILER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
|
@ -32,16 +31,16 @@ rule_ptr token(const rule_ptr &rule);
|
|||
|
||||
class Grammar {
|
||||
const std::vector<std::pair<std::string, rule_ptr>> rules_;
|
||||
std::set<rule_ptr> ubiquitous_tokens_;
|
||||
std::set<std::set<std::string>> expected_conflicts_;
|
||||
std::vector<rule_ptr> ubiquitous_tokens_;
|
||||
std::vector<std::vector<std::string>> expected_conflicts_;
|
||||
|
||||
public:
|
||||
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>> &);
|
||||
Grammar &ubiquitous_tokens(const std::vector<rule_ptr> &);
|
||||
Grammar &expected_conflicts(const std::vector<std::vector<std::string>> &);
|
||||
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;
|
||||
const std::vector<rule_ptr> &ubiquitous_tokens() const;
|
||||
const std::vector<std::vector<std::string>> &expected_conflicts() const;
|
||||
};
|
||||
|
||||
enum GrammarErrorType {
|
||||
|
|
|
|||
|
|
@ -254,15 +254,15 @@ describe("extract_tokens", []() {
|
|||
RuleEntryTypeNamed,
|
||||
},
|
||||
}, {
|
||||
pattern("\\s+"),
|
||||
str("y"),
|
||||
pattern("\\s+"),
|
||||
}, {}});
|
||||
|
||||
AssertThat(get<2>(result), Equals<const GrammarError *>(nullptr));
|
||||
|
||||
AssertThat(get<1>(result).separators.size(), Equals<size_t>(2));
|
||||
AssertThat(get<1>(result).separators[0], EqualsPointer(pattern("\\s+")));
|
||||
AssertThat(get<1>(result).separators[1], EqualsPointer(str("y")));
|
||||
AssertThat(get<1>(result).separators[0], EqualsPointer(str("y")));
|
||||
AssertThat(get<1>(result).separators[1], EqualsPointer(pattern("\\s+")));
|
||||
|
||||
AssertThat(get<0>(result).ubiquitous_tokens, IsEmpty());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace tree_sitter {
|
|||
|
||||
using std::ostream;
|
||||
using std::pair;
|
||||
using std::set;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
|
@ -16,20 +15,20 @@ const vector<pair<string, rule_ptr>> &Grammar::rules() const {
|
|||
return rules_;
|
||||
}
|
||||
|
||||
const set<rule_ptr> &Grammar::ubiquitous_tokens() const {
|
||||
const vector<rule_ptr> &Grammar::ubiquitous_tokens() const {
|
||||
return ubiquitous_tokens_;
|
||||
}
|
||||
|
||||
const set<set<string>> &Grammar::expected_conflicts() const {
|
||||
const vector<vector<string>> &Grammar::expected_conflicts() const {
|
||||
return expected_conflicts_;
|
||||
}
|
||||
|
||||
Grammar &Grammar::ubiquitous_tokens(const set<rule_ptr> &ubiquitous_tokens) {
|
||||
Grammar &Grammar::ubiquitous_tokens(const vector<rule_ptr> &ubiquitous_tokens) {
|
||||
ubiquitous_tokens_ = ubiquitous_tokens;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Grammar &Grammar::expected_conflicts(const set<set<string>> &expected_conflicts) {
|
||||
Grammar &Grammar::expected_conflicts(const vector<vector<string>> &expected_conflicts) {
|
||||
expected_conflicts_ = expected_conflicts;
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pair<InternedGrammar, const GrammarError *> intern_symbols(const Grammar &gramma
|
|||
auto new_rule = interner.apply(rule);
|
||||
if (!interner.missing_rule_name.empty())
|
||||
return { result, missing_rule_error(interner.missing_rule_name) };
|
||||
result.ubiquitous_tokens.insert(new_rule);
|
||||
result.ubiquitous_tokens.push_back(new_rule);
|
||||
}
|
||||
|
||||
for (auto &names : grammar.expected_conflicts()) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
#ifndef COMPILER_PREPARE_GRAMMAR_INTERNED_GRAMMAR_H_
|
||||
#define COMPILER_PREPARE_GRAMMAR_INTERNED_GRAMMAR_H_
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
|
@ -14,7 +12,7 @@ namespace prepare_grammar {
|
|||
|
||||
struct InternedGrammar {
|
||||
std::vector<RuleEntry> rules;
|
||||
std::set<rule_ptr> ubiquitous_tokens;
|
||||
std::vector<rule_ptr> ubiquitous_tokens;
|
||||
std::set<std::set<rules::Symbol>> expected_conflicts;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue