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

Highlight echo #103

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Highlight echo #103

merged 3 commits into from
Oct 30, 2024

Conversation

giacomocavalieri
Copy link
Member

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
Copy link

endofunky commented Oct 28, 2024

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: ($) =>

Thank you so much to @endofunky!!

Co-authored-by: @endofunky
@giacomocavalieri
Copy link
Member Author

That works, hero!!

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

This looks good from what I know about tree-sitter, thanks both!

Can we have tests that shows the precedence of echo is correct? Echoing binary operators and pipelines, for example 🙏

@giacomocavalieri
Copy link
Member Author

Done!

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!!

@lpil lpil merged commit 1759008 into gleam-lang:main Oct 30, 2024
3 checks passed
@giacomocavalieri giacomocavalieri deleted the echo branch October 30, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants