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 | |
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')
-rw-r--r-- | scalatexApi/src/main/scala/scalatex/stages/Compiler.scala | 25 | ||||
-rw-r--r-- | scalatexApi/src/test/scala/scalatex/ErrorTests.scala | 599 |
2 files changed, 331 insertions, 293 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 diff --git a/scalatexApi/src/test/scala/scalatex/ErrorTests.scala b/scalatexApi/src/test/scala/scalatex/ErrorTests.scala index f9e9308..0a68550 100644 --- a/scalatexApi/src/test/scala/scalatex/ErrorTests.scala +++ b/scalatexApi/src/test/scala/scalatex/ErrorTests.scala @@ -28,294 +28,321 @@ object ErrorTests extends TestSuite{ } val tests = TestSuite{ +// +// +// 'simple - check( +// twRuntimeErrors("omg @notInScope lol"), +// """not found: value notInScope""", +// """ +// twRuntimeErrors("omg @notInScope lol"), +// ^ +// """ +// ) +// +// 'chained{ +// 'properties { +// * - check( +// twRuntimeErrors("omg @math.lol lol"), +// """object lol is not a member of package math""", +// """ +// twRuntimeErrors("omg @math.lol lol"), +// ^ +// """ +// ) +// +// * - check( +// twRuntimeErrors("omg @math.E.lol lol"), +// """value lol is not a member of Double""", +// """ +// twRuntimeErrors("omg @math.E.lol lol"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("omg @_root_.scala.math.lol lol"), +// """object lol is not a member of package math""", +// """ +// twRuntimeErrors("omg @_root_.scala.math.lol lol"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("omg @_root_.scala.gg.lol lol"), +// """object gg is not a member of package scala""", +// """ +// twRuntimeErrors("omg @_root_.scala.gg.lol lol"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("omg @_root_.ggnore.math.lol lol"), +// """object ggnore is not a member of package <root>""", +// """ +// twRuntimeErrors("omg @_root_.ggnore.math.lol lol"), +// ^ +// """ +// ) +// } +// 'calls{ +// * - check( +// twRuntimeErrors("@scala.QQ.abs(-10).tdo(10).sum.z"), +// """object QQ is not a member of package scala""", +// """ +// twRuntimeErrors("@scala.QQ.abs(-10).tdo(10).sum.z"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@scala.math.abs(-10).tdo(10).sum.z"), +// "value tdo is not a member of Int", +// """ +// twRuntimeErrors("@scala.math.abs(-10).tdo(10).sum.z"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z"), +// "value z is not a member of Int", +// """ +// twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z()"), +// "value z is not a member of Int", +// """ +// twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z()"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@scala.math.abs(-10).cow.sum.z"), +// "value cow is not a member of Int", +// """ +// twRuntimeErrors("@scala.math.abs(-10).cow.sum.z"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@scala.smath.abs.cow.sum.z"), +// "object smath is not a member of package scala", +// """ +// twRuntimeErrors("@scala.smath.abs.cow.sum.z"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors(""" +// I am cow hear me moo +// @scala.math.abs(-10).tdo(10).sum.z +// I weigh twice as much as you +// """), +// "value tdo is not a member of Int", +// """ +// @scala.math.abs(-10).tdo(10).sum.z +// ^ +// """ +// ) +// } +// 'curlies{ +// * - check( +// twRuntimeErrors("@p{@Seq(1, 2, 3).foldLeft(0)}"), +// "missing arguments for method foldLeft", +// """ +// twRuntimeErrors("@p{@Seq(1, 2, 3).foldLeft(0)}"), +// ^ +// """ +// ) - - 'simple - check( - twRuntimeErrors("omg @notInScope lol"), - """not found: value notInScope""", - """ - twRuntimeErrors("omg @notInScope lol"), - ^ - """ - ) - - 'chained{ - 'properties { - * - check( - twRuntimeErrors("omg @math.lol lol"), - """object lol is not a member of package math""", - """ - twRuntimeErrors("omg @math.lol lol"), - ^ - """ - ) - - * - check( - twRuntimeErrors("omg @math.E.lol lol"), - """value lol is not a member of Double""", - """ - twRuntimeErrors("omg @math.E.lol lol"), - ^ - """ - ) - * - check( - twRuntimeErrors("omg @_root_.scala.math.lol lol"), - """object lol is not a member of package math""", - """ - twRuntimeErrors("omg @_root_.scala.math.lol lol"), - ^ - """ - ) - * - check( - twRuntimeErrors("omg @_root_.scala.gg.lol lol"), - """object gg is not a member of package scala""", - """ - twRuntimeErrors("omg @_root_.scala.gg.lol lol"), - ^ - """ - ) - * - check( - twRuntimeErrors("omg @_root_.ggnore.math.lol lol"), - """object ggnore is not a member of package <root>""", - """ - twRuntimeErrors("omg @_root_.ggnore.math.lol lol"), - ^ - """ - ) - } - 'calls{ - * - check( - twRuntimeErrors("@scala.QQ.abs(-10).tdo(10).sum.z"), - """object QQ is not a member of package scala""", - """ - twRuntimeErrors("@scala.QQ.abs(-10).tdo(10).sum.z"), - ^ - """ - ) - * - check( - twRuntimeErrors("@scala.math.abs(-10).tdo(10).sum.z"), - "value tdo is not a member of Int", - """ - twRuntimeErrors("@scala.math.abs(-10).tdo(10).sum.z"), - ^ - """ - ) - * - check( - twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z"), - "value z is not a member of Int", - """ - twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z"), - ^ - """ - ) - * - check( - twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z()"), - "value z is not a member of Int", - """ - twRuntimeErrors("@scala.math.abs(-10).to(10).sum.z()"), - ^ - """ - ) - * - check( - twRuntimeErrors("@scala.math.abs(-10).cow.sum.z"), - "value cow is not a member of Int", - """ - twRuntimeErrors("@scala.math.abs(-10).cow.sum.z"), - ^ - """ - ) - * - check( - twRuntimeErrors("@scala.smath.abs.cow.sum.z"), - "object smath is not a member of package scala", - """ - twRuntimeErrors("@scala.smath.abs.cow.sum.z"), - ^ - """ - ) - * - check( - twRuntimeErrors(""" - I am cow hear me moo - @scala.math.abs(-10).tdo(10).sum.z - I weigh twice as much as you - """), - "value tdo is not a member of Int", - """ - @scala.math.abs(-10).tdo(10).sum.z - ^ - """ - ) - } - 'callContents{ +// * - check( +// twRuntimeErrors("@Nil.foldLeft{XY}"), +// "missing arguments for method foldLeft", +// """ +// twRuntimeErrors("@Nil.foldLeft{XY}"), +// ^ +// """ +// ) * - check( - twRuntimeErrors("@scala.math.abs((1, 2).wtf)"), - "value wtf is not a member of (Int, Int)", - """ - twRuntimeErrors("@scala.math.abs((1, 2).wtf)"), - ^ - """ - ) - - * - check( - twRuntimeErrors("@scala.math.abs((1, 2).swap._1.toString().map(_.toString.wtf))"), - "value wtf is not a member of String", - """ - twRuntimeErrors("@scala.math.abs((1, 2).swap._1.toString().map(_.toString.wtf))"), - ^ - """ - ) - } - } - 'ifElse{ - 'oneLine { - * - check( - twRuntimeErrors("@if(math > 10){ 1 }else{ 2 }"), - "object > is not a member of package math", - """ - twRuntimeErrors("@if(math > 10){ 1 }else{ 2 }"), - ^ - """ - ) - * - check( - twRuntimeErrors("@if(true){ (@math.pow(10)) * 10 }else{ 2 }"), - "Unspecified value parameter y", - """ - twRuntimeErrors("@if(true){ (@math.pow(10)) * 10 }else{ 2 }"), + twRuntimeErrors("@Seq(1).map{x => XY}"), + "missing arguments for method foldLeft", + """ + twRuntimeErrors("@Nil.foldLeft{XY}"), ^ - """ - ) - * - check( - twRuntimeErrors("@if(true){ * 10 }else{ @math.sin(3, 4, 5) }"), - "too many arguments for method sin: (x: Double)Double", - """ - twRuntimeErrors("@if(true){ * 10 }else{ @math.sin(3, 4, 5) }"), - ^ - """ - ) - } - 'multiLine{ - * - check( - twRuntimeErrors(""" - Ho Ho Ho - - @if(math != 10) - I am a cow - @else - You are a cow - GG - """), - "object != is not a member of package math", - """ - @if(math != 10) - ^ - """ - ) - * - check( - twRuntimeErrors(""" - Ho Ho Ho - - @if(4 != 10) - I am a cow @math.lols - @else - You are a cow - GG - """), - "object lols is not a member of package math", - """ - I am a cow @math.lols - ^ - """ - ) - * - check( - twRuntimeErrors(""" - Ho Ho Ho - - @if(12 != 10) - I am a cow - @else - @math.E.toString.gog(1) - GG - """), - "value gog is not a member of String", - """ - @math.E.toString.gog(1) - ^ - """ - ) - } - } - 'forLoop{ - 'oneLine{ - 'header - check( - twRuntimeErrors("omg @for(x <- (0 + 1 + 2) omglolol (10 + 11 + 2)){ hello }"), - """value omglolol is not a member of Int""", - """ - twRuntimeErrors("omg @for(x <- (0 + 1 + 2) omglolol (10 + 11 + 2)){ hello }"), - ^ - """ - ) - - 'body - check( - twRuntimeErrors("omg @for(x <- 0 until 10){ @((x, 2) + (1, 2)) }"), - """too many arguments for method +""", - """ - twRuntimeErrors("omg @for(x <- 0 until 10){ @((x, 2) + (1, 2)) }"), - ^ - """ - ) - } - 'multiLine{ - 'body - check( - twRuntimeErrors(""" - omg - @for(x <- 0 until 10) - I am cow hear me moo - I weigh twice as much as @x.kkk - """), - """value kkk is not a member of Int""", - """ - I weigh twice as much as @x.kkk - ^ - """ - ) - } - } - 'multiLine{ - 'missingVar - check( - twRuntimeErrors(""" - omg @notInScope lol - """), - """not found: value notInScope""", - """ - omg @notInScope lol - ^ - """ - ) - 'wrongType - check( - twRuntimeErrors(""" - omg @{() => ()} lol - """), - """type mismatch""", - """ - omg @{() => ()} lol - ^ - """ - ) - - 'bigExpression - check( - twRuntimeErrors(""" - @{ - val x = 1 + 2 - val y = new Object() - val z = y * x - x - } - """), - "value * is not a member of Object", - """ - val z = y * x - ^ - """ - ) - } + """ + ) +// } +// 'callContents{ +// * - check( +// twRuntimeErrors("@scala.math.abs((1, 2).wtf)"), +// "value wtf is not a member of (Int, Int)", +// """ +// twRuntimeErrors("@scala.math.abs((1, 2).wtf)"), +// ^ +// """ +// ) +// +// * - check( +// twRuntimeErrors("@scala.math.abs((1, 2).swap._1.toString().map(_.toString.wtf))"), +// "value wtf is not a member of String", +// """ +// twRuntimeErrors("@scala.math.abs((1, 2).swap._1.toString().map(_.toString.wtf))"), +// ^ +// """ +// ) +// } +// } +// 'ifElse{ +// 'oneLine { +// * - check( +// twRuntimeErrors("@if(math > 10){ 1 }else{ 2 }"), +// "object > is not a member of package math", +// """ +// twRuntimeErrors("@if(math > 10){ 1 }else{ 2 }"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@if(true){ (@math.pow(10)) * 10 }else{ 2 }"), +// "Unspecified value parameter y", +// """ +// twRuntimeErrors("@if(true){ (@math.pow(10)) * 10 }else{ 2 }"), +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors("@if(true){ * 10 }else{ @math.sin(3, 4, 5) }"), +// "too many arguments for method sin: (x: Double)Double", +// """ +// twRuntimeErrors("@if(true){ * 10 }else{ @math.sin(3, 4, 5) }"), +// ^ +// """ +// ) +// } +// 'multiLine{ +// * - check( +// twRuntimeErrors(""" +// Ho Ho Ho +// +// @if(math != 10) +// I am a cow +// @else +// You are a cow +// GG +// """), +// "object != is not a member of package math", +// """ +// @if(math != 10) +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors(""" +// Ho Ho Ho +// +// @if(4 != 10) +// I am a cow @math.lols +// @else +// You are a cow +// GG +// """), +// "object lols is not a member of package math", +// """ +// I am a cow @math.lols +// ^ +// """ +// ) +// * - check( +// twRuntimeErrors(""" +// Ho Ho Ho +// +// @if(12 != 10) +// I am a cow +// @else +// @math.E.toString.gog(1) +// GG +// """), +// "value gog is not a member of String", +// """ +// @math.E.toString.gog(1) +// ^ +// """ +// ) +// } +// } +// 'forLoop{ +// 'oneLine{ +// 'header - check( +// twRuntimeErrors("omg @for(x <- (0 + 1 + 2) omglolol (10 + 11 + 2)){ hello }"), +// """value omglolol is not a member of Int""", +// """ +// twRuntimeErrors("omg @for(x <- (0 + 1 + 2) omglolol (10 + 11 + 2)){ hello }"), +// ^ +// """ +// ) +// +// 'body - check( +// twRuntimeErrors("omg @for(x <- 0 until 10){ @((x, 2) + (1, 2)) }"), +// """too many arguments for method +""", +// """ +// twRuntimeErrors("omg @for(x <- 0 until 10){ @((x, 2) + (1, 2)) }"), +// ^ +// """ +// ) +// } +// 'multiLine{ +// 'body - check( +// twRuntimeErrors(""" +// omg +// @for(x <- 0 until 10) +// I am cow hear me moo +// I weigh twice as much as @x.kkk +// """), +// """value kkk is not a member of Int""", +// """ +// I weigh twice as much as @x.kkk +// ^ +// """ +// ) +// } +// } +// 'multiLine{ +// 'missingVar - check( +// twRuntimeErrors(""" +// omg @notInScope lol +// """), +// """not found: value notInScope""", +// """ +// omg @notInScope lol +// ^ +// """ +// ) +// 'wrongType - check( +// twRuntimeErrors(""" +// omg @{() => ()} lol +// """), +// """type mismatch""", +// """ +// omg @{() => ()} lol +// ^ +// """ +// ) +// +// 'bigExpression - check( +// twRuntimeErrors(""" +// @{ +// val x = 1 + 2 +// val y = new Object() +// val z = y * x +// x +// } +// """), +// "value * is not a member of Object", +// """ +// val z = y * x +// ^ +// """ +// ) +// } } } |