/* xgettext Python backend.
- Copyright (C) 2002-2003, 2005-2011 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc.
This file was written by Bruno Haible <haible@clisp.cons.org>, 2002.
token_type_rbracket, /* ] */
token_type_string, /* "abc", 'abc', """abc""", '''abc''' */
token_type_symbol, /* symbol, number */
+ token_type_plus, /* + */
token_type_other /* misc. operator */
};
typedef enum token_type_ty token_type_ty;
int line_number;
};
+/* Free the memory pointed to by a 'struct token_ty'. */
+static inline void
+free_token (token_ty *tp)
+{
+ if (tp->type == token_type_string || tp->type == token_type_symbol)
+ free (tp->string);
+ if (tp->type == token_type_string)
+ drop_reference (tp->comment);
+}
+
/* There are two different input syntaxes for strings, "abc" and r"abc",
and two different input syntaxes for Unicode strings, u"abc" and ur"abc".
tp->type = (c == ']' ? token_type_rbracket : token_type_other);
return;
+ case '+':
+ tp->type = token_type_plus;
+ return;
+
default:
/* We could carefully recognize each of the 2 and 3 character
operators, but it is not necessary, as we only need to recognize
x_python_lex (token_ty *tp)
{
phase5_get (tp);
- if (tp->type != token_type_string)
- return;
- for (;;)
+ if (tp->type == token_type_string)
{
- token_ty tmp;
- size_t len;
+ char *sum = tp->string;
+ size_t sum_len = strlen (sum);
- phase5_get (&tmp);
- if (tmp.type != token_type_string)
+ for (;;)
{
- phase5_unget (&tmp);
- return;
+ token_ty token2, *tp2 = NULL;
+
+ phase5_get (&token2);
+ switch (token2.type)
+ {
+ case token_type_plus:
+ {
+ token_ty token3;
+
+ phase5_get (&token3);
+ if (token3.type == token_type_string)
+ {
+ free_token (&token2);
+ tp2 = &token3;
+ }
+ else
+ phase5_unget (&token3);
+ }
+ break;
+ case token_type_string:
+ tp2 = &token2;
+ break;
+ default:
+ break;
+ }
+
+ if (tp2)
+ {
+ char *addend = tp2->string;
+ size_t addend_len = strlen (addend);
+
+ sum = (char *) xrealloc (sum, sum_len + addend_len + 1);
+ memcpy (sum + sum_len, addend, addend_len + 1);
+ sum_len += addend_len;
+
+ free_token (tp2);
+ continue;
+ }
+ phase5_unget (&token2);
+ break;
}
- len = strlen (tp->string);
- tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1);
- strcpy (tp->string + len, tmp.string);
- free (tmp.string);
+ tp->string = sum;
}
}
xgettext_current_source_encoding = xgettext_current_file_source_encoding;
return true;
+ case token_type_plus:
case token_type_other:
next_context_iter = null_context_list_iterator;
state = 0;