diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-01 10:53:21 -0700 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-01 10:53:21 -0700 |
commit | 0d91fb8632b4f7db48778c15f0a9699f82f92e6c (patch) | |
tree | 0d5d995ce3b842549f65e7d11f5d2ff7c363b915 /scalatexApi/src/main/scala | |
parent | c0b06c5e3f3caa60736794143f278c2af5cbe9fb (diff) | |
download | hands-on-scala-js-0d91fb8632b4f7db48778c15f0a9699f82f92e6c.tar.gz hands-on-scala-js-0d91fb8632b4f7db48778c15f0a9699f82f92e6c.tar.bz2 hands-on-scala-js-0d91fb8632b4f7db48778c15f0a9699f82f92e6c.zip |
Basic curly-error-positions work
Diffstat (limited to 'scalatexApi/src/main/scala')
-rw-r--r-- | scalatexApi/src/main/scala/scalatex/stages/Compiler.scala | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala index fcbe08b..292610c 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala @@ -22,7 +22,7 @@ object Compiler{ ).asInstanceOf[c.universe.Position] } def compileTree(frag: WN.TemplateTree): Tree = { - + println(frag) // println(frag) val fragPos = posFor(literalPos.point + frag.offset) @@ -75,7 +75,7 @@ object Compiler{ q"if($cond){ Seq[$fragType](..$b1): $fragType } else { Seq[$fragType](..$b2): $fragType }" case xx @ WN.ScalaExp(WN.Simple(first, _) +: rest, offset) => - + println("xx " + xx) val firstTree = c.parse(first) firstTree.foreach{x => @@ -84,6 +84,7 @@ object Compiler{ val s = rest.foldLeft[Tree](firstTree) { case (l, WN.Simple(code, _)) => + val fresh = c.fresh() val snippet = s"$fresh$code" @@ -102,16 +103,23 @@ object Compiler{ case Ident(x: TermName) if x.decoded == fresh => l } c.internal.setPos(res, newPos) - + println("CC " + res) // println(Position.formatMessage(newPos.asInstanceOf[scala.reflect.internal.util.Position], "", true)) res } - rec(skeleton) + val res = rec(skeleton) + println(";;;") + println(showCode(res, printPositions = true)) + res - case (l, WN.Block(ws, None, content, _)) => - q"$l(..${content.map(compileTree(_))})" + case (l, b @ WN.Block(ws, None, content, _)) => + val contentTrees = content.map( c => + atPos(posFor(fragPos.point + c.offset))(compileTree(c)) + ) + val res = atPos(posFor(fragPos.point + b.offset))(q"$l(..$contentTrees)") + res case (l, WN.Block(ws, Some(args), content, _)) => val snippet = s"{$args ()}" @@ -120,7 +128,10 @@ object Compiler{ val func = Function(vparamss, q"Seq[$fragType](..${content.map(compileTree(_))})") c.internal.setPos(func, posFor(fragPos.point + skeleton.pos.point)) - q"$l($func)" + val res = q"$l($func)" + c.internal.setPos(res, fragPos) + println("BB " + res) + res } s |