diff options
| author | Colomban Wendling <ban@herbesfolles.org> | 2013-11-18 17:44:22 +0100 | 
|---|---|---|
| committer | Colomban Wendling <ban@herbesfolles.org> | 2013-11-18 17:44:22 +0100 | 
| commit | 301a3ab4b84a95529db69c1b09f452b04dfb3da9 (patch) | |
| tree | ed455de2bd0e257ec6fd049ec6b5a568a1e00a38 /lexers/LexBash.cxx | |
| parent | c715e9dfc7da16a645ae75b57367155ed56061d5 (diff) | |
| download | scintilla-mirror-301a3ab4b84a95529db69c1b09f452b04dfb3da9.tar.gz | |
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.
Diffstat (limited to 'lexers/LexBash.cxx')
| -rw-r--r-- | lexers/LexBash.cxx | 8 | 
1 files changed, 7 insertions, 1 deletions
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, "^&%()-+=|{}[]:;>,*/<?!.~@");  	CharacterSet setSingleCharOp(CharacterSet::setNone, "rwxoRWXOezsfdlpSbctugkTBMACahGLNn");  	CharacterSet setParam(CharacterSet::setAlphaNum, "$_"); @@ -627,7 +628,12 @@ static void ColouriseBashDoc(unsigned int startPos, int length, int initStyle,  			} else if (setWordStart.Contains(sc.ch)) {  				sc.SetState(SCE_SH_WORD);  			} else if (sc.ch == '#') { -				sc.SetState(SCE_SH_COMMENTLINE); +				if (stylePrev != SCE_SH_WORD && stylePrev != SCE_SH_IDENTIFIER && +					(sc.currentPos == 0 || setMetaCharacter.Contains(sc.chPrev))) { +					sc.SetState(SCE_SH_COMMENTLINE); +				} else { +					sc.SetState(SCE_SH_WORD); +				}  			} else if (sc.ch == '\"') {  				sc.SetState(SCE_SH_STRING);  				QuoteStack.Start(sc.ch, BASH_DELIM_STRING);  | 
