aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Decorators.scala
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-26 16:12:59 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-04-02 14:55:40 +0200
commita846ccf9efffefc55e0750921096aa323a4f4d04 (patch)
treedb5d0fdae42cb4efaa5ede0a3e7eab1375c8e3e1 /src/dotty/tools/dotc/core/Decorators.scala
parent2033b5607a41b77590b8d23bf5c40c906a0b42e7 (diff)
downloaddotty-a846ccf9efffefc55e0750921096aa323a4f4d04.tar.gz
dotty-a846ccf9efffefc55e0750921096aa323a4f4d04.tar.bz2
dotty-a846ccf9efffefc55e0750921096aa323a4f4d04.zip
move InfoString from ErrorReporting to Decorators and
remove all isSensical/SuppressedMessage logic from InfoString
Diffstat (limited to 'src/dotty/tools/dotc/core/Decorators.scala')
-rw-r--r--src/dotty/tools/dotc/core/Decorators.scala33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala
index 21f914d99..25b5dbabc 100644
--- a/src/dotty/tools/dotc/core/Decorators.scala
+++ b/src/dotty/tools/dotc/core/Decorators.scala
@@ -3,7 +3,7 @@ package core
import annotation.tailrec
import Symbols._
-import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer
+import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer, printing.Showable
import util.Positions.Position, util.SourcePosition
import collection.mutable.ListBuffer
import dotty.tools.dotc.transform.TreeTransforms._
@@ -136,5 +136,36 @@ object Decorators {
implicit def sourcePos(pos: Position)(implicit ctx: Context): SourcePosition =
ctx.source.atPos(pos)
+
+ /** The i"..." string interpolator adds two features to the s interpolator:
+ * 1) On all Showables, `show` is called instead of `toString`
+ * 2) Lists can be formatted using the desired separator between two `%` signs,
+ * eg `i"myList = (${myList}%, %)"`
+ */
+ implicit class InfoString(val sc: StringContext) extends AnyVal {
+
+ def i(args: Any*)(implicit ctx: Context): String = {
+
+ def treatArg(arg: Any, suffix: String): (Any, String) = arg match {
+ case arg: Seq[_] if suffix.nonEmpty && suffix.head == '%' =>
+ val (rawsep, rest) = suffix.tail.span(_ != '%')
+ val sep = StringContext.treatEscapes(rawsep)
+ if (rest.nonEmpty) (arg map treatSingleArg mkString sep, rest.tail)
+ else (arg, suffix)
+ case _ =>
+ (treatSingleArg(arg), suffix)
+ }
+
+ def treatSingleArg(arg: Any) : Any = arg match {
+ case arg: Showable => arg.show
+ case _ => arg
+ }
+
+ val prefix :: suffixes = sc.parts.toList
+ val (args1, suffixes1) = (args, suffixes).zipped.map(treatArg(_, _)).unzip
+ new StringContext(prefix :: suffixes1.toList: _*).s(args1: _*)
+ }
+ }
+
}