]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Improve interpretation of the [ ] operators.
authorBruno Haible <bruno@clisp.org>
Sat, 16 Aug 2008 10:08:53 +0000 (10:08 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:47 +0000 (12:15 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/x-python.c

index 5bc89d21275fb63be2efed817caa976f63b059a1..85427d44b19bfd56158d2cc335af9b3f93e6d886 100644 (file)
@@ -1,3 +1,14 @@
+2008-08-16  Bruno Haible  <bruno@clisp.org>
+
+       * x-python.c (enum token_type_ty): New values token_type_lbracket,
+       token_type_rbracket.
+       (phase5_get): Recognize also token_type_lbracket, token_type_rbracket.
+       (extract_balanced): Renamed from extract_parenthesized. Add 'delim'
+       argument. Handle token_type_lbracket and token_type_rbracket.
+       (extract_python): Update.
+       Reported by Claude Paroz <claude@2xlibre.net>
+       via <http://savannah.gnu.org/bugs/?23824>.
+
 2008-08-16  Bruno Haible  <bruno@clisp.org>
 
        * x-php.c (extract_balanced): Fix small bug in 2007-03-17 commit.
index e05aca4166369d39883d5883a2161827603b59e0..e12b0e9aee5fd73d6df7f1bceb1a589cacd5c634 100644 (file)
@@ -988,6 +988,8 @@ enum token_type_ty
   token_type_lparen,           /* ( */
   token_type_rparen,           /* ) */
   token_type_comma,            /* , */
+  token_type_lbracket,         /* [ */
+  token_type_rbracket,         /* ] */
   token_type_string,           /* "abc", 'abc', """abc""", '''abc''' */
   token_type_symbol,           /* symbol, number */
   token_type_other             /* misc. operator */
@@ -1581,13 +1583,13 @@ phase5_get (token_ty *tp)
 
        case '[': case '{':
          open_pbb++;
-         tp->type = token_type_other;
+         tp->type = (c == '[' ? token_type_lbracket : token_type_other);
          return;
 
        case ']': case '}':
          if (open_pbb > 0)
            open_pbb--;
-         tp->type = token_type_other;
+         tp->type = (c == ']' ? token_type_rbracket : token_type_other);
          return;
 
        default:
@@ -1664,14 +1666,17 @@ static flag_context_list_table_ty *flag_context_list_table;
    and msgid_plural can contain subexpressions of the same form.  */
 
 
-/* Extract messages until the next balanced closing parenthesis.
+/* Extract messages until the next balanced closing parenthesis or bracket.
    Extracted messages are added to MLP.
-   Return true upon eof, false upon closing parenthesis.  */
+   DELIM can be either token_type_rparen or token_type_rbracket, or
+   token_type_eof to accept both.
+   Return true upon eof, false upon closing parenthesis or bracket.  */
 static bool
-extract_parenthesized (message_list_ty *mlp,
-                      flag_context_ty outer_context,
-                      flag_context_list_iterator_ty context_iter,
-                      struct arglist_parser *argparser)
+extract_balanced (message_list_ty *mlp,
+                 token_type_ty delim,
+                 flag_context_ty outer_context,
+                 flag_context_list_iterator_ty context_iter,
+                 struct arglist_parser *argparser)
 {
   /* Current argument number.  */
   int arg = 1;
@@ -1720,9 +1725,10 @@ extract_parenthesized (message_list_ty *mlp,
          continue;
 
        case token_type_lparen:
-         if (extract_parenthesized (mlp, inner_context, next_context_iter,
-                                    arglist_parser_alloc (mlp,
-                                                          state ? next_shapes : NULL)))
+         if (extract_balanced (mlp, token_type_rparen,
+                               inner_context, next_context_iter,
+                               arglist_parser_alloc (mlp,
+                                                     state ? next_shapes : NULL)))
            {
              xgettext_current_source_encoding = po_charset_utf8;
              arglist_parser_done (argparser, arg);
@@ -1734,10 +1740,16 @@ extract_parenthesized (message_list_ty *mlp,
          continue;
 
        case token_type_rparen:
-         xgettext_current_source_encoding = po_charset_utf8;
-         arglist_parser_done (argparser, arg);
-         xgettext_current_source_encoding = xgettext_current_file_source_encoding;
-         return false;
+         if (delim == token_type_rparen || delim == token_type_eof)
+           {
+             xgettext_current_source_encoding = po_charset_utf8;
+             arglist_parser_done (argparser, arg);
+             xgettext_current_source_encoding = xgettext_current_file_source_encoding;
+             return false;
+           }
+         next_context_iter = null_context_list_iterator;
+         state = 0;
+         continue;
 
        case token_type_comma:
          arg++;
@@ -1749,6 +1761,32 @@ extract_parenthesized (message_list_ty *mlp,
          state = 0;
          continue;
 
+       case token_type_lbracket:
+         if (extract_balanced (mlp, token_type_rbracket,
+                               null_context, null_context_list_iterator,
+                               arglist_parser_alloc (mlp, NULL)))
+           {
+             xgettext_current_source_encoding = po_charset_utf8;
+             arglist_parser_done (argparser, arg);
+             xgettext_current_source_encoding = xgettext_current_file_source_encoding;
+             return true;
+           }
+         next_context_iter = null_context_list_iterator;
+         state = 0;
+         continue;
+
+       case token_type_rbracket:
+         if (delim == token_type_rbracket || delim == token_type_eof)
+           {
+             xgettext_current_source_encoding = po_charset_utf8;
+             arglist_parser_done (argparser, arg);
+             xgettext_current_source_encoding = xgettext_current_file_source_encoding;
+             return false;
+           }
+         next_context_iter = null_context_list_iterator;
+         state = 0;
+         continue;
+
        case token_type_string:
          {
            lex_pos_ty pos;
@@ -1825,10 +1863,11 @@ extract_python (FILE *f,
 
   init_keywords ();
 
-  /* Eat tokens until eof is seen.  When extract_parenthesized returns
+  /* Eat tokens until eof is seen.  When extract_balanced returns
      due to an unbalanced closing parenthesis, just restart it.  */
-  while (!extract_parenthesized (mlp, null_context, null_context_list_iterator,
-                                arglist_parser_alloc (mlp, NULL)))
+  while (!extract_balanced (mlp, token_type_eof,
+                           null_context, null_context_list_iterator,
+                           arglist_parser_alloc (mlp, NULL)))
     ;
 
   fp = NULL;