Phidica / sublime-fish

A robust Sublime Text syntax package for fish
MIT License
35 stars 2 forks source link

Sporadic integer highlighting #7

Closed rwols closed 6 years ago

rwols commented 6 years ago
complete -c node -l  es52_globals -d 'activate new semantics for global var declarations. type: bool default: false'
#                       ^ should this be a constant.numeric?
Phidica commented 6 years ago

At present the behaviour is as intended. I believe the constant.numeric scope should be applied to standalone integers and floats only, and not to numbers that appear embedded within alphanumeric strings. If the digits would be interpreted as an integer or float by a command parsing them, then that is when I think they should be highlighted uniquely. Essentially I am applying a distinction similar to a language like Python or C++ (which rigorously defines int, float, string, etc), which I am aware becomes somewhat arbitrary in a shell environment but I would like to try and stick to anyway

rwols commented 6 years ago

I thought everything in fish is a string, and every variable is a list of strings? For context, I found this peculiarity in this file.

Phidica commented 6 years ago

In my opinion, the highlighting in this file is perfectly correct, including for the lines where numbers are present in the strings. Would it not appear strange if the 8 in "v8-options" was a different colour? Why should it be? Treating the numbers no different from letters looks better in this file, where each completion is using similar sorts of strings and some just happen to contain numbers because they are allowed to be alphanumeric

Ultimately, since the fish parser itself doesn't distinguish between numbers and letters under any circumstances, there is no satisfactory answer as to how this syntax (which strives to emulate the fish parser) should behave when it encounters numerals. I see three possible approaches:

  1. Never scope numerals differently (ie, fully in alignment with how fish treats them)
  2. Always scope numerals differently, no matter where they appear
  3. Scope numerals differently only when they are the entire argument

Obviously the option truest to fish would be the first, but I felt that we could at least try to provide some additional information over fish in places where the user might expect it (for instance, in calls to math). Thus I prefer the third option, which shows benefits in cases like:

math var1 = 3 \% 2 \; var1
#!   ^^^^ meta.string.unquoted
#!          ^ constant.numeric
#!               ^ constant.numeric
#!                    ^^^^ meta.string.unquoted

I believe that it would be unhelpful and less instructive to scope the "1" in "var1" as a numeric in cases such as this

rwols commented 6 years ago

Yes, I completely agree that (3) would be most helpful.

rwols commented 6 years ago

It seems you already fixed this, pulling from latest master solved this for me.

Phidica commented 6 years ago

Ahh I see. I misunderstood your original question as asking for that scope to be applied, not as wondering why it was (in an older version). Well, I'm glad we are in agreement about the optimum behaviour :)