tree-sitter/spec/runtime/helpers/spy_input.h

41 lines
889 B
C
Raw Normal View History

2015-07-16 17:32:19 -07:00
#ifndef HELPERS_spy_input_H_
#define HELPERS_spy_input_H_
#include <string>
#include <vector>
#include "tree_sitter/runtime.h"
2015-09-19 14:46:14 -07:00
struct SpyInputEdit {
size_t position;
size_t chars_removed;
std::string text_inserted;
};
2015-07-16 17:32:19 -07:00
class SpyInput {
size_t chars_per_chunk;
size_t buffer_size;
char *buffer;
size_t byte_offset;
2015-09-19 14:46:14 -07:00
std::vector<SpyInputEdit> undo_stack;
2015-09-19 13:29:30 -07:00
static const char * read(void *, size_t *);
static int seek(void *, size_t, size_t);
2015-09-19 14:46:14 -07:00
std::string swap_substr(size_t, size_t, std::string);
2015-09-19 13:29:30 -07:00
2014-08-06 13:00:35 -07:00
public:
2015-07-16 17:32:19 -07:00
SpyInput(std::string content, size_t chars_per_chunk);
~SpyInput();
TSInput input();
2015-09-19 13:29:30 -07:00
void clear();
2015-09-19 14:46:14 -07:00
TSInputEdit replace(size_t start_char, size_t chars_removed, std::string text);
TSInputEdit undo();
static size_t char_count(const std::string &);
2014-08-06 13:00:35 -07:00
std::string content;
std::vector<std::string> strings_read;
};
2015-07-16 17:32:19 -07:00
#endif // HELPERS_spy_input_H_