tree-sitter/spec/helpers/spy_input.h

40 lines
867 B
C
Raw Normal View History

#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();
2014-08-06 13:00:35 -07:00
std::string content;
TSInputEncoding encoding;
2014-08-06 13:00:35 -07:00
std::vector<std::string> strings_read;
};
#endif // HELPERS_SPY_INPUT_H_