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

Issue:
feat: json traversal
this needs more time than I have for it at the moment but I don't think it'll be too hard to get basic support for #166! element indexing (possibly some common ground with the `array[1,2,3]` syntax?) and jsonpath are bigger considerations though.


Discussion / hints:
I added the other json operators and updated the test. Actually it looks like this is it. All other json operations are probably handled by `invocation`
Drive-by appreciation comment:

I am honestly amazed by your aptitude and the promptness at fixing the issues I've reported. Stellar project maintenance! I certainly wasn't expecting to see all 3 issues addressed the same day I reported them
> Drive-by appreciation comment:
>
> I am honestly amazed by your aptitude and the promptness at fixing the issues I've reported. Stellar project maintenance! I certainly wasn't expecting to see all 3 issues addressed the same day I reported them

the JSON issue has secretly been bugging me for a while (along with array literals and subscripting, but that's for later) and I've always been too busy with other things & other projects to take a look, and it turns out it just fits right into the `expression` node now

Fix patch:
diff --git a/grammar.js b/grammar.js
index 67ff92e8..1204acd4 100644
--- a/grammar.js
+++ b/grammar.js
@@ -2318,22 +2318,10 @@ module.exports = grammar({
         $.array,
         $.interval,
         $.between_expression,
-        $.json_traversal,
         seq("(", $._expression, ")"),
       )
     ),
 
-    json_traversal: $ => seq(
-      $._expression,
-      choice(
-        '->',
-        '->>',
-        '#>',
-        '#>>',
-      ),
-      $._literal_string,
-    ),
-
     binary_expression: $ => choice(
       ...[
         ['+', 'binary_plus'],
@@ -2350,6 +2338,10 @@ module.exports = grammar({
         ['>=', 'binary_relation'],
         ['>', 'binary_relation'],
         ['<>', 'binary_relation'],
+        ['->', 'binary_relation'],
+        ['->>', 'binary_relation'],
+        ['#>', 'binary_relation'],
+        ['#>>', 'binary_relation'],
         [$.keyword_is, 'binary_is'],
         [$.is_not, 'binary_is'],
         [$.keyword_like, 'pattern_matching'],


Test patch:
diff --git a/test/corpus/json.txt b/test/corpus/json.txt
index 3d817f5a..522b2cf7 100644
--- a/test/corpus/json.txt
+++ b/test/corpus/json.txt
@@ -13,35 +13,42 @@ FROM users;
 --------------------------------------------------------------------------------
 
 (program
- (statement
-  (select
-   (keyword_select)
-   (select_expression
-    (term
-     (json_traversal
-      (literal))
-     (keyword_as)
-     (identifier))
-    (term
-     (json_traversal
-      (json_traversal
-       (literal))))
-    (term
-     (json_traversal
-      (json_traversal
-       (literal)))
-     (keyword_as)
-     (identifier))
-    (term
-     (json_traversal
-      (literal)))
-    (term
-     (json_traversal
-      (literal))
-      (keyword_as)
-      (identifier))))
+  (statement
+    (select
+      (keyword_select)
+      (select_expression
+        (term
+          value: (binary_expression
+            left: (literal)
+            right: (literal))
+          (keyword_as)
+          alias: (identifier))
+        (term
+          value: (binary_expression
+            left: (binary_expression
+              left: (literal)
+              right: (literal))
+            right: (literal)))
+        (term
+          value: (binary_expression
+            left: (binary_expression
+              left: (literal)
+              right: (literal))
+            right: (literal))
+          (keyword_as)
+          alias: (identifier))
+        (term
+          value: (binary_expression
+            left: (literal)
+            right: (literal)))
+        (term
+          value: (binary_expression
+            left: (literal)
+            right: (literal))
+          (keyword_as)
+          alias: (identifier))))
     (from
-     (keyword_from)
-     (relation
-      (object_reference
-       (identifier))))))
+      (keyword_from)
+      (relation
+        (object_reference
+          name: (identifier))))))