]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Improve interpretation of the [ ] operators.
authorBruno Haible <bruno@clisp.org>
Sat, 17 Mar 2007 12:00:22 +0000 (12:00 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:43 +0000 (12:14 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/x-php.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/xgettext-php-1

index 815854309b08043cefcb283435e2bda99da8dd41..863c2cd60caba0c879ac6e600bc87427cf862bb2 100644 (file)
@@ -1,3 +1,13 @@
+2007-03-17  Bruno Haible  <bruno@clisp.org>
+
+       * x-php.c (enum token_type_ty): New values token_type_lbracket,
+       token_type_rbracket.
+       (x_php_lex): 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_php): Update.
+       Reported by Robert Vock <RobertVock@gmx.de>.
+
 2007-03-10  Bruno Haible  <bruno@clisp.org>
 
        * msginit.c (get_user_fullname): Reduce scope of local variables.
index b25770451ea3ce5836f87c4d1a5e397ea8639f75..ccbd1758ecf749350ae51b0d77d7e398254a1150 100644 (file)
@@ -739,6 +739,8 @@ enum token_type_ty
   token_type_lparen,           /* ( */
   token_type_rparen,           /* ) */
   token_type_comma,            /* , */
+  token_type_lbracket,         /* [ */
+  token_type_rbracket,         /* ] */
   token_type_string_literal,   /* "abc" */
   token_type_symbol,           /* symbol, number */
   token_type_other             /* misc. operator */
@@ -1092,6 +1094,14 @@ x_php_lex (token_ty *tp)
          tp->type = token_type_comma;
          return;
 
+       case '[':
+         tp->type = token_type_lbracket;
+         return;
+
+       case ']':
+         tp->type = token_type_rbracket;
+         return;
+
        case '<':
          {
            int c2 = phase1_getc ();
@@ -1261,14 +1271,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.
+   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.  */
 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;
@@ -1317,9 +1330,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)))
            {
              arglist_parser_done (argparser, arg);
              return true;
@@ -1329,8 +1343,14 @@ extract_parenthesized (message_list_ty *mlp,
          continue;
 
        case token_type_rparen:
-         arglist_parser_done (argparser, arg);
-         return false;
+         if (delim == token_type_rparen || delim == token_type_eof)
+           {
+             arglist_parser_done (argparser, arg);
+             return false;
+           }
+         next_context_iter = null_context_list_iterator;
+         state = 0;
+         continue;
 
        case token_type_comma:
          arg++;
@@ -1342,6 +1362,25 @@ 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)))
+           {
+             arglist_parser_done (argparser, arg);
+             return true;
+           }
+
+       case token_type_rbracket:
+         if (delim == token_type_rbracket || delim == token_type_eof)
+           {
+             arglist_parser_done (argparser, arg);
+             return false;
+           }
+         next_context_iter = null_context_list_iterator;
+         state = 0;
+         continue;
+
        case token_type_string_literal:
          {
            lex_pos_ty pos;
@@ -1400,10 +1439,11 @@ extract_php (FILE *f,
   /* Initial mode is HTML mode, not PHP mode.  */
   skip_html ();
 
-  /* 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)))
     ;
 
   /* Close scanner.  */
index 97409a20635f6af63b3e93ed8796328586295e23..9b435b42edd5e47c91b2f3c734c4286691852753 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-17  Bruno Haible  <bruno@clisp.org>
+
+       * xgettext-php-1: Test that strings [ ] are not extracted for an outer
+       gettext call.
+
 2007-02-19  Bruno Haible  <bruno@clisp.org>
 
        * tstgettext.c: Don't include exit.h.
index 050f15cf454846a19dee2909dcf4288f2137cabb..e143cd96db51acc5e002c750f11d1ce4850a7d55 100755 (executable)
@@ -20,6 +20,8 @@ echo _("Hey Jude");
      Nickname of the Beatles
 */
 echo _("The Fabulous Four");
+// This will not be extracted.
+echo _(table["key"]);
 ?>
 EOF