Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed unused keyword #179

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
node-version: 18
- run: npm install
- run: npm test
- run: scripts/test-keywords.sh
validate_tests:
runs-on: ["ubuntu-latest"]
strategy:
Expand Down
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ module.exports = grammar({
),

function_language: $ => seq(
make_keyword('language'),
$.keyword_language,
choice(
$.keyword_sql,
$.keyword_plpgsql,
Expand Down
43 changes: 38 additions & 5 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
(keyword_spgist)
(keyword_gin)
(keyword_brin)
(keyword_float)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float can be a @function.call and a @type.builtin

select 
 1::float;

select 
 float(1);

So I would keep it there. in nvim-treesitter - the last match wins, thus the order matters here (which makes things unnecessarily complicated imo.)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have float in @type.builtin and the rule for invocation should cover the @function.call case.

(keyword_array)
] @function.call

Expand Down Expand Up @@ -68,6 +67,13 @@
(keyword_following)
(keyword_first)
(keyword_current_timestamp)
(keyword_immutable)
(keyword_atomic)
(keyword_parallel)
(keyword_leakproof)
(keyword_safe)
(keyword_cost)
(keyword_strict)
] @attribute

[
Expand All @@ -85,6 +91,7 @@
(keyword_avro)
(keyword_jsonfile)
(keyword_sequencefile)
(keyword_volatile)
] @storageclass

[
Expand Down Expand Up @@ -191,21 +198,44 @@
(keyword_sort)
(keyword_compute)
(keyword_comment)
(keyword_partitioned)
(keyword_location)
(keyword_cached)
(keyword_uncached)
(keyword_lines)
(keyword_stored)
(keyword_location)
(keyword_partitioned)
(keyword_cached)
(keyword_analyze)
(keyword_rewrite)
(keyword_statistics)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think statistics and stats should be @type.qualifier and not @keyword

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these from here because they were duplicated in @type.qualifier already 👍

(keyword_optimize)
(keyword_vacuum)
(keyword_cache)
(keyword_language)
(keyword_sql)
(keyword_called)
(keyword_conflict)
(keyword_declare)
(keyword_filter)
(keyword_function)
(keyword_input)
(keyword_name)
(keyword_oid)
(keyword_options)
(keyword_plpgsql)
(keyword_precision)
(keyword_regclass)
(keyword_regnamespace)
(keyword_regproc)
(keyword_regtype)
(keyword_restricted)
(keyword_return)
(keyword_returns)
(keyword_separator)
(keyword_setof)
(keyword_stable)
(keyword_support)
(keyword_tblproperties)
(keyword_trigger)
(keyword_unsafe)
] @keyword

[
Expand Down Expand Up @@ -244,10 +274,12 @@
(keyword_serial)
(keyword_bigserial)
(keyword_smallint)
(keyword_mediumint)
(keyword_bigint)
(keyword_tinyint)
(keyword_decimal)
(keyword_float)
(keyword_double)
(keyword_numeric)
(keyword_real)
(double)
Expand Down Expand Up @@ -291,6 +323,7 @@
"/"
"%"
"^"
":="
"="
"<"
"<="
Expand Down
20 changes: 20 additions & 0 deletions scripts/test-keywords.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

mkdir -p tmp/tree-sitter-sql/

cat src/grammar.json |
jq '.rules | to_entries[] | select(.key | contains("keyword")) | .key' |
tr -d '"' |
sort > tmp/tree-sitter-sql/keywords.txt

cat queries/highlights.scm |
grep -o "keyword\w\+" |
sort > tmp/tree-sitter-sql/highlights.txt

keywords=$(comm -3 tmp/tree-sitter-sql/keywords.txt tmp/tree-sitter-sql/highlights.txt)

if [[ "$keywords" ]]; then
echo "ERROR: keywords in grammar.json are not in sync with queries/highlights.scm"
echo $keywords
exit 1
fi
10 changes: 10 additions & 0 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ return 1;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_return)
Expand Down Expand Up @@ -521,6 +522,7 @@ return 1;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_return)
Expand Down Expand Up @@ -557,6 +559,7 @@ return 1;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_volatility
(keyword_immutable))
Expand Down Expand Up @@ -616,6 +619,7 @@ create or replace function public.fn()
value: (literal)))))
(dollar_quote))
(function_language
(keyword_language)
(keyword_sql))
(function_volatility
(keyword_volatile))
Expand Down Expand Up @@ -661,6 +665,7 @@ as 'select 1;';
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_as)
Expand Down Expand Up @@ -691,6 +696,7 @@ as 'create table x (id int) row_format=dynamic';
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_as)
Expand Down Expand Up @@ -723,6 +729,7 @@ end;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_sql))
(function_body
(keyword_begin)
Expand Down Expand Up @@ -760,6 +767,7 @@ $function$;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_plpgsql))
(function_body
(keyword_as)
Expand Down Expand Up @@ -803,6 +811,7 @@ $function$;
(int
(keyword_int))
(function_language
(keyword_language)
(keyword_plpgsql))
(function_body
(keyword_as)
Expand Down Expand Up @@ -883,6 +892,7 @@ $function$
(keyword_returns)
(keyword_trigger)
(function_language
(keyword_language)
(keyword_plpgsql))
(function_body
(keyword_as)
Expand Down