nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
97 stars 24 forks source link

Support the spread operator #98

Open hedyhli opened 3 months ago

hedyhli commented 3 months ago
image

Currently, the ... is parsed as a string, whereas it's a special operator that should be assigned something special, and then highlighted as an operator. If it's parsed as a expr_unary, highlights.scm can then be changed as follows:

diff --git a/queries/nu/highlights.scm b/queries/nu/highlights.scm
index c73f8f3..ce0b839 100644
--- a/queries/nu/highlights.scm
+++ b/queries/nu/highlights.scm
@@ -161,7 +161,7 @@
     "++="
 ] @operator)

-(expr_unary ["not" "-"] @operator)
+(expr_unary ["not" "-" "..."] @operator)

 (val_range [
     ".."
fdncred commented 3 months ago

agreed

mrdgo commented 1 week ago

I'd take a look at this. I also observed a problem with an alias:

image

They all work correctly, even without the quotes, but tree-sitter-nu can't handle them. These two are probably related. If not, I'll create separate PRs