summaryrefslogtreecommitdiff
path: root/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
diff options
context:
space:
mode:
Diffstat (limited to 'scalatexApi/src/main/scala/scalatex/stages/Compiler.scala')
-rw-r--r--scalatexApi/src/main/scala/scalatex/stages/Compiler.scala23
1 files changed, 17 insertions, 6 deletions
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
index 5704b2c..0ac9844 100644
--- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
+++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
@@ -25,18 +25,29 @@ object Compiler{
case (curr, Ast.Chain.TypeArgs(str, offset2)) =>
val TypeApply(fun, args) = c.parse(s"omg$str")
TypeApply(curr, args)
- case (curr, Ast.Block(front, parts, offset)) =>
- q"$curr(..${compileBlock(front, parts, offset)})"
+ case (curr, Ast.Block(parts, offset)) =>
+ q"$curr(..${compileBlock(parts, offset)})"
+ case (curr, Ast.Header(header, block, offset)) =>
+ q"$curr(${compileHeader(header, block, offset)})"
+
}
}
- def compileBlock(front: Option[String], parts: Seq[Ast.Block.Sub], offset: Int): Seq[c.Tree] = {
+ def compileBlock(parts: Seq[Ast.Block.Sub], offset: Int): Seq[c.Tree] = {
parts.map{
- case Ast.Block.Text(str, offset2) => q"$str"
+ case Ast.Block.Text(str, _) => q"$str"
case Ast.Chain(code, parts, offset) => compileChain(code, parts, offset)
-
+ case Ast.Header(header, block, offset) => compileHeader(header, block, offset)
}
}
- val res = q"Seq[$fragType](..${compileBlock(None, template.parts, template.offset)})"
+ def compileHeader(header: String, block: Ast.Block, offset: Int): c.Tree = {
+ val Block(stmts, expr) = c.parse(s"{$header\n ()}")
+ Block(stmts, wrapBlock(compileBlock(block.parts, block.offset)))
+ }
+
+ def wrapBlock(items: Seq[c.Tree]) = {
+ q"Seq[$fragType](..$items)"
+ }
+ val res = wrapBlock(compileBlock(template.parts, template.offset))
println("::::::::::::::::::::::::::::::::::::::::::::::::")
println(res)
println("::::::::::::::::::::::::::::::::::::::::::::::::")