diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-15 14:11:26 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-15 14:11:26 -0800 |
commit | 0f784a53bcce67c760c8c1041d0f4c632fc3e5b3 (patch) | |
tree | fd3bee2bc874b8418ecb3127adcf6d33d23f50fc /src/compiler | |
parent | 0e8984100709658588c67d097452b8606c12d750 (diff) | |
parent | f606d8176e57fbb61495b693bf3cd4e77373fcfb (diff) | |
download | scala-0f784a53bcce67c760c8c1041d0f4c632fc3e5b3.tar.gz scala-0f784a53bcce67c760c8c1041d0f4c632fc3e5b3.tar.bz2 scala-0f784a53bcce67c760c8c1041d0f4c632fc3e5b3.zip |
Merge pull request #3285 from som-snytt/issue/8015-FF-NLs
Count lines by EOLs
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/CharArrayReader.scala | 26 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 87bd498ea1..32c15b04aa 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -206,9 +206,9 @@ trait Scanners extends ScannersCommon { token = kwArray(idx) if (token == IDENTIFIER && allowIdent != name) { if (name == nme.MACROkw) - syntaxError(name+" is now a reserved word; usage as an identifier is disallowed") + syntaxError(s"$name is now a reserved word; usage as an identifier is disallowed") else if (emitIdentifierDeprecationWarnings) - deprecationWarning(name+" is now a reserved word; usage as an identifier is deprecated") + deprecationWarning(s"$name is now a reserved word; usage as an identifier is deprecated") } } } @@ -389,7 +389,7 @@ trait Scanners extends ScannersCommon { // println("blank line found at "+lastOffset+":"+(lastOffset to idx).map(buf(_)).toList) return true } - if (idx == end) return false + if (idx == end) return false } while (ch <= ' ') } idx += 1; ch = buf(idx) diff --git a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala index f116e4af34..e6f95eb0d6 100644 --- a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala +++ b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala @@ -46,7 +46,7 @@ abstract class CharArrayReader extends CharArrayReaderData { self => def isUnicodeEscape = charOffset == lastUnicodeOffset /** Advance one character; reducing CR;LF pairs to just LF */ - final def nextChar() { + final def nextChar(): Unit = { if (charOffset >= buf.length) { ch = SU } else { @@ -54,7 +54,10 @@ abstract class CharArrayReader extends CharArrayReaderData { self => ch = c charOffset += 1 if (c == '\\') potentialUnicode() - else if (c < ' ') { skipCR(); potentialLineEnd() } + if (ch < ' ') { + skipCR() + potentialLineEnd() + } } } @@ -74,7 +77,7 @@ abstract class CharArrayReader extends CharArrayReaderData { self => } /** Interpret \\uxxxx escapes */ - private def potentialUnicode() { + private def potentialUnicode() = { def evenSlashPrefix: Boolean = { var p = charOffset - 2 while (p >= 0 && buf(p) == '\\') p -= 1 @@ -105,13 +108,17 @@ abstract class CharArrayReader extends CharArrayReaderData { self => } /** replace CR;LF by LF */ - private def skipCR() { - if (ch == CR) - if (charOffset < buf.length && buf(charOffset) == LF) { - charOffset += 1 - ch = LF + private def skipCR() = + if (ch == CR && charOffset < buf.length) + buf(charOffset) match { + case LF => + charOffset += 1 + ch = LF + case '\\' => + if (lookaheadReader.getu == LF) + potentialUnicode() + case _ => } - } /** Handle line ends */ private def potentialLineEnd() { @@ -132,5 +139,6 @@ abstract class CharArrayReader extends CharArrayReaderData { self => def error(offset: Int, msg: String) = self.error(offset, msg) /** A mystery why CharArrayReader.nextChar() returns Unit */ def getc() = { nextChar() ; ch } + def getu() = { require(buf(charOffset) == '\\') ; ch = '\\' ; charOffset += 1 ; potentialUnicode() ; ch } } } |