sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 587 forks source link

[ShellScript] Add ZSH #4024

Open deathaxe opened 1 month ago

deathaxe commented 1 month ago

Fixes #1358 Fixes #2635 Resolves #3826 Fixes #4033

This PR refactors Bash as foundation for adding Zsh.

Used syntax specifications:

Syntax follows officiel specifications as close as possible to reliably support most language features.

Bash highlights

Various scopes of keywords, punctuation, etc. have been modified to follow latest scope naming best practices.

Those may cause syntax tests of 3rd-party packages to fail. Syntax highlighting itself should however still work.

Zsh highlights

Benchmarks

Parsing performance is evaluated using syntax test files from current release and various other real world scripts.

This PR does not affect parsing performance.

michaelblyons commented 1 month ago

Oof. Can't with_prototype Shellscript anymore. It hits the sanity limit. I'm gonna have to make some edits to some things.

I'll report back on usage after a bit. First impression: lots of things are strings now.

deathaxe commented 1 month ago

This may be caused by various embed's being used to support shell highlighting in quoted strings, which are expanded to push...with_prototype, if ShellScript itself is used like this.

Well, Makefile, MArkdown and YamlPipelines successfully make use of extended ShellScript with little effort to inject own rules.

push...with_prototype is very likely to create undesirable results with most of current ST syntaxes anyway, due to the many special purpose context switches, they require to implement a language.

michaelblyons commented 1 month ago

Initial impression is good. I think I'm over the shock of so many things being "string" scoped now. There are a couple odd things I've found so far, but most of them are not really decidable. (Is for example awk -F' c-? ' a long option value, or an option with a string value?)

Is it worth making a special match for /dev/null? Is it possible to identify the variable being assigned to in mapfile so that it is a variable, not a string?

deathaxe commented 1 month ago

(Is for example awk -F' c-? ' a long option value, ...

Speaking for the shell, yes. Words are separated by space, parens and pipe operators, only. Thus -f' c-? ' is a single word.

It doesn't say anything about how the command awk interprets the words passed to it as arguments.

Quoting is however important for the shell with regards to character escaping, pattern matching or expansions being applied or not.

Is it worth making a special match for /dev/null?

Possibly. Maybe devices in general (/dev/...)?

Is it possible to identify the variable being assigned to in mapfile so that it is a variable, not a string?

Yes, sure. That's what the syntax does for declare, local, ... already to correctly scope indexed and associated arrays' values.

In general I am still thinking about how to scope l-values in assignments, so we can add them to symbol list or enable goto definition for them.

michaelblyons commented 1 month ago

In a case statement, if there is white space between the patter and the ), is that white space part of string.unquoted or should it be unscoped?

For the most part, I have been extremely pleased with the Bash syntax. I don't use ZSH, so someone else will have to look at that.

deathaxe commented 1 month ago

Case patterns actually are pattern lists, rather than a single pattern with alternation. It means each word is a single pattern pat1 | pat2 | pat3 ). As such whitespace doesn't belong to them and shoudln't receive string scope. Also | is not part of those patterns. It's rather a sequence separator or logical operator.

michaelblyons commented 4 weeks ago

@okdana @Antibioticss Test drive the ZSH, maybe?