Clean up lint errors

This commit is contained in:
Max Brunsfeld 2014-06-09 21:14:38 -07:00
parent 54a555168d
commit 21c259df9c
13 changed files with 57 additions and 58 deletions

View file

@ -37,7 +37,7 @@ static ts_tree * ts_lex(ts_lexer *lexer, ts_state_id lex_state)
#else
#define DEBUG_LEX(...)
#endif
#define START_LEXER() \
DEBUG_LEX("LEX %d", lex_state); \
char lookahead; \

View file

@ -11,6 +11,6 @@ fi
$CPPLINT \
--root=src \
--linelength=110 \
--filter=-legal/copyright,-readability/namespace,-whitespace/indent,-whitespace/line_length \
--filter=-legal/copyright,-readability/namespace,-whitespace/indent,-whitespace/line_length,-readability/todo \
$(find src/compiler -type f) \
2>&1

View file

@ -89,7 +89,7 @@ static vector<string> list_directory(string dir_name) {
if (name != "." && name != "..")
result.push_back(dir_name + "/" + name);
}
closedir(dir);
return result;
}

View file

@ -8,43 +8,43 @@ int hidden_symbols[] = { 0, 0, 1 };
describe("stacks", [&]() {
ts_stack stack;
before_each([&]() {
stack = ts_stack_make();
});
after_each([&]() {
ts_stack_delete(&stack);
});
it("starts out empty", [&]() {
AssertThat(stack.size, Equals(0));
AssertThat(ts_stack_top_state(&stack), Equals(0));
AssertThat(ts_stack_top_node(&stack), Equals((ts_tree *)nullptr));
});
describe("pushing a symbol", [&]() {
ts_tree *node1;
before_each([&]() {
node1 = ts_tree_make_leaf(sym1, 5, 1);
ts_stack_push(&stack, 5, node1);
});
after_each([&]() {
ts_tree_release(node1);
});
it("adds the symbol to the stack", [&]() {
AssertThat(stack.size, Equals(1));
AssertThat(ts_stack_top_state(&stack), Equals(5));
AssertThat(ts_stack_top_node(&stack), Equals(node1));
});
});
describe("reducing a symbol", [&]() {
ts_tree **nodes;
before_each([&]() {
nodes = tree_array({
ts_tree_make_leaf(sym1, 5, 1),
@ -52,35 +52,35 @@ describe("stacks", [&]() {
ts_tree_make_leaf(hidden_sym, 5, 1),
ts_tree_make_leaf(sym1, 5, 1),
});
for (ts_state_id i = 0; i < 4; i++)
ts_stack_push(&stack, 10 + i, nodes[i]);
});
after_each([&]() {
for (ts_state_id i = 0; i < 4; i++)
ts_tree_release(nodes[i]);
free(nodes);
});
it("pops the given number of nodes off the stack", [&]() {
AssertThat(stack.size, Equals(4));
ts_stack_reduce(&stack, sym2, 3, hidden_symbols, nullptr);
AssertThat(stack.size, Equals(1));
});
it("returns a node with the given symbol", [&]() {
ts_tree *node = ts_stack_reduce(&stack, sym2, 3, hidden_symbols, nullptr);
AssertThat(ts_tree_symbol(node), Equals(sym2));
});
it("makes all of the removed nodes immediate children of the new node", [&]() {
ts_tree *expected_children[3] = {
stack.entries[1].node,
stack.entries[2].node,
stack.entries[3].node,
};
ts_tree *node = ts_stack_reduce(&stack, sym2, 3, hidden_symbols, nullptr);
size_t immediate_child_count;
ts_tree **immediate_children = ts_tree_immediate_children(node, &immediate_child_count);
@ -89,46 +89,46 @@ describe("stacks", [&]() {
for (size_t i = 0; i < 3; i++)
AssertThat(immediate_children[i], Equals(expected_children[i]));
});
it("removes any hidden nodes from its regular list of children", [&]() {
ts_tree *expected_children[2] = {
stack.entries[1].node,
stack.entries[3].node,
};
ts_tree *node = ts_stack_reduce(&stack, sym2, 3, hidden_symbols, nullptr);
size_t child_count;
ts_tree **children = ts_tree_children(node, &child_count);
AssertThat(child_count, Equals(2));
for (size_t i = 0; i < 2; i++)
AssertThat(children[i], Equals(expected_children[i]));
});
describe("when there are hidden nodes with children of their own", [&]() {
ts_tree **grandchildren;
ts_tree *hidden_node;
before_each([&]() {
grandchildren = tree_array({
ts_tree_make_leaf(sym1, 10, 2),
ts_tree_make_leaf(sym2, 10, 2),
});
hidden_node = ts_tree_make_node(hidden_sym, 2, 0, grandchildren);
ts_stack_push(&stack, 21, hidden_node);
});
after_each([&]() {
for (ts_state_id i = 0; i < 2; i++)
ts_tree_release(grandchildren[i]);
free(grandchildren);
ts_tree_release(hidden_node);
});
it("makes those child nodes children of the new node", [&]() {
ts_tree *node = ts_stack_reduce(&stack, sym2, 4, hidden_symbols, nullptr);
ts_tree *expected_children[4] = {
stack.entries[1].node,
stack.entries[3].node,
@ -138,7 +138,7 @@ describe("stacks", [&]() {
size_t child_count;
ts_tree **children = ts_tree_children(node, &child_count);
AssertThat(child_count, Equals(4));
for (size_t i = 0; i < 4; i++)
AssertThat(children[i], Equals(expected_children[i]));

View file

@ -27,12 +27,12 @@ describe("trees", []() {
ts_tree_release(tree2);
ts_tree_release(parent1);
});
describe("making a parent node", [&]() {
it("computes its offset and size based on its child nodes", [&]() {
AssertThat(ts_tree_size(parent1), Equals(9));
});
it("computes its offset based on its first child", [&]() {
AssertThat(ts_tree_offset(parent1), Equals(2));
});

View file

@ -56,7 +56,7 @@ namespace tree_sitter {
else
return stream << string("#<null>");
}
const vector<string> & Grammar::ubiquitous_tokens() const {
return ubiquitous_tokens_;
}
@ -65,7 +65,7 @@ namespace tree_sitter {
ubiquitous_tokens_ = ubiquitous_tokens;
return *this;
}
const vector<pair<string, rule_ptr>> & Grammar::rules() const {
return rules_;
}

View file

@ -1,6 +1,7 @@
#ifndef COMPILER_PREPARE_GRAMMAR_EXPAND_TOKENS_H_
#define COMPILER_PREPARE_GRAMMAR_EXPAND_TOKENS_H_
#include <utility>
#include "tree_sitter/compiler.h"
namespace tree_sitter {

View file

@ -69,7 +69,6 @@ namespace tree_sitter {
size_t index = tokens.size();
tokens.push_back({ token_description(rule), rule });
return make_shared<Symbol>(index, SymbolOptionAuxToken);
}
rule_ptr default_apply(const rules::Rule *rule) {

View file

@ -1,6 +1,7 @@
#include "compiler/prepare_grammar/parse_regex.h"
#include <string>
#include <utility>
#include <vector>
#include "compiler/rules/choice.h"
#include "compiler/rules/seq.h"
#include "compiler/rules/repeat.h"

View file

@ -1,9 +1,9 @@
#ifndef COMPILER_PREPARE_GRAMMAR_PARSE_REGEX_H_
#define COMPILER_PREPARE_GRAMMAR_PARSE_REGEX_H_
#include "tree_sitter/compiler.h"
#include <string>
#include <utility>
#include "tree_sitter/compiler.h"
namespace tree_sitter {
namespace prepare_grammar {
@ -12,5 +12,4 @@ namespace tree_sitter {
}
}
#endif // COMPILER_PREPARE_GRAMMAR_PARSE_REGEX_H_
#endif // COMPILER_PREPARE_GRAMMAR_PARSE_REGEX_H_

View file

@ -4,7 +4,6 @@
#include "compiler/rules/pattern.h"
#include "compiler/rules/seq.h"
#include "compiler/rules/choice.h"
#include "compiler/rules/seq.h"
#include "compiler/rules/string.h"
#include "compiler/rules/metadata.h"
#include "compiler/util/string_helpers.h"

View file

@ -1,5 +1,5 @@
#ifndef COMPILER_GENERATE_CODE_TOKEN_DESCRIPTION_H_
#define COMPILER_GENERATE_CODE_TOKEN_DESCRIPTION_H_
#ifndef COMPILER_PREPARE_GRAMMAR_TOKEN_DESCRIPTION_H_
#define COMPILER_PREPARE_GRAMMAR_TOKEN_DESCRIPTION_H_
#include <string>
#include "tree_sitter/compiler.h"
@ -10,4 +10,4 @@ namespace tree_sitter {
}
}
#endif // COMPILER_GENERATE_CODE_TOKEN_DESCRIPTION_H_
#endif // COMPILER_PREPARE_GRAMMAR_TOKEN_DESCRIPTION_H_

View file

@ -25,22 +25,22 @@ void reduce(ts_lr_parser *parser, ts_symbol symbol, size_t child_count) {
static size_t breakdown_stack(ts_lr_parser *parser, ts_input_edit *edit) {
if (!edit) return 0;
ts_stack *stack = &parser->stack;
size_t position = 0;
for (;;) {
ts_tree *node = ts_stack_top_node(stack);
if (!node) break;
position = ts_stack_right_position(stack);
size_t child_count;
ts_tree **children = ts_tree_immediate_children(node, &child_count);
if (position <= edit->position && !children) break;
stack->size--;
position -= ts_tree_total_size(node);
for (size_t i = 0; i < child_count && position < edit->position; i++) {
ts_tree *child = children[i];
ts_state_id state = ts_stack_top_state(stack);
@ -49,10 +49,10 @@ static size_t breakdown_stack(ts_lr_parser *parser, ts_input_edit *edit) {
ts_tree_retain(child);
position += ts_tree_total_size(child);
}
ts_tree_release(node);
}
return position;
}
@ -62,13 +62,13 @@ ts_symbol * expected_symbols(ts_lr_parser *parser, size_t *count) {
for (size_t i = 0; i < parser->config.symbol_count; i++)
if (actions[i].type != ts_parse_action_type_error)
++(*count);
size_t n = 0;
ts_symbol *result = malloc(*count * sizeof(*result));
for (ts_symbol i = 0; i < parser->config.symbol_count; i++)
if (actions[i].type != ts_parse_action_type_error)
result[n++] = i;
return result;
}
@ -79,21 +79,21 @@ int handle_error(ts_lr_parser *parser) {
expected_symbols(parser, &count),
0,
0);
for (;;) {
ts_tree_release(parser->lookahead);
size_t position = ts_lexer_position(&parser->lexer);
parser->lookahead = parser->config.lex_fn(&parser->lexer, ts_lex_state_error);
int at_end = 0;
if (ts_lexer_position(&parser->lexer) == position)
at_end = !ts_lexer_advance(&parser->lexer);
if (at_end || ts_tree_symbol(parser->lookahead) == ts_builtin_sym_end) {
ts_stack_push(&parser->stack, 0, error);
return 0;
}
/*
* Unwind the stack, looking for a state in which this token
* may appear after an error.
@ -121,10 +121,10 @@ ts_tree * get_tree_root(ts_lr_parser *parser) {
return top_node;
if (ts_tree_symbol(top_node) == ts_builtin_sym_error)
return top_node;
size_t immediate_child_count;
ts_tree **immedate_children = ts_tree_immediate_children(top_node, &immediate_child_count);
stack->size--;
for (size_t i = 0; i < immediate_child_count; i++) {
ts_tree *child = immedate_children[i];
@ -133,7 +133,7 @@ ts_tree * get_tree_root(ts_lr_parser *parser) {
ts_state_id next_state = actions_for_state(parser, state)[ts_tree_symbol(child)].data.to_state;
ts_stack_push(stack, next_state, child);
}
ts_tree *new_node = ts_stack_reduce(stack,
ts_tree_symbol(top_node),
stack->size,
@ -188,10 +188,10 @@ void ts_lr_parser_initialize(ts_lr_parser *parser, ts_input input, ts_input_edit
if (!edit) ts_stack_shrink(&parser->stack, 0);
parser->lookahead = NULL;
parser->next_lookahead = NULL;
size_t position = breakdown_stack(parser, edit);
input.seek_fn(input.data, position);
parser->lexer = ts_lexer_make();
parser->lexer.input = input;
ts_lexer_advance(&parser->lexer);