Skip to content

Commit f010c62

Browse files
committed
Revert Scanners and Tokens to their original form
Since we decided to go with the non dotty-scanner approach these are unnecessary to have altered, might just as well revert them.
1 parent b5d6df2 commit f010c62

File tree

5 files changed

+14
-81
lines changed

5 files changed

+14
-81
lines changed

src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ object Scanners {
4545
/** the string value of a literal */
4646
var strVal: String = null
4747

48-
/** the started parsing of a literal */
49-
var startedLiteral: String = null
50-
5148
/** the base of a number */
5249
var base: Int = 0
5350

@@ -177,13 +174,8 @@ object Scanners {
177174

178175
}
179176

180-
class Scanner(
181-
source: SourceFile,
182-
override val startFrom: Offset = 0,
183-
preserveWhitespace: Boolean = false
184-
)(implicit ctx: Context) extends ScannerCommon(source)(ctx) {
185-
val keepComments = ctx.settings.YkeepComments.value
186-
val whitespace = new StringBuilder
177+
class Scanner(source: SourceFile, override val startFrom: Offset = 0)(implicit ctx: Context) extends ScannerCommon(source)(ctx) {
178+
val keepComments = ctx.settings.YkeepComments.value
187179

188180
/** All doc comments as encountered, each list contains doc comments from
189181
* the same block level. Starting with the deepest level and going upward
@@ -247,13 +239,13 @@ object Scanners {
247239

248240
/** Are we directly in a string interpolation expression?
249241
*/
250-
def inStringInterpolation =
242+
private def inStringInterpolation =
251243
sepRegions.nonEmpty && sepRegions.head == STRINGLIT
252244

253245
/** Are we directly in a multiline string interpolation expression?
254246
* @pre inStringInterpolation
255247
*/
256-
def inMultiLineInterpolation =
248+
private def inMultiLineInterpolation =
257249
inStringInterpolation && sepRegions.tail.nonEmpty && sepRegions.tail.head == STRINGPART
258250

259251
/** read next token and return last offset
@@ -324,7 +316,7 @@ object Scanners {
324316
token = if (pastBlankLine()) NEWLINES else NEWLINE
325317
}
326318

327-
if (!preserveWhitespace) postProcessToken()
319+
postProcessToken()
328320
// print("[" + this +"]")
329321
}
330322

@@ -383,20 +375,9 @@ object Scanners {
383375
offset = charOffset - 1
384376
(ch: @switch) match {
385377
case ' ' | '\t' | CR | LF | FF =>
386-
if (preserveWhitespace) {
387-
while ((' ' :: '\t' :: CR :: LF :: FF :: Nil) contains ch) {
388-
whitespace += ch
389-
nextChar()
390-
}
391-
token = WHITESPACE
392-
strVal = whitespace.toString
393-
whitespace.clear()
394-
} else {
395-
nextChar()
396-
fetchToken()
397-
}
398-
case c @ (
399-
'A' | 'B' | 'C' | 'D' | 'E' |
378+
nextChar()
379+
fetchToken()
380+
case 'A' | 'B' | 'C' | 'D' | 'E' |
400381
'F' | 'G' | 'H' | 'I' | 'J' |
401382
'K' | 'L' | 'M' | 'N' | 'O' |
402383
'P' | 'Q' | 'R' | 'S' | 'T' |
@@ -407,14 +388,12 @@ object Scanners {
407388
'k' | 'l' | 'm' | 'n' | 'o' |
408389
'p' | 'q' | 'r' | 's' | 't' |
409390
'u' | 'v' | 'w' | 'x' | 'y' |
410-
'z') =>
391+
'z' =>
411392
putChar(ch)
412393
nextChar()
413394
getIdentRest()
414-
if (ch == '"' && token == IDENTIFIER) {
395+
if (ch == '"' && token == IDENTIFIER)
415396
token = INTERPOLATIONID
416-
startedLiteral = "\""
417-
}
418397
case '<' => // is XMLSTART?
419398
def fetchLT() = {
420399
val last = if (charOffset >= 2) buf(charOffset - 2) else ' '
@@ -515,11 +494,9 @@ object Scanners {
515494
getLitChar()
516495
if (ch == '\'') {
517496
nextChar()
518-
startedLiteral = null
519497
token = CHARLIT
520498
setStrVal()
521499
} else {
522-
startedLiteral = "\'"
523500
error("unclosed character literal")
524501
}
525502
}
@@ -709,12 +686,8 @@ object Scanners {
709686
if (ch == '"') {
710687
setStrVal()
711688
nextChar()
712-
startedLiteral = null
713689
token = STRINGLIT
714-
} else {
715-
startedLiteral = "\""
716-
error("unclosed string literal")
717-
}
690+
} else error("unclosed string literal")
718691
}
719692

720693
private def getRawStringLit(): Unit = {

src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ abstract class TokensCommon {
141141

142142
object Tokens extends TokensCommon {
143143
final val minToken = EMPTY
144-
final val maxToken = COMMENT
144+
final val maxToken = XMLSTART
145145

146146
final val INTERPOLATIONID = 10; enter(INTERPOLATIONID, "string interpolator")
147147
final val SYMBOLLIT = 11; enter(SYMBOLLIT, "symbol literal") // TODO: deprecate
@@ -188,11 +188,6 @@ object Tokens extends TokensCommon {
188188
/** XML mode */
189189
final val XMLSTART = 96; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate
190190

191-
/** Whitespace */
192-
final val WHITESPACE = 97; enter(WHITESPACE, "whitespace")
193-
final val COMMENT = 98; enter(COMMENT, "comment")
194-
195-
196191
final val alphaKeywords = tokenRange(IF, FORSOME)
197192
final val symbolicKeywords = tokenRange(USCORE, VIEWBOUND)
198193
final val symbolicTokens = tokenRange(COMMA, VIEWBOUND)

test/test/TestREPL.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestREPL(script: String) extends REPL {
2020
override lazy val config = new REPL.Config {
2121
override val output = new NewLinePrintWriter(out)
2222

23-
override def input(implicit ctx: Context) = new InteractiveReader {
23+
override def input(in: Interpreter)(implicit ctx: Context) = new InteractiveReader {
2424
val lines = script.lines
2525
def readLine(prompt: String): String = {
2626
val line = lines.next

tests/repl/imports.check

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ scala> import scala.collection.mutable
22
import scala.collection.mutable
33
scala> val buf = mutable.ListBuffer[Int]()
44
buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
5-
scala> object o {
6-
| val xs = List(1, 2, 3)
7-
| }
5+
scala> object o { val xs = List(1, 2, 3) }
86
defined module o
97
scala> import o._
108
import o._

tests/repl/multilines.check

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)