#!/usr/bin/perl6 sub html-escape($_ is copy) { s:g/\&/&/; s:g/\/>/; s:g/\"/"/; s:g/\'/'/; $_; } BEGIN { use nqp; use QAST:from; role Templating { rule escape:if { "#if" [ '#else' ]? } } role Grammar { method tweak_tpl($v) { $v ?? self.apply_tweak(Templating) !! self } } role Actions { method escape:if (Mu $/ is raw) { #$/.make: QAST::SVal.new(:value) $/.make: QAST::Op.new( :op, nqp::atkey($/, "cond").ast, nqp::atkey($/, "then").ast, nqp::existskey($/, "else") ?? nqp::atkey($/, "else").ast !!QAST::SVal.new(:value('')), ); } } $*LANG.define_slang("Quote", %*LANG but Grammar, %*LANG but Actions); } my $name = 'Franta'; for [X] (^2) xx 3 -> [$bold, $uc, $exclaim] { say qq:tpl[ Hello #if $bold {}#if $uc {$name.uc()}#else {$name}#if $exclaim {!}#else {.} #if $bold {} ] }