Support the spread operator
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 [
".."
agreed
I'd take a look at this. I also observed a problem with an alias:
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
So far, I couldn't get this to work in pure grammar.js. As I understand, the dots must have no whitespace before the list and we would have to detect a correctly delimited list. I fear that we need to implement this in a scanner.c. Except @blindFS can do some magic?
Edit: just as I wrote that down, an idea struck. Will fiddle, might still need someone to discuss a solution.
As soon as a bracket, brace, or paren follows the three dots, nu expects a closing one and tries to spread the resulting value. In theory, this should be doable as a unary operator.
I noticed this issue the other day, my plan is
- create new rules for ...() ...[] ...{} ...$, correct me if something's missing.
- Then add those rules to allowed places, I believe ...{} is only allowed inside record.
We can group ...( for example as single terminal token, so it won't mess other patterns with leading dots like range or decimal.
Maybe I should create a new issue for all the problems that I found so far, so that someone may come and fix it before me.
I'd take a look at this. I also observed a problem with an alias:
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
@mrdgo The alias example still fails after #143, but it's another issue caused by restricted command identifier.
