From 226ffd6b5b3a854f5e33cb57fb722c7feba17e46 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 27 Aug 2014 22:23:45 -0700 Subject: [PATCH] Fix initializer list deduction warnings in specs --- include/tree_sitter/parser.h | 10 ++-- .../build_tables/item_set_closure_spec.cc | 18 +++++-- .../build_tables/item_set_transitions_spec.cc | 51 ++++++++++++++----- src/runtime/tree.c | 1 + 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 79f658ff..105f3670 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -93,14 +93,14 @@ struct TSLanguage { #define LEX_FN() static TSTree *ts_lex(TSLexer *lexer, TSStateId lex_state) -#define DEBUG_LEX(...) \ - if (lexer->debug) { \ +#define DEBUG_LEX(...) \ + if (lexer->debug) { \ fprintf(stderr, "LEX " __VA_ARGS__); \ - fprintf(stderr, "\n"); \ + fprintf(stderr, "\n"); \ } #define START_LEXER() \ - DEBUG_LEX("START %d", lex_state); \ + DEBUG_LEX("START %d", lex_state); \ char lookahead; \ next_state: \ lookahead = ts_lexer_lookahead_char(lexer); \ @@ -112,7 +112,7 @@ struct TSLanguage { { \ DEBUG_LEX("ADVANCE %d", state_index); \ if (ts_lexer_is_done(lexer)) { \ - DEBUG_LEX("END"); \ + DEBUG_LEX("END"); \ return NULL; \ } \ ts_lexer_advance(lexer); \ diff --git a/spec/compiler/build_tables/item_set_closure_spec.cc b/spec/compiler/build_tables/item_set_closure_spec.cc index aa39936b..09d9259f 100644 --- a/spec/compiler/build_tables/item_set_closure_spec.cc +++ b/spec/compiler/build_tables/item_set_closure_spec.cc @@ -19,13 +19,21 @@ describe("computing closures of item sets", []() { }, {}); it("adds items at the beginnings of referenced rules", [&]() { - ParseItemSet item_set = item_set_closure(ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0), - { Symbol(10, SymbolOptionToken) }, - grammar); + ParseItemSet item_set = item_set_closure( + ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0), + set({ Symbol(10, SymbolOptionToken) }), + grammar + ); AssertThat(item_set, Equals(ParseItemSet({ - { ParseItem(Symbol(1), grammar.rule(Symbol(1)), 0), { Symbol(11, SymbolOptionToken) } }, - { ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0), { Symbol(10, SymbolOptionToken) } }, + { + ParseItem(Symbol(1), grammar.rule(Symbol(1)), 0), + set({ Symbol(11, SymbolOptionToken) }), + }, + { + ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0), + set({ Symbol(10, SymbolOptionToken) }), + }, }))); }); }); diff --git a/spec/compiler/build_tables/item_set_transitions_spec.cc b/spec/compiler/build_tables/item_set_transitions_spec.cc index 84f31570..42c9bf3a 100644 --- a/spec/compiler/build_tables/item_set_transitions_spec.cc +++ b/spec/compiler/build_tables/item_set_transitions_spec.cc @@ -13,16 +13,29 @@ describe("lexical item set transitions", []() { it("merges the transitions by computing the union of the two item sets", [&]() { LexItemSet set1({ LexItem(Symbol(1), CharacterSet().include('a', 'f').copy()), - LexItem(Symbol(2), CharacterSet().include('e', 'x').copy()) }); + LexItem(Symbol(2), CharacterSet().include('e', 'x').copy()) + }); AssertThat(char_transitions(set1), Equals(map({ - { CharacterSet().include('a', 'd'), LexItemSet({ - LexItem(Symbol(1), blank()) }) }, - { CharacterSet().include('e', 'f'), LexItemSet({ - LexItem(Symbol(1), blank()), - LexItem(Symbol(2), blank()) }) }, - { CharacterSet().include('g', 'x'), LexItemSet({ - LexItem(Symbol(2), blank()) }) }, + { + CharacterSet().include('a', 'd'), + LexItemSet({ + LexItem(Symbol(1), blank()), + }) + }, + { + CharacterSet().include('e', 'f'), + LexItemSet({ + LexItem(Symbol(1), blank()), + LexItem(Symbol(2), blank()), + }) + }, + { + CharacterSet().include('g', 'x'), + LexItemSet({ + LexItem(Symbol(2), blank()), + }) + }, }))); }); }); @@ -36,14 +49,26 @@ describe("syntactic item set transitions", [&]() { it("computes the closure of the new item sets", [&]() { ParseItemSet set1({ - { ParseItem(Symbol(0), seq({ i_token(22), i_sym(1) }), 3), { Symbol(23, SymbolOptionToken) } }, + { + ParseItem(Symbol(0), seq({ i_token(22), i_sym(1) }), 3), + set({ Symbol(23, SymbolOptionToken) }) + }, }); AssertThat(sym_transitions(set1, grammar), Equals(map({ - { Symbol(22, SymbolOptionToken), ParseItemSet({ - { ParseItem(Symbol(0), i_sym(1), 4), { Symbol(23, SymbolOptionToken) } }, - { ParseItem(Symbol(1), i_token(21), 0), { Symbol(23, SymbolOptionToken) } }, - }) }, + { + Symbol(22, SymbolOptionToken), + ParseItemSet({ + { + ParseItem(Symbol(0), i_sym(1), 4), + set({ Symbol(23, SymbolOptionToken) }), + }, + { + ParseItem(Symbol(1), i_token(21), 0), + set({ Symbol(23, SymbolOptionToken) }) + }, + }) + }, }))); }); }); diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 91253b7e..4b8e6576 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -55,6 +55,7 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count, .size = size, .offset = offset, .options = options }; + result->children = children; result->child_count = child_count; result->visible_child_count = visible_child_count;