]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext for Scheme: Understand guile 2.0 comment syntax, part 2.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Oct 2011 22:06:39 +0000 (00:06 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Oct 2011 22:06:39 +0000 (00:06 +0200)
NEWS
gettext-tools/src/ChangeLog
gettext-tools/src/x-scheme.c

diff --git a/NEWS b/NEWS
index 9c85882f8bf3eff5409f4bcc8c72d737f46299dd..515b4b53e4234c75f77782c38d7395a9fdcd78fa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 Version 0.18.2 - July 2010
 
+* xgettext now understands the block comment syntax of Guile 2.0.
+
 * libgettextpo library:
   - The initial msgstr of a new message is now "", not NULL.
   - Bug fixes in the functions po_message_is_range, po_file_check_all,
index 8392394b6a26b637f7eeec6ac13f3fc497efafcc..e2ed7bb5229563b5c6c37ad8c4fd2133d5010e8c 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-04  Bruno Haible  <bruno@clisp.org>
+
+       xgettext for Scheme: Understand guile 2.0 comment syntax, part 2.
+       * x-scheme.c (read_object): Extract and don't ignore block comments.
+       Understand the #|...|# syntax of SRFI-30. (Code copied from x-lisp.c.)
+
 2011-10-04  Bruno Haible  <bruno@clisp.org>
 
        xgettext for Scheme: Understand guile 2.0 comment syntax, part 1.
index 3b7beeb2dafc7dfe6782a9ebcff31425f7293066..1ddcb2db10f136fd2d7fb3b6b47ac49311b12829 100644 (file)
@@ -60,7 +60,7 @@
    - The syntax code assigned to each character, and how tokens are built
      up from characters (single escape, multiple escape etc.).
 
-   - Comment syntax: ';' and '#! ... !#'.
+   - Comment syntax: ';' and '#! ... !#' and '#| ... |#' (may be nested).
 
    - String syntax: "..." with single escapes.
 
@@ -935,21 +935,120 @@ read_object (struct object *op, flag_context_ty outer_context)
                 }
 
               case '!':
-                /* Block comment '#! ... !#'.  We don't extract it
-                   because it's only used to introduce scripts on Unix.  */
+                /* Block comment '#! ... !#'.  See
+                   <http://www.gnu.org/software/guile/manual/html_node/Block-Comments.html>.  */
                 {
-                  int last = 0;
+                  int c;
 
+                  comment_start ();
+                  c = do_getc ();
                   for (;;)
                     {
-                      c = do_getc ();
                       if (c == EOF)
-                        /* EOF is not allowed here.  But be tolerant.  */
                         break;
-                      if (last == '!' && c == '#')
+                      if (c == '!')
+                        {
+                          c = do_getc ();
+                          if (c == EOF)
+                            break;
+                          if (c == '#')
+                            {
+                              comment_line_end (0);
+                              break;
+                            }
+                          else
+                            comment_add ('!');
+                        }
+                      else
+                        {
+                          /* We skip all leading white space.  */
+                          if (!(buflen == 0 && (c == ' ' || c == '\t')))
+                            comment_add (c);
+                          if (c == '\n')
+                            {
+                              comment_line_end (1);
+                              comment_start ();
+                            }
+                          c = do_getc ();
+                        }
+                    }
+                  if (c == EOF)
+                    {
+                      /* EOF not allowed here.  But be tolerant.  */
+                      op->type = t_eof;
+                      return;
+                    }
+                  last_comment_line = line_number;
+                  continue;
+                }
+
+              case '|':
+                /* Block comment '#| ... |#'.  See
+                   <http://www.gnu.org/software/guile/manual/html_node/Block-Comments.html>
+                   and <http://srfi.schemers.org/srfi-30/srfi-30.html>.  */
+                {
+                  int depth = 0;
+                  int c;
+
+                  comment_start ();
+                  c = do_getc ();
+                  for (;;)
+                    {
+                      if (c == EOF)
                         break;
-                      last = c;
+                      if (c == '|')
+                        {
+                          c = do_getc ();
+                          if (c == EOF)
+                            break;
+                          if (c == '#')
+                            {
+                              if (depth == 0)
+                                {
+                                  comment_line_end (0);
+                                  break;
+                                }
+                              depth--;
+                              comment_add ('|');
+                              comment_add ('#');
+                              c = do_getc ();
+                            }
+                          else
+                            comment_add ('|');
+                        }
+                      else if (c == '#')
+                        {
+                          c = do_getc ();
+                          if (c == EOF)
+                            break;
+                          comment_add ('#');
+                          if (c == '|')
+                            {
+                              depth++;
+                              comment_add ('|');
+                              c = do_getc ();
+                            }
+                        }
+                      else
+                        {
+                          /* We skip all leading white space.  */
+                          if (!(buflen == 0 && (c == ' ' || c == '\t')))
+                            comment_add (c);
+                          if (c == '\n')
+                            {
+                              comment_line_end (1);
+                              comment_start ();
+                            }
+                          c = do_getc ();
+                        }
+                    }
+                  if (c == EOF)
+                    {
+                      /* EOF not allowed here.  But be tolerant.  */
+                      op->type = t_eof;
+                      return;
                     }
+                  last_comment_line = line_number;
                   continue;
                 }