File tree 4 files changed +34
-2
lines changed
compiler/src/dotty/tools/dotc/parsing
4 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -439,6 +439,7 @@ object JavaScanners {
439
439
}
440
440
oct.asInstanceOf [Char ]
441
441
end octal
442
+ var skip = false
442
443
def greatEscape : Char =
443
444
nextChar()
444
445
if '0' <= ch && ch <= '7' then octal
@@ -455,11 +456,12 @@ object JavaScanners {
455
456
case '\\ ' => '\\ '
456
457
case CR | LF if inTextBlock =>
457
458
if ! scanOnly then nextChar()
459
+ skip = true
458
460
0
459
461
case _ =>
460
462
if ! scanOnly then error(" invalid escape character" , charOffset - 1 )
461
463
ch
462
- if x != 0 then nextChar()
464
+ if ! skip then nextChar()
463
465
x
464
466
end greatEscape
465
467
@@ -470,7 +472,7 @@ object JavaScanners {
470
472
val res = ch
471
473
nextChar()
472
474
res
473
- if c != 0 && ! scanOnly then putChar(c)
475
+ if ! skip && ! scanOnly then putChar(c)
474
476
end getlitch
475
477
476
478
/** Read a triple-quote delimited text block, starting after the first three double quotes.
Original file line number Diff line number Diff line change 64
64
====
65
65
X Y
66
66
====
67
+ 582059
68
+ ====
69
+ 0
70
+ ====
71
+ 2a
72
+ ====
73
+ c3bf
74
+ ====
Original file line number Diff line number Diff line change @@ -30,4 +30,23 @@ object Test extends App {
30
30
println(" ====" )
31
31
println(valueOf[TextBlocks .Octal .type ])
32
32
println(" ====" )
33
+ println(hexdump(valueOf[TextBlocks .Octal .type ]))
34
+ println(" ====" )
35
+ println(hexdump(valueOf[TextBlocks .Zero .type ].toString))
36
+ println(" ====" )
37
+ println(hexdump(valueOf[TextBlocks .Magic .type ].toString))
38
+ println(" ====" )
39
+ println(hexdump(valueOf[TextBlocks .Maxie .type ].toString))
40
+ println(" ====" )
33
41
}
42
+
43
+ val printable = raw " \p{Print} " .r
44
+
45
+ def hexdump (s : String ) = s.getBytes(io.Codec .UTF8 .charSet) // java.nio.charset.StandardCharsets.UTF_8
46
+ .map(b => b.toInt.toHexString.takeRight(2 )).mkString
47
+ /*
48
+ .map(b => b.toChar match {
49
+ case c @ printable() => f"$c%2c"
50
+ case _ => f"$b%02x"
51
+ }).mkString
52
+ */
Original file line number Diff line number Diff line change @@ -81,4 +81,7 @@ class TextBlocks {
81
81
""" ;
82
82
83
83
final static String Octal = "X\040 Y" ;
84
+ final static char Zero = '\0' ;
85
+ final static char Magic = '\52' ;
86
+ final static char Maxie = '\377' ;
84
87
}
You can’t perform that action at this time.
0 commit comments