[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gettext] [PATCH] Add support for php nowdocs syntax (like heredoc)
From: |
Andreas Stricker |
Subject: |
[bug-gettext] [PATCH] Add support for php nowdocs syntax (like heredoc) |
Date: |
Wed, 4 Apr 2012 09:41:41 +0200 |
Reported-by: Byrial Jensen <address@hidden>
---
gettext-tools/src/x-php.c | 15 ++++++-
gettext-tools/tests/Makefile.am | 2 +-
gettext-tools/tests/xgettext-php-5 | 79 ++++++++++++++++++++++++++++++++++++
3 files changed, 93 insertions(+), 3 deletions(-)
create mode 100755 gettext-tools/tests/xgettext-php-5
diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c
index 4781005..b2174f8 100644
--- a/gettext-tools/src/x-php.c
+++ b/gettext-tools/src/x-php.c
@@ -1161,12 +1161,18 @@ phase4_get (token_ty *tp)
int c3 = phase1_getc ();
if (c3 == '<')
{
- /* Start of here document.
+ /* Start of here and now document.
Parse whitespace, then label, then newline. */
do
c = phase3_getc ();
while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
+ /* a nowdoc encloses the label into single quotes */
+ if (c == '\'')
+ {
+ c = phase3_getc ();
+ }
+
bufpos = 0;
do
{
@@ -1178,9 +1184,14 @@ phase4_get (token_ty *tp)
buffer[bufpos++] = c;
c = phase3_getc ();
}
- while (c != EOF && c != '\n' && c != '\r');
+ while (c != EOF && c != '\n' && c != '\r' && c != '\'');
/* buffer[0..bufpos-1] now contains the label. */
+ if (c == '\'') /* eat the nowdoc single quote */
+ {
+ c = phase3_getc ();
+ }
+
/* Now skip the here document. */
for (;;)
{
diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am
index f875913..c6b5110 100644
--- a/gettext-tools/tests/Makefile.am
+++ b/gettext-tools/tests/Makefile.am
@@ -87,7 +87,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5
gettext-6 gettext-7 \
xgettext-objc-1 xgettext-objc-2 \
xgettext-perl-1 xgettext-perl-2 xgettext-perl-3 xgettext-perl-4 \
xgettext-perl-5 xgettext-perl-6 xgettext-perl-7 xgettext-perl-8 \
- xgettext-php-1 xgettext-php-2 xgettext-php-3 xgettext-php-4 \
+ xgettext-php-1 xgettext-php-2 xgettext-php-3 xgettext-php-4
xgettext-php-5 \
xgettext-po-1 \
xgettext-properties-1 \
xgettext-python-1 xgettext-python-2 xgettext-python-3 \
diff --git a/gettext-tools/tests/xgettext-php-5
b/gettext-tools/tests/xgettext-php-5
new file mode 100755
index 0000000..9e5febf
--- /dev/null
+++ b/gettext-tools/tests/xgettext-php-5
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+# Test PHP support: nowdocs documents.
+# This is basically the same test as for heredocs
+# See the php manual for details:
+#
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles xg-ph-5.php"
+cat <<EOF > xg-ph-5.php
+<?
+echo _("Egyptians");
+echo <<<'EOD'
+Ramses
+EOD;
+echo _("Babylonians");
+echo <<<'EOD'
+Nebukadnezar
+EOD
+echo _("Assyrians");
+echo <<<'EOD'
+Assurbanipal
+EOT
+echo _("Persians");
+echo <<<'EOD'
+Darius
+
+echo _("Greeks");
+echo <<<'EOD'
+Alexander
+
+EOD
+echo _("Romans");
+echo <<<'EOD'
+Augustus
+ EOD
+echo _("Goths");
+echo <<<'EOD'
+Odoakar
+Theoderich
+EOD
+echo _("Franks");
+?>
+EOF
+
+tmpfiles="$tmpfiles xg-ph-5.tmp.po xg-ph-5.po"
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --no-location -d xg-ph-5.tmp xg-ph-5.php
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+LC_ALL=C tr -d '\r' < xg-ph-5.tmp.po > xg-ph-5.po
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+tmpfiles="$tmpfiles xg-ph-5.ok"
+cat <<EOF > xg-ph-5.ok
+msgid "Egyptians"
+msgstr ""
+
+msgid "Babylonians"
+msgstr ""
+
+msgid "Assyrians"
+msgstr ""
+
+msgid "Romans"
+msgstr ""
+
+msgid "Franks"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-ph-5.ok xg-ph-5.po
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result
--
1.7.9.2