Skip to content

Commit

Permalink
Remove more textbuffer things
Browse files Browse the repository at this point in the history
  • Loading branch information
verhovsky committed Jun 14, 2023
1 parent d29c35c commit fe176b3
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 65 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,6 @@ function getTextFromFunction ({startIndex, endIndex}) {
return result.substr(0, goalLength);
}

function getTextFromTextBuffer ({startPosition, endPosition}) {
return this.input.getTextInRange({start: startPosition, end: endPosition});
}

const {pointTransferArray} = binding;

const NODE_FIELD_COUNT = 6;
Expand Down
57 changes: 0 additions & 57 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,63 +103,6 @@ class CallbackInput {
size_t partial_string_offset;
};

class TextBufferInput {
public:
TextBufferInput(const vector<pair<const char16_t *, uint32_t>> *slices)
: slices_(slices),
byte_offset(0),
slice_index_(0),
slice_offset_(0) {}

TSInput input() {
return TSInput{this, Read, TSInputEncodingUTF16};
}

private:
void seek(uint32_t byte_offset) {
this->byte_offset = byte_offset;

uint32_t total_length = 0;
uint32_t goal_index = byte_offset / 2;
for (unsigned i = 0, n = this->slices_->size(); i < n; i++) {
uint32_t next_total_length = total_length + this->slices_->at(i).second;
if (next_total_length > goal_index) {
this->slice_index_ = i;
this->slice_offset_ = goal_index - total_length;
return;
}
total_length = next_total_length;
}

this->slice_index_ = this->slices_->size();
this->slice_offset_ = 0;
}

static const char *Read(void *payload, uint32_t byte, TSPoint position, uint32_t *length) {
auto self = static_cast<TextBufferInput *>(payload);

if (byte != self->byte_offset) self->seek(byte);

if (self->slice_index_ == self->slices_->size()) {
*length = 0;
return "";
}

auto &slice = self->slices_->at(self->slice_index_);
const char16_t *result = slice.first + self->slice_offset_;
*length = 2 * (slice.second - self->slice_offset_);
self->byte_offset += *length;
self->slice_index_++;
self->slice_offset_ = 0;
return reinterpret_cast<const char *>(result);
}

const vector<pair<const char16_t *, uint32_t>> *slices_;
uint32_t byte_offset;
uint32_t slice_index_;
uint32_t slice_offset_;
};

void Parser::Init(Local<Object> exports) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Expand Down
2 changes: 0 additions & 2 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Parser : public Nan::ObjectWrap {
static void GetLogger(const Nan::FunctionCallbackInfo<v8::Value> &);
static void SetLogger(const Nan::FunctionCallbackInfo<v8::Value> &);
static void Parse(const Nan::FunctionCallbackInfo<v8::Value> &);
static void ParseTextBuffer(const Nan::FunctionCallbackInfo<v8::Value> &);
static void ParseTextBufferSync(const Nan::FunctionCallbackInfo<v8::Value> &);
static void PrintDotGraphs(const Nan::FunctionCallbackInfo<v8::Value> &);

static Nan::Persistent<v8::Function> constructor;
Expand Down
2 changes: 0 additions & 2 deletions tree-sitter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ declare module "tree-sitter" {
type: "parse" | "lex"
) => void;

export type TextBuffer = Buffer;

export interface InputReader {
(index: any, position: Point): string;
}
Expand Down

0 comments on commit fe176b3

Please sign in to comment.