fix: handle more cases of editing subtrees that depend on column values
(cherry picked from commit a83b893016)
This commit is contained in:
parent
77794c558f
commit
d10308528d
5 changed files with 137 additions and 3 deletions
21
test/fixtures/test_grammars/depends_on_column/corpus.txt
vendored
Normal file
21
test/fixtures/test_grammars/depends_on_column/corpus.txt
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
==================
|
||||
X is at odd column
|
||||
==================
|
||||
|
||||
x
|
||||
|
||||
---
|
||||
|
||||
(x_is_at
|
||||
(odd_column))
|
||||
|
||||
===================
|
||||
X is at even column
|
||||
===================
|
||||
|
||||
x
|
||||
|
||||
---
|
||||
|
||||
(x_is_at
|
||||
(even_column))
|
||||
7
test/fixtures/test_grammars/depends_on_column/grammar.js
vendored
Normal file
7
test/fixtures/test_grammars/depends_on_column/grammar.js
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = grammar({
|
||||
name: "depends_on_column",
|
||||
rules: {
|
||||
x_is_at: ($) => seq(/[ \r\n]*/, choice($.odd_column, $.even_column), "x"),
|
||||
},
|
||||
externals: ($) => [$.odd_column, $.even_column],
|
||||
});
|
||||
40
test/fixtures/test_grammars/depends_on_column/scanner.c
vendored
Normal file
40
test/fixtures/test_grammars/depends_on_column/scanner.c
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "tree_sitter/parser.h"
|
||||
|
||||
enum TokenType { ODD_COLUMN, EVEN_COLUMN };
|
||||
|
||||
// The scanner is stateless
|
||||
|
||||
void *tree_sitter_depends_on_column_external_scanner_create() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tree_sitter_depends_on_column_external_scanner_destroy(
|
||||
void *payload
|
||||
) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
unsigned tree_sitter_depends_on_column_external_scanner_serialize(
|
||||
void *payload,
|
||||
char *buffer
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tree_sitter_depends_on_column_external_scanner_deserialize(
|
||||
void *payload,
|
||||
const char *buffer,
|
||||
unsigned length
|
||||
) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
bool tree_sitter_depends_on_column_external_scanner_scan(
|
||||
void *payload,
|
||||
TSLexer *lexer,
|
||||
const bool *valid_symbols
|
||||
) {
|
||||
lexer->result_symbol =
|
||||
lexer->get_column(lexer) % 2 ? ODD_COLUMN : EVEN_COLUMN;
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue