Merge pull request #304 from jmitchell/jmitchell/ux-1-index-rows
Use 1-indexed rows in CLI and log output (resolves #287)
This commit is contained in:
commit
55dd2330ab
5 changed files with 37 additions and 10 deletions
|
|
@ -56,6 +56,33 @@ fn test_parsing_with_logging() {
|
|||
"reduce sym:struct_item, child_count:3".to_string()
|
||||
)));
|
||||
assert!(messages.contains(&(LogType::Lex, "skip character:' '".to_string())));
|
||||
|
||||
for (_, m) in &messages {
|
||||
assert!(!m.contains("row:0"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_parsing_with_debug_graph_enabled() {
|
||||
use std::io::{BufRead, BufReader, Seek};
|
||||
|
||||
let has_zero_indexed_row = |s: &str| s.contains("position: 0,");
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(get_language("javascript")).unwrap();
|
||||
|
||||
let mut debug_graph_file = tempfile::tempfile().unwrap();
|
||||
parser.print_dot_graphs(&debug_graph_file);
|
||||
parser.parse("const zero = 0", None).unwrap();
|
||||
|
||||
debug_graph_file.seek(std::io::SeekFrom::Start(0)).unwrap();
|
||||
let log_reader = BufReader::new(debug_graph_file)
|
||||
.lines()
|
||||
.map(|l| l.expect("Failed to read line from graph log"));
|
||||
for line in log_reader {
|
||||
assert!(!has_zero_indexed_row(&line), "Graph log output includes zero-indexed row: {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ tree-sitter parse ./the-file
|
|||
This should print the following:
|
||||
|
||||
```
|
||||
(source_file [0, 0] - [0, 5])
|
||||
(source_file [1, 0] - [1, 5])
|
||||
```
|
||||
|
||||
You might notice that the first time you run `tree-sitter parse`, it takes a few seconds. This is because Tree-sitter automatically compiles your C code into a dynamically-loadable library. Whenever you make changes to your grammar, you can update the parser simply by re-running `tree-sitter generate`. When the parser changes, Tree-sitter will recompile it as needed.
|
||||
|
|
|
|||
|
|
@ -331,8 +331,8 @@ static inline void iterator_print_state(Iterator *self) {
|
|||
"(%-25s %s\t depth:%u [%u, %u] - [%u, %u])",
|
||||
name, self->in_padding ? "(p)" : " ",
|
||||
self->visible_depth,
|
||||
start.row, start.column,
|
||||
end.row, end.column
|
||||
start.row + 1, start.column,
|
||||
end.row + 1, end.column
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -361,7 +361,7 @@ unsigned ts_subtree_get_changed_ranges(const Subtree *old_tree, const Subtree *n
|
|||
|
||||
do {
|
||||
#ifdef DEBUG_GET_CHANGED_RANGES
|
||||
printf("At [%-2u, %-2u] Compare ", position.extent.row, position.extent.column);
|
||||
printf("At [%-2u, %-2u] Compare ", position.extent.row + 1, position.extent.column);
|
||||
iterator_print_state(&old_iter);
|
||||
printf("\tvs\t");
|
||||
iterator_print_state(&new_iter);
|
||||
|
|
@ -443,8 +443,8 @@ unsigned ts_subtree_get_changed_ranges(const Subtree *old_tree, const Subtree *n
|
|||
#ifdef DEBUG_GET_CHANGED_RANGES
|
||||
printf(
|
||||
" change: [[%u, %u] - [%u, %u]]\n",
|
||||
position.extent.row, position.extent.column,
|
||||
next_position.extent.row, next_position.extent.column
|
||||
position.extent.row + 1, position.extent.column,
|
||||
next_position.extent.row + 1, next_position.extent.column
|
||||
);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId pa
|
|||
LOG(
|
||||
"lex_external state:%d, row:%u, column:%u",
|
||||
lex_mode.external_lex_state,
|
||||
current_position.extent.row,
|
||||
current_position.extent.row + 1,
|
||||
current_position.extent.column
|
||||
);
|
||||
ts_lexer_start(&self->lexer);
|
||||
|
|
@ -370,7 +370,7 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId pa
|
|||
LOG(
|
||||
"lex_internal state:%d, row:%u, column:%u",
|
||||
lex_mode.lex_state,
|
||||
current_position.extent.row,
|
||||
current_position.extent.row + 1,
|
||||
current_position.extent.column
|
||||
);
|
||||
ts_lexer_start(&self->lexer);
|
||||
|
|
@ -1674,7 +1674,7 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) {
|
|||
LOG("process version:%d, version_count:%u, state:%d, row:%u, col:%u",
|
||||
version, ts_stack_version_count(self->stack),
|
||||
ts_stack_state(self->stack, version),
|
||||
ts_stack_position(self->stack, version).extent.row,
|
||||
ts_stack_position(self->stack, version).extent.row + 1,
|
||||
ts_stack_position(self->stack, version).extent.column);
|
||||
|
||||
if (!ts_parser__advance(self, version, allow_node_reuse)) return NULL;
|
||||
|
|
|
|||
|
|
@ -785,7 +785,7 @@ bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f)
|
|||
fprintf(
|
||||
f,
|
||||
" tooltip=\"position: %u,%u\nnode_count:%u\nerror_cost: %u\ndynamic_precedence: %d\"];\n",
|
||||
node->position.extent.row,
|
||||
node->position.extent.row + 1,
|
||||
node->position.extent.column,
|
||||
node->node_count,
|
||||
node->error_cost,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue