From 78c5fe8e02b9c37e214f17dd73155e44b27b898e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 3 Oct 2014 15:44:21 -0700 Subject: [PATCH] clang-format --- include/tree_sitter/parser.h | 37 ++++++++++----------- src/compiler/prepare_grammar/parse_regex.cc | 13 +++----- src/runtime/lexer.c | 17 +++++----- src/runtime/parser.c | 8 ++--- src/runtime/stack.h | 3 +- src/runtime/tree.c | 3 +- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index cd305079..350fe03c 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -80,30 +80,29 @@ struct TSLanguage { TSTree *(*lex_fn)(TSLexer *, TSStateId); }; -#define DEBUG_LEX(...) \ - if (lexer->debug) { \ - fprintf(stderr, "LEX "); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ +#define DEBUG_LEX(...) \ + if (lexer->debug) { \ + fprintf(stderr, "LEX "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ } -#define START_LEXER() \ - DEBUG_LEX("START %d", lex_state); \ - int32_t lookahead; \ - next_state: \ - lookahead = ts_lexer_lookahead_char(lexer); \ - DEBUG_LEX( \ - (0 < lookahead && lookahead <= 255 ? "CHAR '%c'" : "CHAR %d"), \ - lookahead); +#define START_LEXER() \ + DEBUG_LEX("START %d", lex_state); \ + int32_t lookahead; \ + next_state: \ + lookahead = ts_lexer_lookahead_char(lexer); \ + DEBUG_LEX((0 < lookahead &&lookahead <= 255 ? "CHAR '%c'" : "CHAR %d"), \ + lookahead); #define START_TOKEN() ts_lexer_start_token(lexer); -#define ADVANCE(state_index) \ - { \ - DEBUG_LEX("ADVANCE %d", state_index); \ - ts_lexer_advance(lexer); \ - lex_state = state_index; \ - goto next_state; \ +#define ADVANCE(state_index) \ + { \ + DEBUG_LEX("ADVANCE %d", state_index); \ + ts_lexer_advance(lexer); \ + lex_state = state_index; \ + goto next_state; \ } #define ACCEPT_TOKEN(symbol) \ diff --git a/src/compiler/prepare_grammar/parse_regex.cc b/src/compiler/prepare_grammar/parse_regex.cc index a13aee95..2d3e2414 100644 --- a/src/compiler/prepare_grammar/parse_regex.cc +++ b/src/compiler/prepare_grammar/parse_regex.cc @@ -30,8 +30,9 @@ class PatternParser { explicit PatternParser(const string &input) : input(input), iter((const uint8_t *)input.data()), - end(iter + input.size()) - { next(); } + end(iter + input.size()) { + next(); + } pair rule(bool nested) { vector choices = {}; @@ -206,13 +207,9 @@ class PatternParser { iter += lookahead_size; } - uint32_t peek() { - return lookahead; - } + uint32_t peek() { return lookahead; } - bool has_more_input() { - return lookahead && iter <= end; - } + bool has_more_input() { return lookahead && iter <= end; } pair error(string msg) { return { blank(), new GrammarError(GrammarErrorTypeRegex, msg) }; diff --git a/src/runtime/lexer.c b/src/runtime/lexer.c index db6469f6..9a63e11e 100644 --- a/src/runtime/lexer.c +++ b/src/runtime/lexer.c @@ -43,8 +43,10 @@ static int advance(TSLexer *lexer) { } static TSTree *accept(TSLexer *lexer, TSSymbol symbol, int is_hidden) { - TSLength size = ts_length_sub(lexer->current_position, lexer->token_start_position); - TSLength padding = ts_length_sub(lexer->token_start_position, lexer->token_end_position); + TSLength size = + ts_length_sub(lexer->current_position, lexer->token_start_position); + TSLength padding = + ts_length_sub(lexer->token_start_position, lexer->token_end_position); lexer->token_end_position = lexer->current_position; return (symbol == ts_builtin_sym_error) ? ts_tree_make_error(size, padding, ts_lexer_lookahead_char(lexer)) @@ -57,9 +59,8 @@ static TSTree *accept(TSLexer *lexer, TSSymbol symbol, int is_hidden) { * this library. */ TSLexer ts_lexer_make() { - TSLexer result = (TSLexer) { .debug = 0, - .advance_fn = advance, - .accept_fn = accept, }; + TSLexer result = + (TSLexer) { .debug = 0, .advance_fn = advance, .accept_fn = accept, }; ts_lexer_reset(&result); return result; } @@ -68,9 +69,9 @@ void ts_lexer_reset(TSLexer *lexer) { lexer->chunk = NULL; lexer->chunk_start = 0; lexer->chunk_size = 0; - lexer->current_position = ts_length_zero(), - lexer->token_start_position = ts_length_zero(), - lexer->token_end_position = ts_length_zero(), + lexer->current_position = ts_length_zero(); + lexer->token_start_position = ts_length_zero(); + lexer->token_end_position = ts_length_zero(); lexer->lookahead = 0; lexer->lookahead_size = 0; } diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 8134b70a..68af9901 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -153,9 +153,8 @@ static int handle_error(TSParser *parser) { ts_stack_shrink(&parser->stack, entry - parser->stack.entries + 1); parser->lookahead->padding = ts_length_zero(); error->size = ts_length_sub( - ts_length_sub( - parser->lexer.token_start_position, - ts_stack_right_position(&parser->stack)), + ts_length_sub(parser->lexer.token_start_position, + ts_stack_right_position(&parser->stack)), error->padding); ts_stack_push(&parser->stack, state_after_error, error); ts_tree_release(error); @@ -189,7 +188,8 @@ static int handle_error(TSParser *parser) { static TSTree *get_root(TSParser *parser) { if (parser->stack.size == 0) - ts_stack_push(&parser->stack, 0, ts_tree_make_error(ts_length_zero(), ts_length_zero(), 0)); + ts_stack_push(&parser->stack, 0, + ts_tree_make_error(ts_length_zero(), ts_length_zero(), 0)); reduce(parser, ts_builtin_sym_document, parser->stack.size); parser->lookahead->options = 0; diff --git a/src/runtime/stack.h b/src/runtime/stack.h index e9c7d397..a4941ec8 100644 --- a/src/runtime/stack.h +++ b/src/runtime/stack.h @@ -28,8 +28,7 @@ TSLength ts_stack_right_position(const TSStack *stack); #define TS_STACK_FROM_TOP(stack, entry) \ for (TSStackEntry *entry = stack.entries + stack.size - 1; \ - entry >= stack.entries; \ - entry--) + entry >= stack.entries; entry--) #ifdef __cplusplus } diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 50901cf8..cbb18ca8 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -97,7 +97,8 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count, TSTreeChild *grandchildren = ts_tree_visible_children(child, &n); for (size_t j = 0; j < n; j++) { visible_children[vis_i].tree = grandchildren[j].tree; - visible_children[vis_i].offset = ts_length_add(offset, grandchildren[j].offset); + visible_children[vis_i].offset = + ts_length_add(offset, grandchildren[j].offset); vis_i++; } }