diff options
author | Jad Altahan <xviyy@aol.com> | 2019-02-02 09:32:22 +1100 |
---|---|---|
committer | Jad Altahan <xviyy@aol.com> | 2019-02-02 09:32:22 +1100 |
commit | 3b23e66a4f754a935f308a5c41a2f08f2968d5c3 (patch) | |
tree | f688f9b036be84522f7e42877903e3dfc258c973 /lexers/LexNim.cxx | |
parent | e0c07db56fc58abb484479f0fa2d84abfeee82e3 (diff) | |
download | scintilla-mirror-3b23e66a4f754a935f308a5c41a2f08f2968d5c3.tar.gz |
Backport: Feature [feature-requests:#1262]. Enhance raw string identifier styling in Nim
Adds property 'lexer.nim.raw.strings.highlight.ident'.
Backport of changeset 7247:1eeda6575035.
Diffstat (limited to 'lexers/LexNim.cxx')
-rw-r--r-- | lexers/LexNim.cxx | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lexers/LexNim.cxx b/lexers/LexNim.cxx index 8506593f6..78b6cf9e8 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) { |