jskinner / DefaultPackages

Old bug tracker for Sublime Text's "Default Packages", e.g. bad syntax highlighting
http://web.archive.org/web/20150524043750/https://www.sublimetext.com/forum/viewtopic.php?f=2&t=12095
26 stars 2 forks source link

Many issues with bash / shell script highlighting #125

Closed okdana closed 6 years ago

okdana commented 9 years ago

I'm not sure if it would be better to break these up into separate issues, but i wanted to err on the side of not spamming. Sorry if this is too general.

The Shell Script (Bash) highlighter is super super limited and in many cases broken entirely. In particular:

Braces in parameter expansion/interpolation are handled naïvely; any closing brace following the first opening brace (regardless of context) can prematurely close the expanded parameter, potentially breaking the rest of the file.

screen shot 2015-04-30 at 02 23 22 screen shot 2015-04-30 at 02 19 36

Similarly, parameter-expansion operators are handled naïvely — basically if any character used as an operator appears anywhere on the line after the variable name, regardless of context, it's highlighted as an operator. This includes operators that can only appear at the beginning of the expansion, like !.

screen shot 2015-04-30 at 02 31 40 screen shot 2015-04-30 at 02 36 37

The 'body' of a parameter expansion (the part after the operator) doesn't 'include' (in the sense of the tmLanguage file) other scopes.

screen shot 2015-04-30 at 03 17 41

^ and , (upper-case and lower-case, respectively) aren't recognised as parameter expansion operators.

screen shot 2015-04-30 at 02 28 36

Variable declarations (arguments to export, declare, typeset, local, readonly) and un-declarations (unset) are not highlighted.

screen shot 2015-04-30 at 02 43 46

Variable assignments are not highlighted (interpolated variables and variables like for i in ... are).

screen shot 2015-04-30 at 02 41 22

Arithmetic constructs are highlighted as a literal strings, except when they appear in double-quotes (or in a for loop). Edit: Looks like the theme probably just needs rules to make it not like this. I sort of question the scoping of these constructs as 'strings' though, especially the (( ... )) one.

screen shot 2015-04-30 at 03 03 26

Command-substitution constructs are highlighted inconsistently. Dollar substitution ($( ... )) is highlighted correctly, but the body of a back-tick substitution is highlighted as a literal string. Edit: This may be a function of the theme i was using, sorry. See also edit above.

screen shot 2015-04-30 at 03 05 47

Process-substitution constructs are not highlighted correctly (similar to back-ticks). Edit: Probably theme-related, see also edits above.

screen shot 2015-04-30 at 03 23 58

Nested interpolations aren't highlighted correctly.

screen shot 2015-04-30 at 03 40 37

The <<- operator (heredoc ignoring leading tabs) is not highlighted correctly.

screen shot 2015-04-30 at 03 21 42

Heredoc bodies aren't highlighted as strings (as they are for other languages).

Related to the above, the highlighting doesn't understand the effect of single quotes on a heredoc delimiter.

screen shot 2015-04-30 at 03 35 45

Literal patterns following a regular-expression operator are not highlighted correctly (should be string or dedicated regular-expression scope).

screen shot 2015-04-30 at 03 27 40

Operators in single brackets aren't highlighted correctly.

screen shot 2015-04-30 at 03 38 46

The in control key word (in case ... in) isn't highlighted correctly.

screen shot 2015-04-30 at 02 45 18

The break control key word isn't highlighted correctly.

screen shot 2015-04-30 at 03 44 32

Semi-colons aren't recognised as operators in for-loop arithmetic constructs.

screen shot 2015-04-30 at 03 47 09

The appearance of a control key word in a substitution construct will break the construct and potentially all following text.

screen shot 2015-04-30 at 03 59 03

I suppose shell scripts are not very sexy but it seemed useful to at least document these somewhere. Also, i'm sorry if any of these are theme-specific; i tried to rule those out but i may have got distracted trying to write the examples.

FichteFoll commented 9 years ago

Thanks for the very detailed report. I suspect the bash syntax will be rewritten anyway shortly, following http://www.sublimetext.com/forum/viewtopic.php?f=2&t=17892, so this will surely be of use.

okdana commented 9 years ago

Oh, yeah, i did hear something about that. Thanks for responding!

leesei commented 9 years ago

@okdana can you post the file you used to validate the syntax?

leesei commented 9 years ago

I discovered an issue with heredoc:

cat <<EOF
works fine without space
EOF

cat << EOF
with space it is not ok
EOF

(I noticed Github have the same issue after posting.)

BTW, when looking the syntax file, I see that many other syntax (like HTML and MARKDOWN) can be highlighted within the content of heredoc. How to trigger them?

okdana commented 9 years ago

I don't have any 'real-world' files i'm comfortable sharing (all stuff from my job), but here's a test file i put together quickly:

https://gist.githubusercontent.com/okdana/45d3fd437e2f97f2ac63/raw/a822842edf8acdb7af4d182bbe18545f36d4c7be/bashsyntax.sh

leesei commented 9 years ago

Thanks a lot. I think the file will help improve any Bash syntax highlighter.

Would you also add the Heredoc white space issue I posted to your Gist? (Gist has no PR :grimacing:)

okdana commented 9 years ago

Updated, sorry. That actually explains why i was seeing some of the behaviour i was, i didn't notice before.

I also noticed that the syntax thing does recognise the <<- operator (Ctrl+Shift+P reports string.unquoted.heredoc.no-indent) when it's not followed by white-space, though it still highlights the - incorrectly.

jfcherng commented 9 years ago

I am just trying to fix this issue. PR: https://github.com/sublimehq/Packages/pull/47

okdana commented 9 years ago

That looks awesome, thank you! I will definitely try it out as soon as i'm able.

keith-hall commented 7 years ago

note this repo has been deprecated in favor of https://github.com/sublimehq/Packages/issues/434

FichteFoll commented 6 years ago

The syntax definition has been rewritten via https://github.com/sublimehq/Packages/pull/1057. I imagine that most, if not all, of this has been fixed. I tested a few test cases manually but am too lazy to type out all of them (since they weren't provided as verbatim text).

If you find any remaining issues with the current bash/shell script highlighting, please open a separate issue on https://github.com/sublimehq/Packages (after confirming it doesn't exist already).