Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substantially reduce wrongly highlighted stuff for Bash #793

Merged
merged 3 commits into from
Oct 6, 2015

Conversation

zeitgeist87
Copy link
Collaborator

This patch set contains not only two new features for Bash (namely arithmetic environments and command substitutions), but it uses these features to fix a lot of the annoying stuff about Bash highlighting.

The following simple example should illustrate what I mean:

bash

Here 104 is highlighted as a number, - as an operator, file as a function and . as punctuation. All of these things are wrong, because Bash interprets this as the string "104-file.txt".

In Bash numbers and arithmetic operations can only exist in arithmetic environments and everything outside of an arithmetic environment is interpreted as a string:

$((5 + 6))

Also keywords and functions can only have certain characters surrounding them namely /(^|\s|;|\||&)/. In any other context it is just a string.

This patch set fixes all of the above and adds support for command substitution. I also added tests for all of the new features.

The result looks like this:

bash2

Keywords and functions should not start with a boundary character,
because this leads to lots of false matches. Bash actually only
allows a few boundary characters for commands and functions. This
patch replaces the \b with an explicit list of allowed characters.
This improves the highlighting of pathnames enourmously.

Some examples of invalid highlighting this patch fixes:

cat /etc/passwd
cat ./if/else/something-file.txt

This patch also adds the built-in commands ":" and ".".

: NOOP-command
. Source command
Currently arithmetic operators are wrongly matched all over the
place. For example the dash in `ls -la` is highlighted as
a minus operator, but for Bash it is only a string. Another
example would be a simple path like this `cat 801-file.txt`. Here
`801` is wrongly highlighted as a number and `-` is highlighted as
an operator.

Bash only supports numbers and arithmetic operators inside of a so called
arithemtic environment `$((3 + 4))`. By supporting this and
limiting numbers and arithmetic operators to arithemtic
environments, a lot of wrongly highlighted stuff can be avoided.
Command substitution is a very important part of the Bash
language. Every non trivial script uses it in one way or another.
This patch adds support for it.
Golmote added a commit that referenced this pull request Oct 6, 2015
Substantially reduce wrongly highlighted stuff for Bash
@Golmote Golmote merged commit ac6fe2e into PrismJS:gh-pages Oct 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants