From af011e6e1a448c1080b8281203436fe2ed27b101 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Sun, 31 Mar 2024 22:54:26 +0300 Subject: [PATCH] feat(queries): add highlight queries --- bindings/rust/lib.rs | 8 +--- package.json | 1 + queries/highlights.scm | 79 ++++++++++++++++++++++++++++++++++++++++ test/highlight/core.yaml | 32 ++++++++++++++++ 4 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 queries/highlights.scm create mode 100644 test/highlight/core.yaml diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 5d77cb6..c7560ae 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -39,12 +39,8 @@ pub fn language() -> Language { /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); -// Uncomment these to include any queries that this grammar contains - -// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); -// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); -// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); -// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); +/// The highlight queries for this grammar. +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); #[cfg(test)] mod tests { diff --git a/package.json b/package.json index d2fb394..1010b01 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "yaml" ], "injection-regex": "^ya?ml$", + "highlights": "queries/highlights.scm", "external-files": [ "src/schema.generated.c" ] diff --git a/queries/highlights.scm b/queries/highlights.scm new file mode 100644 index 0000000..cb9dcc6 --- /dev/null +++ b/queries/highlights.scm @@ -0,0 +1,79 @@ +(boolean_scalar) @boolean + +(null_scalar) @constant.builtin + +[ + (double_quote_scalar) + (single_quote_scalar) + (block_scalar) + (string_scalar) +] @string + +[ + (integer_scalar) + (float_scalar) +] @number + +(comment) @comment + +[ + (anchor_name) + (alias_name) +] @label + +(tag) @type + +[ + (yaml_directive) + (tag_directive) + (reserved_directive) +] @attribute + +(block_mapping_pair + key: (flow_node + [ + (double_quote_scalar) + (single_quote_scalar) + ] @property)) + +(block_mapping_pair + key: (flow_node + (plain_scalar + (string_scalar) @property))) + +(flow_mapping + (_ + key: (flow_node + [ + (double_quote_scalar) + (single_quote_scalar) + ] @property))) + +(flow_mapping + (_ + key: (flow_node + (plain_scalar + (string_scalar) @property)))) + +[ + "," + "-" + ":" + ">" + "?" + "|" +] @punctuation.delimiter + +[ + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "*" + "&" + "---" + "..." +] @punctuation.special diff --git a/test/highlight/core.yaml b/test/highlight/core.yaml new file mode 100644 index 0000000..8ec6d05 --- /dev/null +++ b/test/highlight/core.yaml @@ -0,0 +1,32 @@ +A null: null +# <- @property +# ^ @punctuation.delimiter +# ^^^^ @constant.builtin +Also a null: # Empty +# ^^^^^^^ @comment +Not a null: "" +# ^^ @string +Booleans: [ true, True, false, FALSE ] +# ^ @punctuation.bracket +# ^ @punctuation.bracket +# ^ @punctuation.delimiter +# ^^^^ @boolean +# ^^^^ @boolean +# ^^^^^ @boolean +# ^^^^^ @boolean +Integers: [ 0, 0o7, 0x3A, -19 ] +# ^ @number +# ^^^ @number +# ^^^^ @number +# ^^^ @number +Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] +# ^^ @number +# ^^^^ @number +# ^^ @number +# ^^^^^^ @number +# ^^^^^^ @number +Also floats: [ .inf, -.Inf, +.INF, .NAN ] +# ^^^^ @number +# ^^^^^ @number +# ^^^^^ @number +# ^^^^ @number