indentation
This commit is contained in:
parent
4cbc4b8bcf
commit
7633cbb836
5 changed files with 50 additions and 50 deletions
|
|
@ -36,8 +36,8 @@ typedef struct {
|
|||
} TSInputEdit;
|
||||
|
||||
typedef struct {
|
||||
size_t row;
|
||||
size_t column;
|
||||
size_t row;
|
||||
size_t column;
|
||||
} TSPoint;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -27,27 +27,27 @@ static inline TSLength ts_length_sub(TSLength len1, TSLength len2) {
|
|||
}
|
||||
|
||||
static inline TSPoint ts_point_add(TSPoint point1, TSPoint point2) {
|
||||
size_t row = point1.row + point2.row;
|
||||
size_t row = point1.row + point2.row;
|
||||
|
||||
size_t column;
|
||||
if (point2.row == 0) {
|
||||
column = point1.column + point2.column;
|
||||
} else {
|
||||
column = point2.column;
|
||||
}
|
||||
size_t column;
|
||||
if (point2.row == 0) {
|
||||
column = point1.column + point2.column;
|
||||
} else {
|
||||
column = point2.column;
|
||||
}
|
||||
|
||||
return (TSPoint){ .row = row, .column = column };
|
||||
}
|
||||
|
||||
static inline TSPoint ts_point_sub(TSPoint point1, TSPoint point2) {
|
||||
size_t row, column;
|
||||
if (point1.row == point2.row) {
|
||||
row = 0;
|
||||
column = point1.column - point2.column;
|
||||
} else {
|
||||
row = point1.row - point2.row;
|
||||
column = point1.column;
|
||||
}
|
||||
size_t row, column;
|
||||
if (point1.row == point2.row) {
|
||||
row = 0;
|
||||
column = point1.column - point2.column;
|
||||
} else {
|
||||
row = point1.row - point2.row;
|
||||
column = point1.column;
|
||||
}
|
||||
|
||||
return (TSPoint){ .row = row, .column = column };
|
||||
}
|
||||
|
|
@ -63,11 +63,11 @@ static inline bool ts_length_eq(TSLength len1, TSLength len2) {
|
|||
}
|
||||
|
||||
static inline TSPoint ts_point_zero() {
|
||||
return (TSPoint){ .row = 0, .column = 0 };
|
||||
return (TSPoint){ .row = 1, .column = 1 };
|
||||
}
|
||||
|
||||
static inline TSPoint ts_point_make(size_t row, size_t column) {
|
||||
return (TSPoint){ .row = row, .column = column };
|
||||
return (TSPoint){ .row = row, .column = column };
|
||||
}
|
||||
|
||||
static inline TSLength ts_length_make(size_t bytes, size_t chars) {
|
||||
|
|
|
|||
|
|
@ -69,12 +69,12 @@ static bool ts_lexer__advance(TSLexer *self, TSStateId state) {
|
|||
self->current_position.bytes += self->lookahead_size;
|
||||
self->current_position.chars += 1;
|
||||
|
||||
if (self->lookahead == '\n') {
|
||||
self->current_point.row += 1;
|
||||
self->current_point.column = 0;
|
||||
} else {
|
||||
self->current_point.column += 1;
|
||||
}
|
||||
if (self->lookahead == '\n') {
|
||||
self->current_point.row += 1;
|
||||
self->current_point.column = 1;
|
||||
} else {
|
||||
self->current_point.column += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (self->current_position.bytes >= self->chunk_start + self->chunk_size)
|
||||
|
|
@ -94,17 +94,17 @@ static TSTree *ts_lexer__accept(TSLexer *self, TSSymbol symbol,
|
|||
|
||||
TSPoint size_point = ts_point_sub(self->current_point, self ->token_start_point);
|
||||
TSPoint padding_point = ts_point_sub(self->token_start_point, self->token_end_point);
|
||||
self->token_end_point = self->current_point;
|
||||
self->token_end_point = self->current_point;
|
||||
|
||||
if (symbol == ts_builtin_sym_error) {
|
||||
DEBUG("error_char");
|
||||
return ts_tree_make_error(size, padding, size_point,
|
||||
padding_point, self->lookahead);
|
||||
padding_point, self->lookahead);
|
||||
} else {
|
||||
DEBUG("accept_token sym:%s", symbol_name);
|
||||
return ts_tree_make_leaf(symbol, padding, size,
|
||||
padding_point,
|
||||
size_point, node_type);
|
||||
padding_point,
|
||||
size_point, node_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#include "runtime/length.h"
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
||||
TSPoint padding_point,
|
||||
TSPoint size_point,
|
||||
TSPoint padding_point,
|
||||
TSPoint size_point,
|
||||
TSNodeType node_type) {
|
||||
TSTree *result = malloc(sizeof(TSTree));
|
||||
*result = (TSTree){
|
||||
|
|
@ -20,8 +20,8 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
|||
.named_child_count = 0,
|
||||
.children = NULL,
|
||||
.padding = padding,
|
||||
.padding_point = padding_point,
|
||||
.size_point = size_point,
|
||||
.padding_point = padding_point,
|
||||
.size_point = size_point,
|
||||
.options = {.type = node_type },
|
||||
};
|
||||
|
||||
|
|
@ -34,12 +34,12 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
|||
}
|
||||
|
||||
TSTree *ts_tree_make_error(TSLength size, TSLength padding,
|
||||
TSPoint size_point,
|
||||
TSPoint padding_point,
|
||||
char lookahead_char) {
|
||||
TSPoint size_point,
|
||||
TSPoint padding_point,
|
||||
char lookahead_char) {
|
||||
TSTree *result =
|
||||
ts_tree_make_leaf(ts_builtin_sym_error, padding, size, padding_point,
|
||||
size_point, TSNodeTypeNamed);
|
||||
size_point, TSNodeTypeNamed);
|
||||
result->lookahead_char = lookahead_char;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ static void ts_tree__set_children(TSTree *self, TSTree **children,
|
|||
child->context.parent = self;
|
||||
child->context.index = i;
|
||||
child->context.offset = ts_tree_total_size(self);
|
||||
child->context.offset_point = ts_tree_offset_point(self);
|
||||
child->context.offset_point = ts_tree_offset_point(self);
|
||||
|
||||
if (i == 0) {
|
||||
self->padding = child->padding;
|
||||
|
|
@ -117,21 +117,21 @@ void ts_tree_release(TSTree *self) {
|
|||
}
|
||||
|
||||
size_t ts_tree_offset_column(const TSTree *self) {
|
||||
const TSTree *parent = self;
|
||||
size_t column = self->padding_point.column;
|
||||
const TSTree *parent = self;
|
||||
size_t column = self->padding_point.column;
|
||||
|
||||
if (self->padding_point.row > 0) {
|
||||
return column;
|
||||
}
|
||||
|
||||
do {
|
||||
parent = parent->context.parent;
|
||||
do {
|
||||
parent = parent->context.parent;
|
||||
if (!parent) break;
|
||||
|
||||
column += parent->context.offset_point.column;
|
||||
} while (parent->context.offset_point.row == 0);
|
||||
column += parent->context.offset_point.column;
|
||||
} while (parent->context.offset_point.row == 0);
|
||||
|
||||
return column;
|
||||
return column;
|
||||
}
|
||||
|
||||
TSLength ts_tree_total_size(const TSTree *self) {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ struct TSTree {
|
|||
TSLength padding;
|
||||
TSLength size;
|
||||
|
||||
TSPoint padding_point;
|
||||
TSPoint size_point;
|
||||
TSPoint padding_point;
|
||||
TSPoint size_point;
|
||||
|
||||
TSSymbol symbol;
|
||||
|
||||
|
|
@ -41,11 +41,11 @@ struct TSTree {
|
|||
};
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, TSPoint,
|
||||
TSPoint, TSNodeType);
|
||||
TSPoint, TSNodeType);
|
||||
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, TSNodeType);
|
||||
TSTree *ts_tree_make_error(TSLength size, TSLength padding,
|
||||
TSPoint padding_point,
|
||||
TSPoint size_point, char lookahead_char);
|
||||
TSPoint padding_point,
|
||||
TSPoint size_point, char lookahead_char);
|
||||
void ts_tree_retain(TSTree *tree);
|
||||
void ts_tree_release(TSTree *tree);
|
||||
bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue