aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-04-07 09:58:43 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-04-07 09:58:43 +0200
commitc7730ad9ea99ce7fa53e4cddefdd2afd9f60ce20 (patch)
tree07047a2d732406423deb561d67439be7cfa723b4 /src
parentf43f520a1a6e60d4a6020af97c52dd6c43ea75cd (diff)
downloaddotty-c7730ad9ea99ce7fa53e4cddefdd2afd9f60ce20.tar.gz
dotty-c7730ad9ea99ce7fa53e4cddefdd2afd9f60ce20.tar.bz2
dotty-c7730ad9ea99ce7fa53e4cddefdd2afd9f60ce20.zip
Add commandline argument `-Ykeep-comments` to remove hardcoding
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/config/ScalaSettings.scala1
-rw-r--r--src/dotty/tools/dotc/parsing/Scanners.scala16
2 files changed, 10 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala
index 07a23fdb6..f9c10442a 100644
--- a/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -159,6 +159,7 @@ class ScalaSettings extends Settings.SettingGroup {
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")
+ val YkeepComments = BooleanSetting("-Ykeep-comments", "Keep comments when scanning source files.")
def stop = YstopAfter
/** Area-specific debug output.
diff --git a/src/dotty/tools/dotc/parsing/Scanners.scala b/src/dotty/tools/dotc/parsing/Scanners.scala
index 4211b6275..9d08948a5 100644
--- a/src/dotty/tools/dotc/parsing/Scanners.scala
+++ b/src/dotty/tools/dotc/parsing/Scanners.scala
@@ -175,7 +175,7 @@ object Scanners {
}
class Scanner(source: SourceFile, override val startFrom: Offset = 0)(implicit ctx: Context) extends ScannerCommon(source)(ctx) {
- var keepComments = false
+ val keepComments = ctx.settings.YkeepComments.value
/** All comments in the reverse order of their position in the source.
* set only when `keepComments` is true.
@@ -560,7 +560,8 @@ object Scanners {
}
private def skipComment(): Boolean = {
- def appendToComment(ch: Char) = commentBuf.append(ch)
+ def appendToComment(ch: Char) =
+ if (keepComments) commentBuf.append(ch)
def nextChar() = {
appendToComment(ch)
Scanner.this.nextChar()
@@ -587,14 +588,15 @@ object Scanners {
def nestedComment() = { nextChar(); skipComment() }
val start = lastCharOffset
def finishComment(): Boolean = {
- val pos = Position(start, charOffset, start)
- val comment = Comment(pos, flushBuf(commentBuf))
+ if (keepComments) {
+ val pos = Position(start, charOffset, start)
+ val comment = Comment(pos, flushBuf(commentBuf))
- if (comment.isDocComment)
- docsPerBlockStack = (docsPerBlockStack.head :+ comment) :: docsPerBlockStack.tail
+ if (comment.isDocComment)
+ docsPerBlockStack = (docsPerBlockStack.head :+ comment) :: docsPerBlockStack.tail
- if (keepComments)
revComments = comment :: revComments
+ }
true
}