]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Scheme: Understand both '-L Scheme' and '-L Guile'.
authorBruno Haible <bruno@clisp.org>
Fri, 16 Aug 2024 19:05:47 +0000 (21:05 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 16 Aug 2024 19:05:47 +0000 (21:05 +0200)
* gettext-tools/src/x-scheme.h (EXTENSIONS_SCHEME): Associate the language
Guile, not Scheme, with the extension .scm.
(SCANNERS_SCHEME): Add info about the 'Guile' language.
(extract_guile): New declaration.
* gettext-tools/src/x-scheme.c (follow_guile): New variable.
(extract_whole_file): Renamed from extract_scheme.
(extract_scheme, extract_guile): New functions.
* gettext-tools/src/xgettext.c (usage): List Guile as a possible argument for
the '-L' option.
* gettext-tools/doc/xgettext.texi: Document 'Guile' as possible argument for
the '-L' option.
* gettext-tools/doc/lang-scheme.texi (Scheme): Explain the difference between
'-L Scheme' and '-L Guile'.
* NEWS: Mention the change.

NEWS
gettext-tools/doc/lang-scheme.texi
gettext-tools/doc/xgettext.texi
gettext-tools/src/x-scheme.c
gettext-tools/src/x-scheme.h
gettext-tools/src/xgettext.c

diff --git a/NEWS b/NEWS
index ecbc450649abdce5b36f748025c27fedc24b3023..b77299356dbfa99b6a351bb09af5a0ea44016f78 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,13 @@ Version 0.23 - August 2024
     o xgettext now assumes source code for Python 3 rather than Python 2.
       This affects the interpretation of escape sequences in string literals.
     o xgettext now recognizes the f-string syntax.
+  - Scheme: xgettext now supports the option '-L Guile' as an alternative to
+    '-L Scheme'.  They are nearly equivalent.  They differ in the interpretation
+    of escape sequences in string literals: While 'xgettext -L Scheme' assumes
+    the R6RS and R7RS syntax of string literals, 'xgettext -L Guile' assumes
+    the syntax of string literals understood by Guile 2.x and 3.0 (without
+    command-line option '--r6rs' or '--r7rs', and before a '#!r6rs' directive
+    is seen).
   - Java: Improved recognition of format strings when the String.formatted
     method is used.
   - Vala: Improved recognition of format strings when the string.printf method
index ca948589327ae0008b876394dfb1e46cd1c058e7..fd4fa7dbb0372c2fa28ba7b29ddadaddd7b72e8d 100644 (file)
@@ -1,10 +1,11 @@
 @c This file is part of the GNU gettext manual.
-@c Copyright (C) 1995-2020 Free Software Foundation, Inc.
+@c Copyright (C) 1995-2024 Free Software Foundation, Inc.
 @c See the file gettext.texi for copying conditions.
 
 @node Scheme
 @subsection GNU guile - Scheme
 @cindex Scheme
+@cindex Guile
 @cindex guile
 
 @table @asis
@@ -42,7 +43,24 @@ guile-2.0
 use
 
 @item Extractor
-@code{xgettext -k_}
+@code{xgettext -L Guile -k_}
+
+@cindex Scheme
+@cindex Guile
+@samp{xgettext -L Scheme} and @samp{xgettext -L Guile} are nearly equivalent.
+They differ in the interpretation of escape sequences in string literals:
+While @samp{xgettext -L Scheme} assumes the
+@uref{https://www.r6rs.org/,,R6RS} and
+@uref{https://standards.scheme.org/corrected-r7rs/r7rs.html,,R7RS}
+syntax of string literals,
+@samp{xgettext -L Guile} assumes the syntax of string literals
+understood by Guile 2.x and 3.0
+(without command-line option @code{--r6rs} or @code{--r7rs},
+and before a @code{#!r6rs} directive is seen).
+After a @code{#!r6rs} directive,
+there is no difference any more
+between @samp{xgettext -L Scheme} and @samp{xgettext -L Guile}
+for the rest of the file.
 
 @item Formatting with positions
 @c @code{format "~1@@*~D ~0@@*~D~2@@*"}, requires @code{(use-modules (ice-9 format))}
index 367aad15323924e3f7478530b1adaa66b533fcda..3e2258dcc5c7a0350619af2abc650f71169f54c9 100644 (file)
@@ -1,5 +1,5 @@
 @c This file is part of the GNU gettext manual.
-@c Copyright (C) 1995-2023 Free Software Foundation, Inc.
+@c Copyright (C) 1995-2024 Free Software Foundation, Inc.
 @c See the file gettext.texi for copying conditions.
 
 @pindex xgettext
@@ -75,6 +75,7 @@ is written to standard output.
 Specifies the language of the input files.  The supported languages
 are @code{C}, @code{C++}, @code{ObjectiveC}, @code{PO}, @code{Shell},
 @code{Python}, @code{Lisp}, @code{EmacsLisp}, @code{librep}, @code{Scheme},
+@code{Guile},
 @code{Smalltalk}, @code{Java}, @code{JavaProperties}, @code{C#}, @code{awk},
 @code{YCP}, @code{Tcl}, @code{Perl}, @code{PHP}, @code{Ruby},
 @code{GCC-source}, @code{NXStringTable}, @code{RST}, @code{RSJ}, @code{Glade},
@@ -305,7 +306,7 @@ For EmacsLisp: @code{_}.
 For librep: @code{_}.
 
 @item
-For Scheme: @code{gettext}, @code{ngettext:1,2}, @code{gettext-noop}.
+For Scheme and Guile: @code{gettext}, @code{ngettext:1,2}, @code{gettext-noop}.
 
 @item
 For Java: @code{GettextResource.gettext:2},
@@ -405,8 +406,8 @@ translators cannot accidentally use format string directives that would
 lead to a crash at runtime.
 @*
 This option has an effect with most languages, namely C, C++, ObjectiveC,
-Shell, Python, Lisp, EmacsLisp, librep, Scheme, Java, C#, awk, YCP, Tcl, Perl, PHP,
-GCC-source, Lua, JavaScript, Vala.
+Shell, Python, Lisp, EmacsLisp, librep, Scheme, Guile, Java, C#, awk,
+YCP, Tcl, Perl, PHP, GCC-source, Lua, JavaScript, Vala.
 
 @item -T
 @itemx --trigraphs
index 5300d815bc58a7d5bf383352d0f71d05f33023fa..6e84df96bab744f6fa0084d1f42c366cd9864d4f 100644 (file)
 #define _(s) gettext(s)
 
 
-/* The Scheme syntax is described in R5RS.  It is implemented in
-   guile-2.0.0/libguile/read.c.
+/* The Scheme syntax is described in R5RS and following standards:
+     - R5RS: https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/
+     - R6RS: https://www.r6rs.org/
+     - R7RS: https://standards.scheme.org/corrected-r7rs/r7rs.html
+
+   It is implemented in guile-3.0.10/libguile/read.c.
    Since we are interested only in strings and in forms similar to
         (gettext msgid ...)
    or   (ngettext msgid msgid_plural ...)
@@ -191,6 +195,10 @@ do_ungetc (int c)
 /* ========================== Reading of tokens.  ========================== */
 
 
+/* True to follow what Guile does (before a '#!r6rs' directive is seen).
+   False to follow R6RS and R7RS.  */
+static bool follow_guile;
+
 /* A token consists of a sequence of characters.  */
 struct token
 {
@@ -1411,11 +1419,11 @@ read_object (struct object *op, flag_region_ty *outer_region)
 }
 
 
-void
-extract_scheme (FILE *f,
-                const char *real_filename, const char *logical_filename,
-                flag_context_list_table_ty *flag_table,
-                msgdomain_list_ty *mdlp)
+static void
+extract_whole_file (FILE *f,
+                    const char *real_filename, const char *logical_filename,
+                    flag_context_list_table_ty *flag_table,
+                    msgdomain_list_ty *mdlp)
 {
   mlp = mdlp->item[0]->messages;
 
@@ -1453,3 +1461,23 @@ extract_scheme (FILE *f,
   logical_file_name = NULL;
   line_number = 0;
 }
+
+void
+extract_scheme (FILE *f,
+                const char *real_filename, const char *logical_filename,
+                flag_context_list_table_ty *flag_table,
+                msgdomain_list_ty *mdlp)
+{
+  follow_guile = false;
+  extract_whole_file (f, real_filename, logical_filename, flag_table, mdlp);
+}
+
+void
+extract_guile (FILE *f,
+               const char *real_filename, const char *logical_filename,
+               flag_context_list_table_ty *flag_table,
+               msgdomain_list_ty *mdlp)
+{
+  follow_guile = true;
+  extract_whole_file (f, real_filename, logical_filename, flag_table, mdlp);
+}
index cff03ac21f82dfe7fd66486b69b01ac779e66682..9a3d372eaaec2189c390e32c000edaac160595fd 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext Scheme backend.
-   Copyright (C) 2004, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
+   Copyright (C) 2004-2024 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2004.
 
    This program is free software: you can redistribute it and/or modify
@@ -28,11 +28,13 @@ extern "C" {
 
 
 #define EXTENSIONS_SCHEME \
-  { "scm",       "Scheme"     },                                        \
+  { "scm",       "Guile"      },                                        \
 
 #define SCANNERS_SCHEME \
   { "Scheme",           extract_scheme, NULL,                             \
                         &flag_table_scheme, &formatstring_scheme, NULL }, \
+  { "Guile",            extract_guile, NULL,                              \
+                        &flag_table_scheme, &formatstring_scheme, NULL }, \
 
 /* Scan a Scheme file and add its translatable strings to mdlp.  */
 extern void extract_scheme (FILE *fp, const char *real_filename,
@@ -40,6 +42,12 @@ extern void extract_scheme (FILE *fp, const char *real_filename,
                             flag_context_list_table_ty *flag_table,
                             msgdomain_list_ty *mdlp);
 
+/* Scan a Guile file and add its translatable strings to mdlp.  */
+extern void extract_guile (FILE *fp, const char *real_filename,
+                           const char *logical_filename,
+                           flag_context_list_table_ty *flag_table,
+                           msgdomain_list_ty *mdlp);
+
 
 /* Handling of options specific to this language.  */
 
index 25179ea89fc02a0df0c2283072ce2905bdbb3e5b..a9c2f04dd1c27416711b710dd0239f0605b8de15 100644 (file)
@@ -1108,9 +1108,9 @@ Choice of input file language:\n"));
       printf (_("\
   -L, --language=NAME         recognise the specified language\n\
                                 (C, C++, ObjectiveC, PO, Shell, Python, Lisp,\n\
-                                EmacsLisp, librep, Scheme, Smalltalk, Java,\n\
-                                JavaProperties, C#, awk, YCP, Tcl, Perl, PHP,\n\
-                                Ruby, GCC-source, NXStringTable, RST, RSJ,\n\
+                                EmacsLisp, librep, Scheme, Guile, Smalltalk,\n\
+                                Java, JavaProperties, C#, awk, YCP, Tcl, Perl,\n\
+                                PHP, Ruby, GCC-source, NXStringTable, RST, RSJ,\n\
                                 Glade, Lua, JavaScript, Vala, Desktop)\n"));
       printf (_("\
   -C, --c++                   shorthand for --language=C++\n"));