use IO::File;
+our $arguments;
our @cond;
sub out {
$T::out_func->(@_);
+ return;
+}
+
+our %deps = ();
+
+sub add_depend($) {
+ $deps{$_[0]} = 1;
}
sub get_nested($$$) {
}
# print "Cond stack: @cond\n";
} else {
- my $res = eval_if_ok("$f($a)");
+ my $res = eval_if_ok("$f $a");
out $res if defined $res;
}
}
} elsif ($t =~ /\G\@#[^\n]*\n/cgs) {
# a comment, which is ignored
} elsif ($t =~ /\G\@\@/cgs) {
- out "\@";
+ out "\@" if $cond[0] > 0;
} elsif ($t =~ /\G\@{/cgs) {
my $x = get_nested(\$t, "{", "}");
out eval_if_ok($x);
$x =~ s/^\[//;
$x =~ s/\]$//;
eval_if_ok($x);
+ } elsif ($t =~ /\G\@\(/cgs) {
+ my $x = get_nested(\$t, '\(', '\)');
+ $x =~ s/^\(//;
+ $x =~ s/\)$//;
+ out (defined($arguments->{$x}) ? $arguments->{$x} : "");
} elsif ($t =~ /\G\@(\w+)\(/cgs) {
my $func = $1;
my $args = get_nested(\$t, '(', ')');
sub parse_file($) {
my ($name) = @_;
+ add_depend($name);
my $fh = new IO::File $name;
die "Unable to open $name: $!" unless defined $fh;
my $text;
parse_string($text);
}
-sub start()
+sub start(;$)
{
+ $arguments = $_[0];
@cond = (1);
}
$#cond and die "Unterminated \@if (depth $#cond)";
}
-sub process_file($) {
- start();
- parse_file($_[0]);
+sub process_file($;$) {
+ my ($name, $args) = @_;
+ start($args);
+ parse_file($name);
finish();
}
-sub process_string($) {
- start();
- parse_string($_[0]);
+sub process_string($;$) {
+ my ($string, $args) = @_;
+ start($args);
+ parse_string($string);
finish();
}
sub load {
my $f = shift @_;
(!defined($f) || @_) and die "\@load requires only one argument";
+ UCW::Temple::add_depend($f);
require $f;
return;
}