]> mj.ucw.cz Git - temple.git/commitdiff
Inline function calls @f(...) now recognize quoted string arguments
authorMartin Mares <mj@ucw.cz>
Wed, 12 Aug 2015 10:22:34 +0000 (12:22 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 12 Aug 2015 10:22:34 +0000 (12:22 +0200)
@f(":-(") does not fail any longer.

Based on a patch from KSP repository by Jirka Setnicka.

UCW/Temple.pm

index 1774fff250b85f07f5610936fa8a154dc60458b0..28f90645df5e25a82de77b7d00a1975d98b81454 100644 (file)
@@ -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)");