diff options
Diffstat (limited to 'scalatexApi/src/main/scala/scalatex/stages/Compiler.scala')
-rw-r--r-- | scalatexApi/src/main/scala/scalatex/stages/Compiler.scala | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala index 0ac9844..8bb203a 100644 --- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala +++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala @@ -17,6 +17,7 @@ object Compiler{ println(template) def compileChain(code: String, parts: Seq[Ast.Chain.Sub], offset: Int): c.Tree = { + println("CODE " + code) parts.foldLeft(c.parse(code)){ case (curr, Ast.Chain.Prop(str, offset2)) => q"$curr.${TermName(str)}" case (curr, Ast.Chain.Args(str, offset2)) => @@ -37,6 +38,22 @@ object Compiler{ 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) + case Ast.Block.For(generators, Ast.Block(parts2, offset2), offset) => + val fresh = c.fresh() + + val tree = c.parse(s"$generators yield $fresh" ) + def rec(t: Tree): Tree = t match { + case a @ Apply(fun, List(f @ Function(vparams, body))) => + val f2 = Function(vparams, rec(body)) + val a2 = Apply(fun, List(f2)) + a2 + case Ident(x: TermName) if x.decoded == fresh => + q"Seq[$fragType](..${compileBlock(parts2, offset2)})" + } + + val out = rec(tree) + println(out) + out } } def compileHeader(header: String, block: Ast.Block, offset: Int): c.Tree = { |