]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Perl: Avoid unnecessary nesting_depth growth.
authorBruno Haible <bruno@clisp.org>
Mon, 18 Sep 2023 18:58:32 +0000 (20:58 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 19 Sep 2023 02:11:37 +0000 (04:11 +0200)
* gettext-tools/src/x-perl.c: Ensure the top-level extract_balanced call returns
when a closing paren or bracket is seen.
(token_type_r_any): New enum item.
(prefer_regexp_over_division, extract_balanced): Handle it.
(extract_perl): Pass token_type_r_any instead of token_type_rbrace.

gettext-tools/src/x-perl.c

index 756d2a3834e92b1cfdc468e645697fcdac9c5dad..7f2e93ff47dc0dac228c6e6e692ef25aa03fc4d8 100644 (file)
@@ -546,7 +546,7 @@ enum token_type_ty
   token_type_lbracket,          /* [ */
   token_type_rbracket,          /* ] */
   token_type_string,            /* quote-like */
-  token_type_number,            /* starting with a digit o dot */
+  token_type_number,            /* starting with a digit or dot */
   token_type_named_op,          /* if, unless, while, ... */
   token_type_variable,          /* $... */
   token_type_object,            /* A dereferenced variable, maybe a blessed
@@ -557,7 +557,8 @@ enum token_type_ty
   token_type_other,             /* regexp, misc. operator */
   /* The following are not really token types, but variants used by
      the parser.  */
-  token_type_keyword_symbol     /* keyword symbol */
+  token_type_keyword_symbol,    /* keyword symbol */
+  token_type_r_any              /* rparen rbrace rbracket */
 };
 typedef enum token_type_ty token_type_ty;
 
@@ -2163,6 +2164,9 @@ prefer_regexp_over_division (token_type_ty type)
       case token_type_other:
         retval = true;
         break;
+      case token_type_r_any:
+        retval = false;
+        break;
   }
 
   #if DEBUG_PERL
@@ -3093,7 +3097,7 @@ collect_message (message_list_ty *mlp, token_ty *tp, int error_level)
    Extracted messages are added to MLP.
 
    DELIM can be either token_type_rbrace, token_type_rbracket,
-   token_type_rparen.
+   token_type_rparen, or token_type_r_any.
    Additionally, if SEMICOLON_DELIM is true, parsing stops at the next
    semicolon outside parentheses.
    Similarly, if COMMA_DELIM is true, parsing stops at the next comma
@@ -3163,7 +3167,11 @@ extract_balanced (message_list_ty *mlp,
                       && tp->sub_type == symbol_type_sub);
         }
 
-      if (delim == tp->type)
+      if (delim == tp->type
+          || (delim == token_type_r_any
+              && (tp->type == token_type_rparen
+                  || tp->type == token_type_rbrace
+                  || tp->type == token_type_rbracket)))
         {
           arglist_parser_done (argparser, arg);
           if (next_argparser != NULL)
@@ -3752,9 +3760,10 @@ extract_perl (FILE *f, const char *real_filename, const char *logical_filename,
   init_keywords ();
 
   /* Eat tokens until eof is seen.  When extract_balanced returns due to an
-     unbalanced closing brace or due to a semicolon, just restart it.  */
+     unbalanced closing paren / brace / bracket or due to a semicolon, just
+     restart it.  */
   while (!extract_balanced (mlp,
-                            token_type_rbrace, true,
+                            token_type_r_any, true,
                             true, true, false,
                             null_context, null_context_list_iterator,
                             1, arglist_parser_alloc (mlp, NULL)))