diff options
| author | Jad Altahan <xviyy@aol.com> | 2019-01-30 11:35:01 +1100 | 
|---|---|---|
| committer | Jad Altahan <xviyy@aol.com> | 2019-01-30 11:35:01 +1100 | 
| commit | 86900d9f6c64e0598e5b217a1d393e55cb53602b (patch) | |
| tree | 8ff373d973fcc7025b02bf24d0aee94aa387cac0 | |
| parent | 850cfb235e8e92c5b180c94f81d599f88e8cef01 (diff) | |
| download | scintilla-mirror-86900d9f6c64e0598e5b217a1d393e55cb53602b.tar.gz | |
Feature [feature-requests:#1261]. Enhance the styling of backticks in Nim
| -rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
| -rw-r--r-- | lexers/LexNim.cxx | 23 | ||||
| -rw-r--r-- | test/examples/x.nim | 6 | ||||
| -rw-r--r-- | test/examples/x.nim.styled | 6 | ||||
| -rw-r--r-- | test/lexTests.py | 2 | 
5 files changed, 36 insertions, 5 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 419dcb5c6..11b388ce6 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -577,6 +577,10 @@  	<a href="https://sourceforge.net/p/scintilla/feature-requests/1260/">Feature #1260</a>.  	</li>   	<li> +	Enhance the styling of backticks in Nim. +	<a href="https://sourceforge.net/p/scintilla/feature-requests/1261/">Feature #1261</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 228666b32..fec9159ef 100644 --- a/lexers/LexNim.cxx +++ b/lexers/LexNim.cxx @@ -454,6 +454,18 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,                      sc.ForwardSetState(SCE_NIM_DEFAULT);                  }                  break; +            case SCE_NIM_FUNCNAME: +                if (sc.ch == '`') { +                    funcNameExists = false; +                    sc.ForwardSetState(SCE_NIM_DEFAULT); +                } else if (sc.atLineEnd) { +                    // Prevent leaking the style to the next line if not closed +                    funcNameExists = false; + +                    sc.ChangeState(SCE_NIM_STRINGEOL); +                    sc.ForwardSetState(SCE_NIM_DEFAULT); +                } +                break;              case SCE_NIM_COMMENT:                  if (sc.Match(']', '#')) {                      if (commentNestLevel > 0) { @@ -527,7 +539,10 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,                  }                  break;              case SCE_NIM_BACKTICKS: -                if (sc.ch == '`' || sc.atLineEnd) { +                if (sc.ch == '`' ) { +                    sc.ForwardSetState(SCE_NIM_DEFAULT); +                } else if (sc.atLineEnd) { +                    sc.ChangeState(SCE_NIM_STRINGEOL);                      sc.ForwardSetState(SCE_NIM_DEFAULT);                  }                  break; @@ -631,10 +646,10 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,              }              // Operator definition              else if (sc.ch == '`') { -                sc.SetState(SCE_NIM_BACKTICKS); -                  if (funcNameExists) { -                    funcNameExists = false; +                    sc.SetState(SCE_NIM_FUNCNAME); +                } else { +                    sc.SetState(SCE_NIM_BACKTICKS);                  }              }              // Keyword diff --git a/test/examples/x.nim b/test/examples/x.nim index 07c9d216f..4bf0de737 100644 --- a/test/examples/x.nim +++ b/test/examples/x.nim @@ -4,3 +4,9 @@ let s = "foobar"  # Feature #1260  {.ident.}  stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!") + +# Feature #1261 +# IsFuncName("proc") so style ticks as SCE_NIM_FUNCNAME: +proc `$` (x: myDataType): string = ... +# Style ticks as SCE_NIM_BACKTICKS: +if `==`( `+`(3,4),7): echo "True" diff --git a/test/examples/x.nim.styled b/test/examples/x.nim.styled index fc1532e60..18ae529e6 100644 --- a/test/examples/x.nim.styled +++ b/test/examples/x.nim.styled @@ -4,3 +4,9 @@  {3}# Feature #1260  {15}{.{16}ident{15}.}{0}  {16}stdin{15}.{16}readLine{15}.{16}split{15}.{16}map{15}({16}parseInt{15}).{16}max{15}.{11}`$`{15}.{16}echo{15}({6}" is the maximum!"{15}){0} + +{3}# Feature #1261 +# IsFuncName("proc") so style ticks as SCE_NIM_FUNCNAME: +{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} diff --git a/test/lexTests.py b/test/lexTests.py index eb38b7af7..46e4eb4fb 100644 --- a/test/lexTests.py +++ b/test/lexTests.py @@ -157,7 +157,7 @@ class TestLexers(unittest.TestCase):  		self.LexExample("x.lua", b"lua", [b"function end"])  	def testNim(self): -		self.LexExample("x.nim", b"nim", [b"else end if let"]) +		self.LexExample("x.nim", b"nim", [b"else end if let proc"])  	def testRuby(self):  		self.LexExample("x.rb", b"ruby", [b"class def end"])  | 
