From 4d4de616f2181fdfcbcc1cd3180689d9e258fcc3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 12 Aug 2015 12:22:34 +0200 Subject: [PATCH] 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. --- UCW/Temple.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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)"); -- 2.39.5