From 301a3ab4b84a95529db69c1b09f452b04dfb3da9 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Mon, 18 Nov 2013 17:44:22 +0100 Subject: Bash: fix comment detection inside a word A comment in bash is defined as "[...] a word beginning with # causes that word and all remaining characters on that line to be ignored". A word is defined as "a sequence of characters considered as a single unit by the shell"; and there is a set of metacharacters defined as "a character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab". In practice, "foo#bar" is one single word, not "foo" followed by a comment. Trickier, "foo\;#bar" is also a single word, but "foo;bar" are 2 words and a control character. So, fix the Bash lexer to check whether the character preceding the hash sign to be either a metacharacter or part of a word. A maybe better fix would be to understand the Bash conception of a word, and analyze those, but it would require a large rewrite. --- lexers/LexBash.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lexers/LexBash.cxx b/lexers/LexBash.cxx index 5f582e401..513a5dff8 100644 --- a/lexers/LexBash.cxx +++ b/lexers/LexBash.cxx @@ -108,6 +108,7 @@ static void ColouriseBashDoc(unsigned int startPos, int length, int initStyle, CharacterSet setWordStart(CharacterSet::setAlpha, "_"); // note that [+-] are often parts of identifiers in shell scripts CharacterSet setWord(CharacterSet::setAlphaNum, "._+-"); + CharacterSet setMetaCharacter(CharacterSet::setNone, "|&;()<> \t\r\n"); CharacterSet setBashOperator(CharacterSet::setNone, "^&%()-+=|{}[]:;>,*/