Repository: DerekStride/tree-sitter-sql (language: python)

Issue:
Between expression or parentheses within case when context are not parsed correctly
Tree-sitter-sql is really great, while I found some legal queries aren't paresed correctly. Would you mind checking them? 
The problems occur when 'between expression' or 'parentheses'  are surrounded by case when statement, here are two examples: 
```
SELECT 
a.*,
case when a.col BETWEEN 0 AND 1 then 1
when a.col >=1 then 0
end as col2
FROM tb_name a
;


SELECT
  a.*,
  CASE WHEN a.col_1 >= 100 THEN 0 ELSE 1 END AS col_a,
  CASE WHEN (a.col_1 >= 100) THEN 0 ELSE 1 END AS col_b
  CASE WHEN ((a.col_0 >= 1) AND (a.col_1 >= 100)) THEN 0
  END AS col_c
FROM
  tb_name a
WHERE
  ((a.col_0 >= 1) AND (a.col_1 >= 100))
;


```


 


Discussion / hints:
I'll take a look. @Appalled which dialect is this? Postgres, MySQL, MSSQL or something else?

Fix patch:
diff --git a/grammar.js b/grammar.js
index afeffd81..316fa7ac 100644
--- a/grammar.js
+++ b/grammar.js
@@ -1358,16 +1358,13 @@ module.exports = grammar({
         // standard CASE WHEN x, where x must be a predicate
         seq(
           $.keyword_when,
-          choice(
-            $.binary_expression,
-            $.identifier,
-          ),
+          $._expression,
           $.keyword_then,
           $._expression,
           repeat(
             seq(
               $.keyword_when,
-              $.binary_expression,
+              $._expression,
               $.keyword_then,
               $._expression,
             )


Test patch:
diff --git a/test/corpus/select.txt b/test/corpus/select.txt
index 216c6c90..1fa72f0b 100644
--- a/test/corpus/select.txt
+++ b/test/corpus/select.txt
@@ -1633,7 +1633,15 @@ FROM my_table;
 Standard CASE
 ================================================================================
 
-SELECT a, CASE WHEN b = 1 THEN 'yes' ELSE 'no' END AS is_b
+SELECT
+    a,
+    CASE
+        WHEN b BETWEEN 0 AND 1 THEN 'small'
+        WHEN (b < 100) THEN 'lower_hundered'
+        WHEN ((b < 1000) and (b>300)) THEN 'middle'
+        WHEN b > 1 THEN 'yes'
+        ELSE 'no'
+    END AS is_b
 FROM my_table;
 
 --------------------------------------------------------------------------------
@@ -1650,6 +1658,36 @@ FROM my_table;
           (case
             (keyword_case)
             (keyword_when)
+            (between_expression
+              (field
+                (identifier))
+              (keyword_between)
+              (literal)
+              (keyword_and)
+              (literal))
+            (keyword_then)
+            (literal)
+            (keyword_when)
+            (binary_expression
+              (field
+                (identifier))
+              (literal))
+            (keyword_then)
+            (literal)
+            (keyword_when)
+            (binary_expression
+              (binary_expression
+                (field
+                  (identifier))
+                (literal))
+              (keyword_and)
+              (binary_expression
+                (field
+                  (identifier))
+                (literal)))
+            (keyword_then)
+            (literal)
+            (keyword_when)
             (binary_expression
               (field
                 (identifier))
@@ -2113,7 +2151,8 @@ FROM test_data;
           (case
             (keyword_case)
             (keyword_when)
-            (identifier)
+            (field
+              (identifier))
             (keyword_then)
             (literal)
             (keyword_end))