From 63a33763ccd8e772ecb4b1714748ab2a8deeb9d5 Mon Sep 17 00:00:00 2001 From: Kein-Hong Man Date: Sun, 20 Dec 2015 13:45:58 +1100 Subject: Bug [#1794]. Support using '#' in non-comment ways as is possible with zsh. --- doc/ScintillaHistory.html | 12 +++++++----- lexers/LexBash.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 6a6ab5ec5..e03a8b344 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -513,16 +513,14 @@
  • Bash lexer flags incomplete here doc delimiters as syntax errors. - Bug #1789. + Bug #1789.
    + Support added for using '#' in non-comment ways as is possible with zsh. + Bug #1794.
  • Errorlist lexer highlights warning messages from the Microsoft linker.
  • - On Windows, Scintilla no longer uses a .DEF file during linking as it duplicates - source code directives. -
  • -
  • Lua lexer includes '&' and '|' bitwise operators for Lua 5.3. Bug #1790.
  • @@ -558,6 +556,10 @@ to the end of the cluster making it easier to understand editing actions.
  • + On Windows, Scintilla no longer uses a .DEF file during linking as it duplicates + source code directives. +
  • +
  • On GTK+ and Qt, Korean input by word fixed.
  • diff --git a/lexers/LexBash.cxx b/lexers/LexBash.cxx index f9d4d2a25..09dd29650 100644 --- a/lexers/LexBash.cxx +++ b/lexers/LexBash.cxx @@ -96,6 +96,19 @@ static int opposite(int ch) { return ch; } +static int GlobScan(StyleContext &sc) { + // forward scan for a glob-like (...), no whitespace allowed + int c, sLen = 0; + while ((c = sc.GetRelativeCharacter(++sLen)) != 0) { + if (IsASpace(c)) { + return 0; + } else if (c == ')') { + return sLen; + } + } + return 0; +} + static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], Accessor &styler) { @@ -337,6 +350,8 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in sc.ForwardSetState(SCE_SH_DEFAULT); } else if (!setWord.Contains(sc.ch)) { sc.SetState(SCE_SH_DEFAULT); + } else if (cmdState == BASH_CMD_ARITH && !setWordStart.Contains(sc.ch)) { + sc.SetState(SCE_SH_DEFAULT); } break; case SCE_SH_NUMBER: @@ -628,6 +643,24 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in } else { sc.SetState(SCE_SH_WORD); } + // handle some zsh features within arithmetic expressions only + if (cmdState == BASH_CMD_ARITH) { + if (sc.chPrev == '[') { // [#8] [##8] output digit setting + sc.SetState(SCE_SH_WORD); + if (sc.chNext == '#') { + sc.Forward(); + } + } else if (sc.chNext == '#' && !IsASpace(sc.GetRelative(2))) { // ##a + sc.SetState(SCE_SH_IDENTIFIER); + sc.Forward(2); + } else if (sc.Match("##^") && IsUpperCase(sc.GetRelative(3))) { // ##^A + sc.SetState(SCE_SH_IDENTIFIER); + sc.Forward(3); + continue; + } else if (setWordStart.Contains(sc.chNext)) { + sc.SetState(SCE_SH_IDENTIFIER); + } + } } else if (sc.ch == '\"') { sc.SetState(SCE_SH_STRING); QuoteStack.Start(sc.ch, BASH_DELIM_STRING); @@ -681,6 +714,15 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in char s[10]; bool isCmdDelim = false; sc.SetState(SCE_SH_OPERATOR); + // globs have no whitespace, do not appear in arithmetic expressions + if (cmdState != BASH_CMD_ARITH && sc.ch == '(' && sc.chNext != '(') { + int i = GlobScan(sc); + if (i > 1) { + sc.SetState(SCE_SH_IDENTIFIER); + sc.Forward(i); + continue; + } + } // handle opening delimiters for test/arithmetic expressions - ((,[[,[ if (cmdState == BASH_CMD_START || cmdState == BASH_CMD_BODY) { -- cgit v1.2.3