Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Ratel] whitespace therapy
  • Loading branch information
Carl Masak committed Jun 9, 2010
1 parent cb67b53 commit 511ea75
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Ratel.pm
Expand Up @@ -2,19 +2,26 @@ 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);
$!compiled
= $source.subst(/(['%]' | ^ ] .*? [ $ | '[%' ])/,
{";\$.emit-hunk({$index++});"},
:g);
}

method emit-hunk(Int $i) {
print @.hunks[$i][0];
}

method do(*%attrs) {
eval $.compiled;
}
Expand Down

0 comments on commit 511ea75

Please sign in to comment.