diff options
author | gentoo90 <gentoo90@gmail.com> | 2013-04-12 23:46:38 +0300 |
---|---|---|
committer | gentoo90 <gentoo90@gmail.com> | 2013-04-12 23:46:38 +0300 |
commit | ed4658e25915e28fa4facd3f68bf60b892d564a8 (patch) | |
tree | 8d359b776d2c384956c274ecc6c895369640c820 | |
parent | ba07267fd7962437c2f0a7dbc66dae1a3a7f2e20 (diff) | |
download | scintilla-mirror-ed4658e25915e28fa4facd3f68bf60b892d564a8.tar.gz |
LexPowerShell fixes and improvements
* fix here-string highlighting
* add doccomment keyword highlighting
* add #region folding
-rw-r--r-- | include/SciLexer.h | 3 | ||||
-rw-r--r-- | include/Scintilla.iface | 3 | ||||
-rw-r--r-- | lexers/LexPowerShell.cxx | 51 |
3 files changed, 55 insertions, 2 deletions
diff --git a/include/SciLexer.h b/include/SciLexer.h index f04222d19..81775d606 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -1326,6 +1326,9 @@ #define SCE_POWERSHELL_FUNCTION 11 #define SCE_POWERSHELL_USER1 12 #define SCE_POWERSHELL_COMMENTSTREAM 13 +#define SCE_POWERSHELL_HERE_STRING 14 +#define SCE_POWERSHELL_HERE_CHARACTER 15 +#define SCE_POWERSHELL_COMMENTDOCKEYWORD 16 #define SCE_MYSQL_DEFAULT 0 #define SCE_MYSQL_COMMENT 1 #define SCE_MYSQL_COMMENTLINE 2 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index c1d6da9e3..364dec91c 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -3923,6 +3923,9 @@ val SCE_POWERSHELL_ALIAS=10 val SCE_POWERSHELL_FUNCTION=11 val SCE_POWERSHELL_USER1=12 val SCE_POWERSHELL_COMMENTSTREAM=13 +val SCE_POWERSHELL_HERE_STRING=14 +val SCE_POWERSHELL_HERE_CHARACTER=15 +val SCE_POWERSHELL_COMMENTDOCKEYWORD=16 # Lexical state for SCLEX_MYSQL lex MySQL=SCLEX_MYSQL SCE_MYSQL_ val SCE_MYSQL_DEFAULT=0 diff --git a/lexers/LexPowerShell.cxx b/lexers/LexPowerShell.cxx index 7f741fc74..1b568c087 100644 --- a/lexers/LexPowerShell.cxx +++ b/lexers/LexPowerShell.cxx @@ -40,6 +40,7 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt WordList &keywords3 = *keywordlists[2]; WordList &keywords4 = *keywordlists[3]; WordList &keywords5 = *keywordlists[4]; + WordList &keywords6 = *keywordlists[5]; styler.StartAt(startPos); @@ -52,9 +53,26 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt sc.SetState(SCE_POWERSHELL_DEFAULT); } } else if (sc.state == SCE_POWERSHELL_COMMENTSTREAM) { + if(sc.atLineStart) { + while(IsASpaceOrTab(sc.ch)) { + sc.Forward(); + } + if (sc.ch == '.' && IsAWordChar(sc.chNext)) { + sc.SetState(SCE_POWERSHELL_COMMENTDOCKEYWORD); + } + } if (sc.ch == '>' && sc.chPrev == '#') { sc.ForwardSetState(SCE_POWERSHELL_DEFAULT); } + } else if (sc.state == SCE_POWERSHELL_COMMENTDOCKEYWORD) { + if(!IsAWordChar(sc.ch)) { + char s[100]; + sc.GetCurrentLowered(s, sizeof(s)); + if (!keywords6.InList(s + 1)) { + sc.ChangeState(SCE_POWERSHELL_COMMENTSTREAM); + } + sc.SetState(SCE_POWERSHELL_COMMENTSTREAM); + } } else if (sc.state == SCE_POWERSHELL_STRING) { // This is a doubles quotes string if (sc.ch == '\"') { @@ -65,6 +83,18 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt if (sc.ch == '\'') { sc.ForwardSetState(SCE_POWERSHELL_DEFAULT); } + } else if (sc.state == SCE_POWERSHELL_HERE_STRING) { + // This is a doubles quotes here-string + if (sc.atLineStart && sc.ch == '\"' && sc.chNext == '@') { + sc.Forward(2); + sc.SetState(SCE_POWERSHELL_DEFAULT); + } + } else if (sc.state == SCE_POWERSHELL_HERE_CHARACTER) { + // This is a single quote here-string + if (sc.atLineStart && sc.ch == '\'' && sc.chNext == '@') { + sc.Forward(2); + sc.SetState(SCE_POWERSHELL_DEFAULT); + } } else if (sc.state == SCE_POWERSHELL_NUMBER) { if (!IsADigit(sc.ch)) { sc.SetState(SCE_POWERSHELL_DEFAULT); @@ -107,6 +137,10 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt sc.SetState(SCE_POWERSHELL_STRING); } else if (sc.ch == '\'') { sc.SetState(SCE_POWERSHELL_CHARACTER); + } else if (sc.ch == '@' && sc.chNext == '\"') { + sc.SetState(SCE_POWERSHELL_HERE_STRING); + } else if (sc.ch == '@' && sc.chNext == '\'') { + sc.SetState(SCE_POWERSHELL_HERE_CHARACTER); } else if (sc.ch == '$') { sc.SetState(SCE_POWERSHELL_VARIABLE); } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { @@ -159,11 +193,23 @@ static void FoldPowerShellDoc(unsigned int startPos, int length, int initStyle, levelNext--; } } else if (foldComment && style == SCE_POWERSHELL_COMMENTSTREAM) { - if (stylePrev != SCE_POWERSHELL_COMMENTSTREAM) { + if (stylePrev != SCE_POWERSHELL_COMMENTSTREAM && stylePrev != SCE_POWERSHELL_COMMENTDOCKEYWORD) { levelNext++; - } else if (styleNext != SCE_POWERSHELL_COMMENTSTREAM) { + } else if (styleNext != SCE_POWERSHELL_COMMENTSTREAM && styleNext != SCE_POWERSHELL_COMMENTDOCKEYWORD) { levelNext--; } + } else if (foldComment && style == SCE_POWERSHELL_COMMENT) { + if (ch == '#') { + unsigned int j = i + 1; + while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) { + j++; + } + if (styler.Match(j, "region")) { + levelNext++; + } else if (styler.Match(j, "endregion")) { + levelNext--; + } + } } if (!IsASpace(ch)) visibleChars++; @@ -194,6 +240,7 @@ static const char * const powershellWordLists[] = { "Aliases", "Functions", "User1", + "DocComment", 0 }; |