From: Martin Mares Date: Wed, 12 Aug 2015 10:22:34 +0000 (+0200) Subject: Inline function calls @f(...) now recognize quoted string arguments X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=4d4de616f2181fdfcbcc1cd3180689d9e258fcc3;p=temple.git Inline function calls @f(...) now recognize quoted string arguments @f(":-(") does not fail any longer. Based on a patch from KSP repository by Jirka Setnicka. --- diff --git a/UCW/Temple.pm b/UCW/Temple.pm index 1774fff..28f9064 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -79,6 +79,29 @@ sub get_nested($$$) { return $z; } +# In addition to get_nested(), skip single-quoted and double-quoted string literals +sub get_function_args($$$) { + my ($r, $left, $right) = @_; + pos $$r = pos($$r) - 1; + my $z = ""; + my $nest = 0; + do { + if ($$r =~ /\G([^$left$right"']+)/cgs + || $$r =~/\G("(\\.|[^"\\])*")/cgs # double-quoted string + || $$r =~/\G('(\\.|[^'\\])*')/cgs # single-quoted string + ) { + } elsif ($$r =~ /\G([$left])/cgs) { + $nest++; + } elsif ($$r =~ /\G([$right])/cgs) { + $nest--; + } else { + error "File ended when looking for matching $right"; + } + $z .= $1; + } while ($nest); + return $z; +} + sub eval_if_ok($) { if ($cond[0] > 0) { my $x = shift; @@ -162,7 +185,7 @@ sub parse_string($$) { out (defined($arguments->{$x}) ? $arguments->{$x} : ""); } elsif ($t =~ /\G\@(\w+)\(/cgs) { my $func = $1; - my $args = get_nested(\$t, '(', ')'); + my $args = get_function_args(\$t, '(', ')'); eval_func($func, $args); } elsif ($t =~ /\G\@(\w+)([^\n]*)\n/cgs) { eval_func($1, "($2)");