From 740d864e678ab0c5518780afd906e2123d8a9d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=E1=BA=A5n-Anh=20Nguy=E1=BB=85n?= Date: Sun, 19 Jul 2020 12:40:17 +0700 Subject: [PATCH] Add '.' as a valid start of a predicate, in addition to '#' See https://github.com/ubolonton/emacs-tree-sitter/issues/38 --- cli/src/tests/query_test.rs | 29 +++++++++++++++++++++++++++++ lib/src/query.c | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 06ecc42e..493bea8a 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -2087,6 +2087,35 @@ fn test_query_disable_pattern() { }); } +#[test] +fn test_query_alternative_predicate_prefix() { + allocations::record(|| { + let language = get_language("c"); + let query = Query::new(language, r#" + ((call_expression + function: (identifier) @keyword + arguments: (argument_list + (string_literal) @function)) + (.eq? @keyword "DEFUN")) + "#).unwrap(); + let source = r#" + DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0, + doc: /* Return the argument unchanged. */ + attributes: const) + (Lisp_Object arg) + { + return arg; + } + "#; + assert_query_matches( + language, + &query, + source, + &[(0, vec![("keyword", "DEFUN"), ("function", "\"identity\"")])], + ); + }); +} + fn assert_query_matches( language: Language, query: &Query, diff --git a/lib/src/query.c b/lib/src/query.c index b95ba057..acce2c72 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -805,8 +805,8 @@ static TSQueryError ts_query__parse_pattern( } } - // A pound character indicates the start of a predicate. - else if (stream->next == '#') { + // A dot/pound character indicates the start of a predicate. + else if (stream->next == '.' || stream->next == '#') { stream_advance(stream); return ts_query__parse_predicate(self, stream); }