gleam-lang / tree-sitter-gleam

🌳 A tree-sitter grammar for the Gleam programming language
Apache License 2.0
78 stars 16 forks source link

Highlight echo #103

Closed giacomocavalieri closed 4 weeks ago

giacomocavalieri commented 1 month ago

This PR adds syntax highlight for the echo keyword. I'm having a problem with a test failing:

syntax highlighting:
  ✗ functions.gleam
    Failure - row: 86, column: 5, expected highlight 'variable', actual highlights: 'function'

I can't really understand why is that, it looks unrelated to the echo addition. By playing around it look like that it's that $.pipeline_echo I've added in the |> operator that's messing things up but I know too little about tree sitter to figure this out on my own

endofunky commented 1 month ago

Specifying a left associativity made the tests pass for me:

diff --git a/grammar.js b/grammar.js
index f5b8e41..3d99544 100644
--- a/grammar.js
+++ b/grammar.js
@@ -21,7 +21,6 @@ module.exports = grammar({
     [$.source_file],
     [$._constant_value, $._case_clause_guard_unit],
     [$.integer],
-    [$.pipeline_echo, $.echo],
     [$.echo],
   ],
   rules: {
@@ -378,7 +377,7 @@ module.exports = grammar({
           )
         )
       ),
-    pipeline_echo: (_$) => " echo",
+    pipeline_echo: (_$) => prec.left("echo"),
     echo: ($) => seq("echo", $._expression),
     tuple: ($) => seq("#", "(", optional(series_of($._expression, ",")), ")"),
     list: ($) =>
giacomocavalieri commented 1 month ago

That works, hero!!

giacomocavalieri commented 4 weeks ago

Done!