From 95616e4dc4cfa67726a99321c83582fce07662df Mon Sep 17 00:00:00 2001 From: Matthias Queitsch Date: Mon, 27 Feb 2023 22:02:30 +0100 Subject: [PATCH 1/4] feat(prql): add prql support --- book/src/generated/lang-support.md | 1 + languages.toml | 13 +++ runtime/queries/prql/highlights.scm | 140 ++++++++++++++++++++++++++++ runtime/queries/prql/injections.scm | 11 +++ 4 files changed, 165 insertions(+) create mode 100644 runtime/queries/prql/highlights.scm create mode 100644 runtime/queries/prql/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index e997b3e81ccc..cf8e502363b8 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -104,6 +104,7 @@ | prisma | ✓ | | | `prisma-language-server` | | prolog | | | | `swipl` | | protobuf | ✓ | | ✓ | | +| prql | ✓ | | | | | purescript | ✓ | | | `purescript-language-server` | | python | ✓ | ✓ | ✓ | `pylsp` | | qml | ✓ | | ✓ | `qmlls` | diff --git a/languages.toml b/languages.toml index d4ea9a8678c9..f78db21e4aa5 100644 --- a/languages.toml +++ b/languages.toml @@ -2208,6 +2208,19 @@ indent = { tab-width = 2, unit = " " } name = "yuck" source = { git = "https://github.com/Philipp-M/tree-sitter-yuck", rev = "9e97da5773f82123a8c8cccf8f7e795d140ed7d1" } +[[language]] +name = "prql" +scope = "source.yprql" +injection-regex = "prql" +file-types = ["prql"] +roots = [] +comment-token = "#" +indent = { tab-width = 4, unit = " " } + +[[grammar]] +name = "prql" +source = { git = "https://github.com/PRQL/tree-sitter-prql", rev = "3f27cac466f030ee7d985d91eba5470e01dd21ea" } + [[language]] name = "po" scope = "source.po" diff --git a/runtime/queries/prql/highlights.scm b/runtime/queries/prql/highlights.scm new file mode 100644 index 000000000000..5b28df153ab2 --- /dev/null +++ b/runtime/queries/prql/highlights.scm @@ -0,0 +1,140 @@ +[ + (keyword_from) + (keyword_filter) + (keyword_derive) + (keyword_group) + (keyword_aggregate) + (keyword_sort) + (keyword_take) + (keyword_window) + (keyword_join) + (keyword_select) + (keyword_switch) + (keyword_inner) + (keyword_right) + (keyword_full) + (keyword_in) + (keyword_rolling) + (keyword_rows) + (keyword_expanding) + (keyword_let) + (keyword_prql) + (keyword_switch) + (keyword_append) + (keyword_remove) + (keyword_intersect) +] @keyword + +(literal) @string + +(assignment + alias: (field) @field) + +alias: (identifier) @field + +(f_string) @string.special +(s_string) @string.special + +(comment) @comment + +(keyword_func) @keyword.function + +(function_call + (identifier) @function.call) + +[ + "+" + "-" + "*" + "/" + "=" + "==" + "<" + "<=" + "!=" + ">=" + ">" + "->" + (bang) +] @operator + +[ + "(" + ")" + "[" + "]" +] @punctuation.bracket + +[ + "," + "." + (pipe) +] @punctuation.delimiter + +(literal + (integer) @number) + +(integer) @number + +(literal + (decimal_number) @float) + +(decimal_number) @float + +[ + (keyword_min) + (keyword_max) + (keyword_count) + (keyword_count_distinct) + (keyword_average) + (keyword_avg) + (keyword_sum) + (keyword_stddev) + (keyword_count) +] @function.call + +[ + (keyword_side) + (keyword_version) + (keyword_target) + (keyword_null) + (keyword_format) +] @attribute + +(target) @function.builtin + + [ + (date) + (time) + (timestamp) +] @string.special + +[ + (keyword_left) + (keyword_inner) + (keyword_right) + (keyword_full) + (keyword_csv) + (keyword_json) +] @method + +[ + (keyword_true) + (keyword_false) +] @boolean + +[ + (keyword_and) + (keyword_or) +] @keyword.operator + +(function_definition + (keyword_func) + name: (identifier) @function) + +(parameter + (identifier) @parameter) + +(variable + (keyword_let) + name: (identifier) @constant) diff --git a/runtime/queries/prql/injections.scm b/runtime/queries/prql/injections.scm new file mode 100644 index 000000000000..f3ca44103f8b --- /dev/null +++ b/runtime/queries/prql/injections.scm @@ -0,0 +1,11 @@ +( + (s_string) @sql + (#offset! @sql 0 2 0 -1) +) + +(from_text + (keyword_from_text) + (keyword_json) + (literal) @json + (#offset! @json 0 3 0 -3) +) From c6925c5779f6c67b519b1713ed7c5dcab7dafa0d Mon Sep 17 00:00:00 2001 From: Matthias Queitsch Date: Tue, 28 Feb 2023 17:33:07 +0100 Subject: [PATCH 2/4] feat(prql): update queries --- languages.toml | 2 +- runtime/queries/prql/highlights.scm | 12 ++++++------ runtime/queries/prql/injections.scm | 11 ++++------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/languages.toml b/languages.toml index f78db21e4aa5..2edf15062207 100644 --- a/languages.toml +++ b/languages.toml @@ -2210,7 +2210,7 @@ source = { git = "https://github.com/Philipp-M/tree-sitter-yuck", rev = "9e97da5 [[language]] name = "prql" -scope = "source.yprql" +scope = "source.prql" injection-regex = "prql" file-types = ["prql"] roots = [] diff --git a/runtime/queries/prql/highlights.scm b/runtime/queries/prql/highlights.scm index 5b28df153ab2..89db9eb19309 100644 --- a/runtime/queries/prql/highlights.scm +++ b/runtime/queries/prql/highlights.scm @@ -28,9 +28,9 @@ (literal) @string (assignment - alias: (field) @field) + alias: (field) @variable.other.member) -alias: (identifier) @field +alias: (identifier) @variable.other.member (f_string) @string.special (s_string) @string.special @@ -72,14 +72,14 @@ alias: (identifier) @field ] @punctuation.delimiter (literal - (integer) @number) + (integer) @constant.numeric.integer) -(integer) @number +(integer) @constant.numeric.integer (literal - (decimal_number) @float) + (decimal_number) @constant.numeric.float) -(decimal_number) @float +(decimal_number) @constant.numeric.float [ (keyword_min) diff --git a/runtime/queries/prql/injections.scm b/runtime/queries/prql/injections.scm index f3ca44103f8b..02a8919f8951 100644 --- a/runtime/queries/prql/injections.scm +++ b/runtime/queries/prql/injections.scm @@ -1,11 +1,8 @@ -( - (s_string) @sql - (#offset! @sql 0 2 0 -1) -) +((s_string) @injection.content + (#set! injection.language "sql")) (from_text (keyword_from_text) (keyword_json) - (literal) @json - (#offset! @json 0 3 0 -3) -) + (literal) @injection.content + (#set! injection.language "json")) From 2a4ac86a0de35ffe9c5bb9cec49c45c968a0892d Mon Sep 17 00:00:00 2001 From: Matthias Queitsch Date: Tue, 28 Feb 2023 17:37:31 +0100 Subject: [PATCH 3/4] feat(prql): update more queries --- runtime/queries/prql/highlights.scm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/runtime/queries/prql/highlights.scm b/runtime/queries/prql/highlights.scm index 89db9eb19309..a9d111d91f90 100644 --- a/runtime/queries/prql/highlights.scm +++ b/runtime/queries/prql/highlights.scm @@ -10,19 +10,15 @@ (keyword_join) (keyword_select) (keyword_switch) - (keyword_inner) - (keyword_right) - (keyword_full) - (keyword_in) + (keyword_append) + (keyword_remove) + (keyword_intersect) (keyword_rolling) (keyword_rows) (keyword_expanding) (keyword_let) (keyword_prql) - (keyword_switch) - (keyword_append) - (keyword_remove) - (keyword_intersect) + (keyword_from_text) ] @keyword (literal) @string @@ -116,12 +112,12 @@ alias: (identifier) @variable.other.member (keyword_full) (keyword_csv) (keyword_json) -] @method +] @function.method [ (keyword_true) (keyword_false) -] @boolean +] @constant.builtin.boolean [ (keyword_and) @@ -133,7 +129,7 @@ alias: (identifier) @variable.other.member name: (identifier) @function) (parameter - (identifier) @parameter) + (identifier) @variable.parameter) (variable (keyword_let) From 0dfa35c43445e58f842c958d83aa60a4786ff503 Mon Sep 17 00:00:00 2001 From: Matthias Queitsch Date: Fri, 3 Mar 2023 17:52:49 +0100 Subject: [PATCH 4/4] feat(prql): update function queries --- runtime/queries/prql/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/prql/highlights.scm b/runtime/queries/prql/highlights.scm index a9d111d91f90..5cfedee4853c 100644 --- a/runtime/queries/prql/highlights.scm +++ b/runtime/queries/prql/highlights.scm @@ -36,7 +36,7 @@ alias: (identifier) @variable.other.member (keyword_func) @keyword.function (function_call - (identifier) @function.call) + (identifier) @function) [ "+" @@ -87,7 +87,7 @@ alias: (identifier) @variable.other.member (keyword_sum) (keyword_stddev) (keyword_count) -] @function.call +] @function [ (keyword_side)