Add ability to edit multiple times between parses
This commit is contained in:
parent
6254f45c1b
commit
f37f73f92f
13 changed files with 135 additions and 119 deletions
|
|
@ -33,12 +33,12 @@ static int spy_seek(void *data, TSLength byte_offset) {
|
|||
}
|
||||
|
||||
SpyInput::SpyInput(string content, size_t chars_per_chunk) :
|
||||
content(content),
|
||||
chars_per_chunk(chars_per_chunk),
|
||||
buffer_size(4 * chars_per_chunk),
|
||||
buffer(new char[buffer_size]),
|
||||
byte_offset(0),
|
||||
strings_read({ "" }) {}
|
||||
content(content),
|
||||
strings_read({""}) {}
|
||||
|
||||
SpyInput::~SpyInput() {
|
||||
delete buffer;
|
||||
|
|
@ -73,7 +73,8 @@ const char * SpyInput::read(size_t *bytes_read) {
|
|||
}
|
||||
|
||||
int SpyInput::seek(size_t pos) {
|
||||
strings_read.push_back("");
|
||||
if (strings_read.size() == 0 || strings_read.back().size() > 0)
|
||||
strings_read.push_back("");
|
||||
byte_offset = pos;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@
|
|||
#include "tree_sitter/runtime.h"
|
||||
|
||||
class SpyInput {
|
||||
size_t chars_per_chunk;
|
||||
size_t buffer_size;
|
||||
char *buffer;
|
||||
size_t byte_offset;
|
||||
|
||||
public:
|
||||
SpyInput(std::string content, size_t chars_per_chunk);
|
||||
~SpyInput();
|
||||
|
|
@ -18,10 +23,6 @@ class SpyInput {
|
|||
int seek(size_t position);
|
||||
|
||||
std::string content;
|
||||
size_t chars_per_chunk;
|
||||
size_t buffer_size;
|
||||
char *buffer;
|
||||
size_t byte_offset;
|
||||
std::vector<std::string> strings_read;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "runtime/helpers/tree_helpers.h"
|
||||
|
||||
const char *symbol_names[24] = {
|
||||
static const char *symbol_names[24] = {
|
||||
"ERROR", "END", "two", "three", "four", "five", "six", "seven", "eight",
|
||||
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
|
||||
"sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty-one",
|
||||
|
|
@ -14,18 +14,6 @@ TSTree ** tree_array(std::vector<TSTree *> trees) {
|
|||
return result;
|
||||
}
|
||||
|
||||
EqualsTree::EqualsTree(const TSTree *expected, const char **symbol_names)
|
||||
: expected(expected), symbol_names(symbol_names) {}
|
||||
|
||||
bool EqualsTree::Matches(const TSTree *actual) const {
|
||||
return ts_tree_eq(actual, expected);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const EqualsTree &matcher) {
|
||||
stream << std::string("equals tree: ") << std::string(ts_tree_string(matcher.expected, matcher.symbol_names));
|
||||
return stream;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSTree *tree) {
|
||||
return stream << std::string(ts_tree_string(tree, symbol_names));;
|
||||
}
|
||||
|
|
@ -34,3 +22,7 @@ std::ostream &operator<<(std::ostream &stream, const TSNode node) {
|
|||
return stream << std::string("{") << (const TSTree *)node.data <<
|
||||
std::string(", ") << std::to_string(ts_node_pos(node).chars) << std::string("}");
|
||||
}
|
||||
|
||||
bool operator==(const TSNode &left, const TSNode &right) {
|
||||
return ts_node_eq(left, right);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,19 +5,10 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
extern const char *symbol_names[24];
|
||||
|
||||
TSTree ** tree_array(std::vector<TSTree *> trees);
|
||||
|
||||
struct EqualsTree {
|
||||
EqualsTree(const TSTree *expected, const char **symbol_names);
|
||||
bool Matches(const TSTree *actual) const;
|
||||
const TSTree *expected;
|
||||
const char **symbol_names;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const EqualsTree &matcher);
|
||||
std::ostream &operator<<(std::ostream &stream, const TSTree *tree);
|
||||
std::ostream &operator<<(std::ostream &stream, const TSNode ref);
|
||||
std::ostream &operator<<(std::ostream &stream, const TSNode node);
|
||||
bool operator==(const TSNode &left, const TSNode &right);
|
||||
|
||||
#endif // HELPERS_TREE_HELPERS_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue