Allow queries to capture ERROR nodes
This commit is contained in:
parent
40408fe6bb
commit
fa43ce01a6
2 changed files with 31 additions and 0 deletions
|
|
@ -365,6 +365,36 @@ fn test_query_matches_with_many() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_capturing_error_nodes() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(
|
||||
language,
|
||||
"
|
||||
(ERROR (identifier) @the-error-identifier) @the-error
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let source = "function a(b,, c, d :e:) {}";
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
let tree = parser.parse(source, None).unwrap();
|
||||
let mut cursor = QueryCursor::new();
|
||||
let matches = cursor.matches(&query, tree.root_node(), to_callback(source));
|
||||
|
||||
assert_eq!(
|
||||
collect_matches(matches, &query, source),
|
||||
&[(
|
||||
0,
|
||||
vec![("the-error", ":e:"), ("the-error-identifier", "e"),]
|
||||
),]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_in_language_with_simple_aliases() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ static TSSymbol ts_query_intern_node_name(
|
|||
uint32_t length,
|
||||
TSSymbolType symbol_type
|
||||
) {
|
||||
if (!strncmp(name, "ERROR", length)) return ts_builtin_sym_error;
|
||||
uint32_t symbol_count = ts_language_symbol_count(self->language);
|
||||
for (TSSymbol i = 0; i < symbol_count; i++) {
|
||||
if (ts_language_symbol_type(self->language, i) != symbol_type) continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue