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 */
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:
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;
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);
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++;
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;
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;