@@ -6,7 +6,7 @@ import parsing.Tokens._
6
6
import scala .annotation .switch
7
7
import scala .collection .mutable .StringBuilder
8
8
import core .Contexts .Context
9
- import util .Chars .{ LF , FF , CR , SU }
9
+ import util .Chars
10
10
import Highlighting .{Highlight , HighlightBuffer }
11
11
12
12
/** This object provides functions for syntax highlighting in the REPL */
@@ -74,7 +74,7 @@ object SyntaxHighlighting {
74
74
newBuf += n
75
75
prev = n
76
76
if (remaining.nonEmpty) takeChar() // drop 1 for appendLiteral
77
- appendLiteral ('"' , next == " \"\"\" " )
77
+ appendString ('"' , next == " \"\"\" " )
78
78
} else {
79
79
if (n.isUpper && keywordStart) {
80
80
appendWhile(n, ! typeEnders.contains(_), typeDef)
@@ -115,9 +115,9 @@ object SyntaxHighlighting {
115
115
case '@' =>
116
116
appendWhile('@' , ! typeEnders.contains(_), annotation)
117
117
case '\" ' =>
118
- appendLiteral ('\" ' , multiline = remaining.take(2 ).mkString == " \"\" " )
118
+ appendString ('\" ' , multiline = remaining.take(2 ).mkString == " \"\" " )
119
119
case '\' ' =>
120
- appendLiteral ('\' ' )
120
+ appendSingleQuote ('\' ' )
121
121
case '`' =>
122
122
appendTo('`' , _ == '`' , none)
123
123
case _ => {
@@ -169,16 +169,15 @@ object SyntaxHighlighting {
169
169
if (curr == '*' ) open += 1
170
170
}
171
171
172
- (curr : @ switch) match {
173
- case LF | FF | CR | SU => newBuf append CommentColor
174
- case _ => ()
172
+ if (Chars .isLineBreakChar(curr)) {
173
+ newBuf append CommentColor
175
174
}
176
175
}
177
176
prev = curr
178
177
newBuf append NoColor
179
178
}
180
179
181
- def appendLiteral (delim : Char , multiline : Boolean = false ) = {
180
+ def appendString (delim : Char , multiline : Boolean = false ) = {
182
181
var curr : Char = 0
183
182
var continue = true
184
183
var closing = 0
@@ -247,15 +246,30 @@ object SyntaxHighlighting {
247
246
closing = 0
248
247
}
249
248
250
- (curr : @ switch) match {
251
- case LF | FF | CR | SU => newBuf append LiteralColor
252
- case _ => ()
249
+ if (Chars .isLineBreakChar(curr)) {
250
+ newBuf append LiteralColor
253
251
}
254
252
}
255
253
newBuf append NoColor
256
254
prev = curr
257
255
}
258
256
257
+ def appendSingleQuote (delim : Char ) = remaining.take(3 ) match {
258
+ case chr #:: '\' ' #:: _ => // single character
259
+ newBuf append LiteralColor
260
+ newBuf appendAll s " ' $chr' "
261
+ newBuf append NoColor
262
+ takeChars(2 )
263
+ prev = '\' '
264
+ case '\\ ' #:: chr #:: '\' ' #:: _ => // escaped character
265
+ newBuf append LiteralColor
266
+ newBuf appendAll s " ' \\ $chr' "
267
+ newBuf append NoColor
268
+ takeChars(3 )
269
+ prev = '\' '
270
+ case _ => appendWhile(delim, ! typeEnders.contains(_), literal)
271
+ }
272
+
259
273
def append (c : Char , shouldHL : String => Boolean , highlight : String => String ) = {
260
274
var curr : Char = 0
261
275
val sb = new StringBuilder (s " $c" )
0 commit comments