diff options
4 files changed, 112 insertions, 101 deletions
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala index 5a3f38b..f55c348 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala @@ -68,7 +68,7 @@ object Compiler{ case None => EmptyTree } - val res = If(incPosRec(cond, offset1), compileBlock(parts2, offset2), elseCompiled) + val res = If(incPosRec(cond, offset1 + 2), compileBlock(parts2, offset2), elseCompiled) println("Tree " + res) incPos(res, offset1) diff --git a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala index 4d35fd1..06659d0 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala @@ -68,27 +68,27 @@ class Parser(input: ParserInput, indent: Int = 0, offset: Int = 0) extends Scala } def IfHead = rule{ "@" ~ capture("if" ~ "(" ~ Expr ~ ")") } def IfElse1 = rule{ - IfHead ~ BraceBlock ~ optional("else" ~ (BraceBlock | IndentBlock)) + push(offsetCursor) ~ IfHead ~ BraceBlock ~ optional("else" ~ (BraceBlock | IndentBlock)) } def IfElse2 = rule{ - Indent ~ IfHead ~ IndentBlock ~ optional(Indent ~ "@else" ~ (BraceBlock | IndentBlock)) + Indent ~ push(offsetCursor) ~ IfHead ~ IndentBlock ~ optional(Indent ~ "@else" ~ (BraceBlock | IndentBlock)) } def IfElse = rule{ - (IfElse1 | IfElse2) ~> (Ast.Block.IfElse(_, _, _)) + (IfElse1 | IfElse2) ~> ((a, b, c, d) => Ast.Block.IfElse(b, c, d, a)) } def ForHead = rule{ - "@" ~ capture("for" ~ '(' ~ Enumerators ~ ')') + push(offsetCursor) ~ "@" ~ capture("for" ~ '(' ~ Enumerators ~ ')') } def ForLoop = rule{ ForHead ~ - BraceBlock ~> (Ast.Block.For(_, _)) + BraceBlock ~> ((a, b, c) => Ast.Block.For(b, c, a)) } def LoneForLoop = rule{ (push(offsetCursor) ~ capture(Indent) ~> ((i, t) => Ast.Block.Text(t, i))) ~ ForHead ~ IndentBlock ~> - (Ast.Block.For(_, _)) + ((a, b, c) => Ast.Block.For(b, c, a)) } def ScalaChain = rule { diff --git a/scalatexApi/src/test/scala/scalatex/ErrorTests.scala b/scalatexApi/src/test/scala/scalatex/ErrorTests.scala index 8535b72..6ed1d31 100644 --- a/scalatexApi/src/test/scala/scalatex/ErrorTests.scala +++ b/scalatexApi/src/test/scala/scalatex/ErrorTests.scala @@ -39,7 +39,7 @@ object ErrorTests extends TestSuite{ """ ) -// 'chained{ + 'chained{ 'properties { * - check( twRuntimeErrors("omg @math.lol lol"), @@ -216,95 +216,95 @@ object ErrorTests extends TestSuite{ """ ) } -// } -// '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) -// ^ -// """ -// ) -// } -// } + } + '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 }"), -// ^ -// """ -// ) + '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)) }"), diff --git a/scalatexApi/src/test/scala/scalatex/ParserTests.scala b/scalatexApi/src/test/scala/scalatex/ParserTests.scala index 68f05cc..68ea441 100644 --- a/scalatexApi/src/test/scala/scalatex/ParserTests.scala +++ b/scalatexApi/src/test/scala/scalatex/ParserTests.scala @@ -163,7 +163,11 @@ object ParserTests extends utest.TestSuite{ _.Body.run(), Block(Seq( Text("\n"), - For("for(x <- 0 until 3)", Block(Seq(Text("\n ", 21), Text("lol", 24)), 21)) + For( + "for(x <- 0 until 3)", + Block(Seq(Text("\n ", 21), Text("lol", 24)), 21), + 1 + ) )) ) 'forBlockBraces - check( @@ -174,7 +178,11 @@ object ParserTests extends utest.TestSuite{ _.Body.run(), Block(Seq( Text("\n"), - For("for(x <- 0 until 3)", Block(Seq(Text("\n ", 22), Text("lol", 25), Text("\n", 28)), 22)) + For( + "for(x <- 0 until 3)", + Block(Seq(Text("\n ", 22), Text("lol", 25), Text("\n", 28)), 22), + 1 + ) )) ) } @@ -194,7 +202,7 @@ object ParserTests extends utest.TestSuite{ |@if(true) | omg""".stripMargin, _.IfElse.run(), - IfElse("if(true)", Block(Seq(Text("\n ", 10), Text("omg", 13)), 10), None) + IfElse("if(true)", Block(Seq(Text("\n ", 10), Text("omg", 13)), 10), None, 1) ) 'ifBlockElseBlock - check( """ @@ -206,7 +214,8 @@ object ParserTests extends utest.TestSuite{ IfElse( "if(true)", Block(Seq(Text("\n ", 10), Text("omg", 13)), 10), - Some(Block(Seq(Text("\n ", 22), Text("wtf", 25)), 22)) + Some(Block(Seq(Text("\n ", 22), Text("wtf", 25)), 22)), + 1 ) ) 'ifBlockElseBraceBlock - check( @@ -219,7 +228,8 @@ object ParserTests extends utest.TestSuite{ IfElse( "if(true)", Block(Seq(Text("\n ", 10), Text("omg", 13), Text("\n", 16)), 10), - Some(Block(Seq(Text("\n ", 23), Text("wtf", 26), Text("\n", 29)), 23)) + Some(Block(Seq(Text("\n ", 23), Text("wtf", 26), Text("\n", 29)), 23)), + 0 ) ) 'ifBlockElseBraceBlockNested - { @@ -243,7 +253,8 @@ object ParserTests extends utest.TestSuite{ ), 16), Some(Block(Vector( Text("\n ", 35), Text("lols", 40), Text("\n ", 44) - ), 35)) + ), 35)), + 6 )), 3)), 1), Text("\n", 48) )) |