From 2e7ffb4d1448108df0d8c40c71c8211a107d1a37 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 9 Sep 2014 13:15:40 -0700 Subject: [PATCH] Tweak auto-format settings Prefer lines that exceed 80 characters by a small margin to line breaks in argument lists --- .clang-format | 2 +- include/tree_sitter/compiler.h | 13 ++++++------- include/tree_sitter/parser.h | 19 +++++++++---------- script/lint.sh | 4 ++-- src/compiler/build_tables/build_lex_table.cc | 3 +-- .../build_tables/build_parse_table.cc | 3 +-- src/compiler/build_tables/first_set.cc | 3 +-- src/compiler/build_tables/item_set_closure.cc | 7 +++---- src/compiler/generate_code/c_code.cc | 3 +-- src/compiler/grammar.cc | 3 +-- src/compiler/parse_table.cc | 6 ++---- .../prepare_grammar/expand_repeats.cc | 5 ++--- .../prepare_grammar/extract_tokens.cc | 4 ++-- .../prepare_grammar/intern_symbols.cc | 5 ++--- src/compiler/prepare_grammar/parse_regex.h | 3 +-- src/compiler/prepared_grammar.cc | 3 +-- src/compiler/rules/character_set.cc | 6 ++---- src/runtime/document.c | 3 +-- src/runtime/tree.c | 8 +++----- 19 files changed, 42 insertions(+), 61 deletions(-) diff --git a/.clang-format b/.clang-format index 453e987c..4e21182e 100644 --- a/.clang-format +++ b/.clang-format @@ -25,7 +25,7 @@ PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 60 PenaltyBreakString: 1000 PenaltyBreakFirstLessLess: 120 -PenaltyExcessCharacter: 1000000 +PenaltyExcessCharacter: 20 PenaltyReturnTypeOnItsOwnLine: 200 PointerBindsToType: true SpacesBeforeTrailingComments: 2 diff --git a/include/tree_sitter/compiler.h b/include/tree_sitter/compiler.h index 710a065f..94b3b54f 100644 --- a/include/tree_sitter/compiler.h +++ b/include/tree_sitter/compiler.h @@ -32,18 +32,17 @@ std::ostream &operator<<(std::ostream &stream, const rules::rule_ptr &rule); } // namespace rules class Grammar { - const std::vector > rules_; + const std::vector> rules_; std::set ubiquitous_tokens_; public: - Grammar(const std::vector > &rules); - bool operator==(const Grammar &other) const; + explicit Grammar(const std::vector> &); + bool operator==(const Grammar &) const; std::string start_rule_name() const; - const rules::rule_ptr rule(const std::string &name) const; - const std::vector > &rules() const; + const rules::rule_ptr rule(const std::string &) const; + const std::vector> &rules() const; const std::set &ubiquitous_tokens() const; - Grammar &ubiquitous_tokens( - const std::set &ubiquitous_tokens); + Grammar &ubiquitous_tokens(const std::set &); }; struct Conflict { diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 2a8d5ef9..3060df93 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -138,16 +138,15 @@ struct TSLanguage { #define ACCEPT_INPUT() \ { .type = TSParseActionTypeAccept } -#define EXPORT_LANGUAGE(language_name) \ - static TSLanguage language = { \ - .symbol_count = SYMBOL_COUNT, \ - .hidden_symbol_flags = ts_hidden_symbol_flags, \ - .parse_table = (const TSParseAction *)ts_parse_actions, \ - .lex_states = ts_lex_states, \ - .symbol_names = ts_symbol_names, \ - .lex_fn = ts_lex, \ - }; \ - \ +#define EXPORT_LANGUAGE(language_name) \ + static TSLanguage language = { .symbol_count = SYMBOL_COUNT, \ + .hidden_symbol_flags = ts_hidden_symbol_flags, \ + .parse_table = \ + (const TSParseAction *)ts_parse_actions, \ + .lex_states = ts_lex_states, \ + .symbol_names = ts_symbol_names, \ + .lex_fn = ts_lex, }; \ + \ const TSLanguage *language_name() { return &language; } #ifdef __cplusplus diff --git a/script/lint.sh b/script/lint.sh index f1e84dee..08d37634 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -10,5 +10,5 @@ fi FILTERS='--filter=-legal/copyright,-readability/todo' -$CPPLINT --root=include $FILTERS include/tree_sitter/compiler.h 2>&1 -$CPPLINT --root=src $FILTERS $(find src/compiler -type f) 2>&1 +$CPPLINT --linelength=90 --root=include $FILTERS include/tree_sitter/compiler.h 2>&1 +$CPPLINT --linelength=90 --root=src $FILTERS $(find src/compiler -type f) 2>&1 diff --git a/src/compiler/build_tables/build_lex_table.cc b/src/compiler/build_tables/build_lex_table.cc index 5f682d05..b1c86b5c 100644 --- a/src/compiler/build_tables/build_lex_table.cc +++ b/src/compiler/build_tables/build_lex_table.cc @@ -87,8 +87,7 @@ class LexTableBuilder { } } - void add_accept_token_actions(const LexItemSet &item_set, - LexStateId state_id) { + void add_accept_token_actions(const LexItemSet &item_set, LexStateId state_id) { for (const LexItem &item : item_set) { if (item.is_done()) { auto current_action = lex_table.state(state_id).default_action; diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index e9be8f95..b30a78a6 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -100,8 +100,7 @@ class ParseTableBuilder { size_t shift_state_id = pair_for_symbol->second.state_index; for (const auto &pair : actions) { const Symbol &lookahead_sym = pair.first; - ParseAction reduce_extra = - ParseAction::ReduceExtra(ubiquitous_symbol); + ParseAction reduce_extra = ParseAction::ReduceExtra(ubiquitous_symbol); if (should_add_action(shift_state_id, lookahead_sym, reduce_extra)) parse_table.add_action(shift_state_id, lookahead_sym, reduce_extra); } diff --git a/src/compiler/build_tables/first_set.cc b/src/compiler/build_tables/first_set.cc index b8b0d8ad..53b5e939 100644 --- a/src/compiler/build_tables/first_set.cc +++ b/src/compiler/build_tables/first_set.cc @@ -54,8 +54,7 @@ class FirstSet : public rules::RuleFn > { } }; -set first_set(const rules::rule_ptr &rule, - const SyntaxGrammar &grammar) { +set first_set(const rules::rule_ptr &rule, const SyntaxGrammar &grammar) { return FirstSet(&grammar).apply(rule); } diff --git a/src/compiler/build_tables/item_set_closure.cc b/src/compiler/build_tables/item_set_closure.cc index 08660b9c..9a707c90 100644 --- a/src/compiler/build_tables/item_set_closure.cc +++ b/src/compiler/build_tables/item_set_closure.cc @@ -18,10 +18,9 @@ using std::pair; using rules::Symbol; using rules::rule_ptr; -const ParseItemSet item_set_closure( - const ParseItem &starting_item, - const set &starting_lookahead_symbols, - const SyntaxGrammar &grammar) { +const ParseItemSet item_set_closure(const ParseItem &starting_item, + const set &starting_lookahead_symbols, + const SyntaxGrammar &grammar) { ParseItemSet result; vector>> items_to_process = { diff --git a/src/compiler/generate_code/c_code.cc b/src/compiler/generate_code/c_code.cc index abdcfa64..6d633eff 100644 --- a/src/compiler/generate_code/c_code.cc +++ b/src/compiler/generate_code/c_code.cc @@ -247,8 +247,7 @@ class CCodeGenerator { } } - void condition_for_character_ranges( - const vector &ranges) { + void condition_for_character_ranges(const vector &ranges) { if (ranges.size() == 1) { add(condition_for_character_range(*ranges.begin())); } else { diff --git a/src/compiler/grammar.cc b/src/compiler/grammar.cc index 783037cc..39d8adf8 100644 --- a/src/compiler/grammar.cc +++ b/src/compiler/grammar.cc @@ -10,8 +10,7 @@ using std::string; using std::vector; using rules::rule_ptr; -Grammar::Grammar( - const std::vector > &rules) +Grammar::Grammar(const std::vector > &rules) : rules_(rules), ubiquitous_tokens_({}) {} bool Grammar::operator==(const Grammar &other) const { diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index c3d2a122..3604b2fb 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -59,8 +59,7 @@ bool ParseAction::operator==(const ParseAction &other) const { bool state_indices_eq = state_index == other.state_index; bool consumed_symbol_counts_eq = consumed_symbol_count == other.consumed_symbol_count; - return types_eq && symbols_eq && state_indices_eq && - consumed_symbol_counts_eq; + return types_eq && symbols_eq && state_indices_eq && consumed_symbol_counts_eq; } ostream &operator<<(ostream &stream, const ParseAction &action) { @@ -112,8 +111,7 @@ ParseStateId ParseTable::add_state() { return states.size() - 1; } -void ParseTable::add_action(ParseStateId id, Symbol symbol, - ParseAction action) { +void ParseTable::add_action(ParseStateId id, Symbol symbol, ParseAction action) { symbols.insert(symbol); states[id].actions[symbol] = action; } diff --git a/src/compiler/prepare_grammar/expand_repeats.cc b/src/compiler/prepare_grammar/expand_repeats.cc index 2d21d4f2..df18a323 100644 --- a/src/compiler/prepare_grammar/expand_repeats.cc +++ b/src/compiler/prepare_grammar/expand_repeats.cc @@ -37,9 +37,8 @@ class ExpandRepeats : public rules::IdentityRuleFn { make_shared(offset + index, rules::SymbolOptionAuxiliary); aux_rules.push_back( { helper_rule_name, - Seq::Build( - { inner_rule, - Choice::Build({ repeat_symbol, make_shared() }) }) }); + Seq::Build({ inner_rule, Choice::Build({ repeat_symbol, + make_shared() }) }) }); return Choice::Build({ repeat_symbol, make_shared() }); } diff --git a/src/compiler/prepare_grammar/extract_tokens.cc b/src/compiler/prepare_grammar/extract_tokens.cc index ee4993b7..74780186 100644 --- a/src/compiler/prepare_grammar/extract_tokens.cc +++ b/src/compiler/prepare_grammar/extract_tokens.cc @@ -91,8 +91,8 @@ class TokenExtractor : public rules::IdentityRuleFn { vector> tokens; }; -static tuple -ubiq_token_err(const rule_ptr rule) { +static tuple ubiq_token_err( + const rule_ptr rule) { return make_tuple(SyntaxGrammar(), LexicalGrammar(), new GrammarError(GrammarErrorTypeInvalidUbiquitousToken, "Not a token: " + rule->to_string())); diff --git a/src/compiler/prepare_grammar/intern_symbols.cc b/src/compiler/prepare_grammar/intern_symbols.cc index 79b9a710..9b66c271 100644 --- a/src/compiler/prepare_grammar/intern_symbols.cc +++ b/src/compiler/prepare_grammar/intern_symbols.cc @@ -42,9 +42,8 @@ class InternSymbols : public rules::IdentityRuleFn { }; pair missing_rule_error(string rule_name) { - return { Grammar({}), - new GrammarError(GrammarErrorTypeUndefinedSymbol, - "Undefined rule '" + rule_name + "'") }; + return { Grammar({}), new GrammarError(GrammarErrorTypeUndefinedSymbol, + "Undefined rule '" + rule_name + "'") }; } pair intern_symbols(const Grammar &grammar) { diff --git a/src/compiler/prepare_grammar/parse_regex.h b/src/compiler/prepare_grammar/parse_regex.h index 2255bea1..f1c12970 100644 --- a/src/compiler/prepare_grammar/parse_regex.h +++ b/src/compiler/prepare_grammar/parse_regex.h @@ -8,8 +8,7 @@ namespace tree_sitter { namespace prepare_grammar { -std::pair parse_regex( - const std::string &); +std::pair parse_regex(const std::string &); } // namespace prepare_grammar } // namespace tree_sitter diff --git a/src/compiler/prepared_grammar.cc b/src/compiler/prepared_grammar.cc index 7d0d80e9..13290b90 100644 --- a/src/compiler/prepared_grammar.cc +++ b/src/compiler/prepared_grammar.cc @@ -11,8 +11,7 @@ using std::pair; using std::vector; using std::set; -const rules::rule_ptr &PreparedGrammar::rule(const rules::Symbol &symbol) - const { +const rules::rule_ptr &PreparedGrammar::rule(const rules::Symbol &symbol) const { return symbol.is_auxiliary() ? aux_rules[symbol.index].second : rules[symbol.index].second; } diff --git a/src/compiler/rules/character_set.cc b/src/compiler/rules/character_set.cc index 175ca4fc..bbf6cbc4 100644 --- a/src/compiler/rules/character_set.cc +++ b/src/compiler/rules/character_set.cc @@ -17,8 +17,7 @@ static void add_range(set *characters, uint32_t min, uint32_t max) { characters->insert(c); } -static void remove_range(set *characters, uint32_t min, - uint32_t max) { +static void remove_range(set *characters, uint32_t min, uint32_t max) { for (uint32_t c = min; c <= max; c++) characters->erase(c); } @@ -33,8 +32,7 @@ static set remove_chars(set *left, return result; } -static set add_chars(set *left, - const set &right) { +static set add_chars(set *left, const set &right) { set result; for (uint32_t c : right) if (left->insert(c).second) diff --git a/src/runtime/document.c b/src/runtime/document.c index b0db7a1f..9804fecb 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -32,8 +32,7 @@ static void reparse(TSDocument *document, TSInputEdit *edit) { } } -void ts_document_set_language(TSDocument *document, - const TSLanguage *language) { +void ts_document_set_language(TSDocument *document, const TSLanguage *language) { ts_parser_destroy(&document->parser); document->parser = ts_parser_make(language); document->parser.debug = document->debug; diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 7ad79713..ce07949b 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -19,8 +19,7 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, size_t size, size_t padding, } TSTree *ts_tree_make_error(size_t size, size_t padding, char lookahead_char) { - TSTree *result = - ts_tree_make_leaf(ts_builtin_sym_error, size, padding, false); + TSTree *result = ts_tree_make_leaf(ts_builtin_sym_error, size, padding, false); result->lookahead_char = lookahead_char; return result; } @@ -161,9 +160,8 @@ static size_t write_lookahead_to_string(char *string, size_t limit, } } -static size_t tree_write_to_string(const TSTree *tree, - const char **symbol_names, char *string, - size_t limit, int is_root) { +static size_t tree_write_to_string(const TSTree *tree, const char **symbol_names, + char *string, size_t limit, int is_root) { if (!tree) return snprintf(string, limit, "(NULL)");