diff options
author | Bruno Haible <bruno@clisp.org> | 2008-08-16 10:08:53 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:15:47 +0200 |
commit | e3af853612c1398b62190e14d6e711559e0b0ef5 (patch) | |
tree | 9b4de73913121ff8d775f906624bb9f136552756 | |
parent | 25360c47bf5554419146fe65855582e393730bcd (diff) | |
download | external_gettext-e3af853612c1398b62190e14d6e711559e0b0ef5.zip external_gettext-e3af853612c1398b62190e14d6e711559e0b0ef5.tar.gz external_gettext-e3af853612c1398b62190e14d6e711559e0b0ef5.tar.bz2 |
Improve interpretation of the [ ] operators.
-rw-r--r-- | gettext-tools/src/ChangeLog | 11 | ||||
-rw-r--r-- | gettext-tools/src/x-python.c | 75 |
2 files changed, 68 insertions, 18 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 5bc89d2..85427d4 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,5 +1,16 @@ 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. 2008-08-15 Bruno Haible <bruno@clisp.org> diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index e05aca4..e12b0e9 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -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; |