diff options
| -rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
| -rw-r--r-- | lexers/LexNim.cxx | 26 | ||||
| -rw-r--r-- | test/examples/x.nim | 8 | ||||
| -rw-r--r-- | test/examples/x.nim.styled | 8 | 
4 files changed, 45 insertions, 1 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 11b388ce6..579ce0f37 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -581,6 +581,10 @@  	<a href="https://sourceforge.net/p/scintilla/feature-requests/1261/">Feature #1261</a>.  	</li>   	<li> +	Enhance raw string identifier styling in Nim. +	<a href="https://sourceforge.net/p/scintilla/feature-requests/1262/">Feature #1262</a>. +	</li> + 	<li>  	Fix fold behaviour with comments in nim.  	<a href="https://sourceforge.net/p/scintilla/feature-requests/1254/">Feature #1254</a>.  	</li> diff --git a/lexers/LexNim.cxx b/lexers/LexNim.cxx index fec9159ef..92e1560a9 100644 --- a/lexers/LexNim.cxx +++ b/lexers/LexNim.cxx @@ -55,6 +55,11 @@ int GetNumStyle(const int numType) {      return SCE_NIM_NUMBER;  } +bool IsLetter(const int ch) { +    // 97 to 122 || 65 to 90 +    return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); +} +  bool IsAWordChar(const int ch) {      return ch < 0x80 && (isalnum(ch) || ch == '_' || ch == '.');  } @@ -163,10 +168,12 @@ int IndentAmount(const Sci_Position line, Accessor &styler) {  struct OptionsNim {      bool fold;      bool foldCompact; +    bool highlightRawStrIdent;      OptionsNim() {          fold = true;          foldCompact = true; +        highlightRawStrIdent = false;      }  }; @@ -177,6 +184,10 @@ static const char *const nimWordListDesc[] = {  struct OptionSetNim : public OptionSet<OptionsNim> {      OptionSetNim() { +        DefineProperty("lexer.nim.raw.strings.highlight.ident", &OptionsNim::highlightRawStrIdent, +            "Set to 1 to enable highlighting generalized raw string identifiers. " +            "Generalized raw string identifiers are anything other than r (or R)."); +          DefineProperty("fold", &OptionsNim::fold);          DefineProperty("fold.compact", &OptionsNim::foldCompact); @@ -451,6 +462,16 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,                  if (IsAlphaNumeric(sc.ch) && sc.chNext == '\"') {                      isStylingRawStringIdent = true; + +                    if (options.highlightRawStrIdent) { +                        if (styler.SafeGetCharAt(sc.currentPos + 2) == '\"' && +                            styler.SafeGetCharAt(sc.currentPos + 3) == '\"') { +                            sc.ChangeState(SCE_NIM_TRIPLEDOUBLE); +                        } else { +                            sc.ChangeState(SCE_NIM_STRING); +                        } +                    } +                      sc.ForwardSetState(SCE_NIM_DEFAULT);                  }                  break; @@ -603,7 +624,10 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,                      sc.SetState(SCE_NIM_STRING);                  } -                if (sc.ch == 'r' || sc.ch == 'R') { +                int rawStrStyle = options.highlightRawStrIdent ? IsLetter(sc.ch) : +                                  (sc.ch == 'r' || sc.ch == 'R'); + +                if (rawStrStyle) {                      sc.Forward();                      if (sc.state == SCE_NIM_TRIPLEDOUBLE) { diff --git a/test/examples/x.nim b/test/examples/x.nim index 4bf0de737..ac8a274f4 100644 --- a/test/examples/x.nim +++ b/test/examples/x.nim @@ -10,3 +10,11 @@ stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!")  proc `$` (x: myDataType): string = ...  # Style ticks as SCE_NIM_BACKTICKS:  if `==`( `+`(3,4),7): echo "True" + +# Feature #1262 +# Standard raw string identifier: +let standardDoubleLitRawStr = R"A raw string\" +let standardTripleLitRawStr = R"""A triple-double raw string\"""" +# Style of 'customIdent' is determined by lexer.nim.raw.strings.highlight.ident. 16 if false, 6 or 10 if true +let customDoubleLitRawStr = customIdent"A string\" +let customTripleLitRawStr = customIdent"""A triple-double raw string\"""" diff --git a/test/examples/x.nim.styled b/test/examples/x.nim.styled index 18ae529e6..2753d005e 100644 --- a/test/examples/x.nim.styled +++ b/test/examples/x.nim.styled @@ -10,3 +10,11 @@  {8}proc{0} {12}`$`{0} {15}({16}x{15}:{0} {16}myDataType{15}):{0} {16}string{0} {15}={0} {15}...{0}  {3}# Style ticks as SCE_NIM_BACKTICKS:  {8}if{0} {11}`==`{15}({0} {11}`+`{15}({5}3{15},{5}4{15}),{5}7{15}):{0} {16}echo{0} {6}"True"{0} + +{3}# Feature #1262 +# Standard raw string identifier: +{8}let{0} {16}standardDoubleLitRawStr{0} {15}={0} {6}R"A raw string\"{0} +{8}let{0} {16}standardTripleLitRawStr{0} {15}={0} {10}R"""A triple-double raw string\""""{0} +{3}# Style of 'customIdent' is determined by lexer.nim.raw.strings.highlight.ident. 16 if false, 6 or 10 if true +{8}let{0} {16}customDoubleLitRawStr{0} {15}={0} {16}customIdent{6}"A string\"{0} +{8}let{0} {16}customTripleLitRawStr{0} {15}={0} {16}customIdent{10}"""A triple-double raw string\""""{0} | 
