unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: prj@po.cwru.edu (Paul Jarc)
Cc: guile-devel@gnu.org
Subject: Re: libguile/print.c fixes
Date: Tue, 06 May 2003 10:51:29 -0400	[thread overview]
Message-ID: <m33cjsw2k8.fsf@multivac.cwru.edu> (raw)
In-Reply-To: <87ade0zwwe.fsf@raven.i.defaultvalue.org> (Rob Browning's message of "Mon, 05 May 2003 20:28:17 -0500")

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]

Rob Browning <rlb@defaultvalue.org> wrote:
> prj@po.cwru.edu (Paul Jarc) writes:
>> Symbol names containing \ don't strictly need to be printed in
>> #{this}# style, but it would significantly simplify the code if they
>> were.  Any objections?
>
> Not sure.  It's nice to avoid the escaping when you don't need it, but
> I'm not sure how much complexity that introduces.

I guess it's not that complex, although it does introduce a
performance hit for certain long symbol names, since part of the
string is re-scanned.  This patch fixes the bugs with symbol names,
but leaves backslash handling the way it is.
	* print.c (scm_print_symbol_name): Bug fixes and comments.


paul

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: guile.patch --]
[-- Type: text/x-patch, Size: 3046 bytes --]

Index: libguile/print.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/print.c,v
retrieving revision 1.149
diff -u -r1.149 print.c
--- libguile/print.c	5 Apr 2003 20:45:17 -0000	1.149
+++ libguile/print.c	6 May 2003 14:48:58 -0000
@@ -282,27 +282,37 @@
 void
 scm_print_symbol_name (const char *str, size_t len, SCM port)
 {
-  size_t pos;
+  /* This points to the first character that has not yet been written to the
+   * port. */
+  size_t pos = 0;
+  /* This points to the character we're currently looking at. */
   size_t end;
-  int weird;
-  int maybe_weird;
+  /* If the name contains weird characters, we'll escape them with
+   * backslashes and set this flag; it indicates that we should surround the
+   * name with "#{" and "}#". */
+  int weird = 0;
+  /* Backslashes are not sufficient to make a name weird, but if a name is
+   * weird because of other characters, backslahes need to be escaped too.
+   * The first time we see a backslash, we set maybe_weird, and mw_pos points
+   * to the backslash.  Then if the name turns out to be weird, we re-process
+   * everything starting from mw_pos. */
+  int maybe_weird = 0;
   size_t mw_pos = 0;
-  
-  pos = 0;
-  weird = 0;
-  maybe_weird = 0;
-  
-  /* XXX - Lots of weird symbol names are missed, such as "12" or
-     "'a". */
+  /* If the name is purely numeric, then it's weird as a whole, even though
+   * none of the individual characters is weird.  But we won't know this
+   * until we reach the end of the name.  This flag describes the part of the
+   * name we've looked at so far. */
+  int all_digits = 1;
 
   if (len == 0)
     scm_lfwrite ("#{}#", 4, port);
-  else if (str[0] == '#' || str[0] == ':' || str[len-1] == ':')
+  else if (str[0] == '#' || str[0] == '\'' ||
+	   str[0] == ':' || str[len-1] == ':')
     {
       scm_lfwrite ("#{", 2, port);
       weird = 1;
     }
-  
+
   for (end = pos; end < len; ++end)
     switch (str[end])
       {
@@ -314,8 +324,10 @@
       case ')':
       case '"':
       case ';':
+      case '#':
       case SCM_WHITE_SPACES:
       case SCM_LINE_INCREMENTORS:
+	all_digits = 0;
       weird_handler:
 	if (maybe_weird)
 	  {
@@ -328,9 +340,7 @@
 	    weird = 1;
 	  }
 	if (pos < end)
-	  {
-	    scm_lfwrite (str + pos, end - pos, port);
-	  }
+	  scm_lfwrite (str + pos, end - pos, port);
 	{
 	  char buf[2];
 	  buf[0] = '\\';
@@ -340,6 +350,7 @@
 	pos = end + 1;
 	break;
       case '\\':
+	all_digits = 0;
 	if (weird)
 	  goto weird_handler;
 	if (!maybe_weird)
@@ -348,14 +359,18 @@
 	    mw_pos = pos;
 	  }
 	break;
-      case '}':
-      case '#':
-	if (weird)
-	  goto weird_handler;
+      case '0': case '1': case '2': case '3': case '4':
+      case '5': case '6': case '7': case '8': case '9':
 	break;
       default:
+	all_digits = 0;
 	break;
       }
+  if (all_digits)
+    {
+      scm_lfwrite ("#{", 2, port);
+      weird = 1;
+    }
   if (pos < end)
     scm_lfwrite (str + pos, end - pos, port);
   if (weird)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

  reply	other threads:[~2003-05-06 14:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-05 21:32 libguile/print.c fixes Paul Jarc
2003-05-06  1:25 ` Rob Browning
2003-05-17 19:55   ` Marius Vollmer
2003-05-06  1:28 ` Rob Browning
2003-05-06 14:51   ` Paul Jarc [this message]
2003-05-17 20:01     ` Marius Vollmer
2003-05-19 14:52       ` Paul Jarc
2003-05-19 15:04         ` Marius Vollmer
2003-06-27 15:58         ` Paul Jarc
2003-06-30 22:40           ` Paul Jarc
2003-07-22 15:27             ` patch ping (was: libguile/print.c fixes) Paul Jarc
2003-07-22 16:42               ` Marius Vollmer
2003-07-22 16:47                 ` patch ping Paul Jarc
2003-07-27 16:35                   ` Marius Vollmer
2003-07-28 16:38                     ` Paul Jarc
2003-09-15 12:39                       ` Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m33cjsw2k8.fsf@multivac.cwru.edu \
    --to=prj@po.cwru.edu \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).