Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial import of template sketch.

  • Loading branch information...
commit 117120eae7100f2a5b86a3b52f255f789197824a 1 parent 668d76b
@tene tene authored
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/Ratel.pm
View
21 lib/Ratel.pm
@@ -0,0 +1,21 @@
+class Ratel {
+ has $.source;
+ has $.compiled;
+ has @.hunks;
+ method load(Str $filename) {
+ $.compile(slurp($filename));
+ }
+ method compile(Str $text) {
+ my $index = 0;
+ $!source = $text;
+ my $source = "%]$text[%";
+ @!hunks = $source.comb(/'%]' (.*?) '[%'/);
+ $!compiled = $source.subst(/(['%]' | ^ ] .*? [ $ | '[%' ])/, {";\$.emit-hunk({$index++});"}, :g);
+ }
+ method emit-hunk(Int $i) {
+ print @.hunks[$i][0];
+ }
+ method do(*%attrs) {
+ eval $.compiled;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.