Re: [PATCH] Implement per-port reader options and #!fold-case

2012-10-16 Thread Ludovic Courtès
Hi,

Mark H Weaver  skribis:

> From 005465769504c4173f3469d7d3958bb0945d1e3b Mon Sep 17 00:00:00 2001
> From: Mark H Weaver 
> Date: Sat, 13 Oct 2012 20:28:27 -0400
> Subject: [PATCH 1/3] Improve formatting of options help given long option
>  names
>
> * module/ice-9/boot-9.scm (define-option-interface): When printing
>   options help, e.g. for (read-options 'help), expand the width of the
>   first column by another tab stop, to accommodate option names of up to
>   23 characters.

OK.

> From f7c40bfde4e27c6ae1cc0bc346aff07907b54f1d Mon Sep 17 00:00:00 2001
> From: Mark H Weaver 
> Date: Sat, 13 Oct 2012 20:41:45 -0400
> Subject: [PATCH 2/3] Remove prototype for scm_read_token, which does not
>  exist.
>
> * libguile/read.h: Remove prototype for scm_read_token.

OK.

I’m leaving the other path aside while the other thread is in progress.

Thanks!

Ludo’.




[PATCH] Implement per-port reader options and #!fold-case

2012-10-14 Thread Mark H Weaver
Hello all,

Here's a patch set to implement per-port reader options in 2.0.  It also
implements the "#!fold-case" and "#!no-fold-case" reader directives from
the R7RS draft.

The first two patches are cleanups for minor problems I noticed while
working on the last patch, which is the interesting one.

Comments and suggestions solicited.

 Mark

>From 005465769504c4173f3469d7d3958bb0945d1e3b Mon Sep 17 00:00:00 2001
From: Mark H Weaver 
Date: Sat, 13 Oct 2012 20:28:27 -0400
Subject: [PATCH 1/3] Improve formatting of options help given long option
 names

* module/ice-9/boot-9.scm (define-option-interface): When printing
  options help, e.g. for (read-options 'help), expand the width of the
  first column by another tab stop, to accommodate option names of up to
  23 characters.
---
 module/ice-9/boot-9.scm |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index cf8252a..d679f6e 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -2850,8 +2850,11 @@ module '(ice-9 q) '(make-q q-length))}."
 (lambda (option)
   (apply (lambda (name value documentation)
(display name)
-   (if (< (string-length (symbol->string name)) 8)
-   (display #\tab))
+   (let ((len (string-length (symbol->string name
+ (when (< len 16)
+   (display #\tab)
+   (when (< len 8)
+ (display #\tab
(display #\tab)
(display value)
(display #\tab)
-- 
1.7.10.4

>From f7c40bfde4e27c6ae1cc0bc346aff07907b54f1d Mon Sep 17 00:00:00 2001
From: Mark H Weaver 
Date: Sat, 13 Oct 2012 20:41:45 -0400
Subject: [PATCH 2/3] Remove prototype for scm_read_token, which does not
 exist.

* libguile/read.h: Remove prototype for scm_read_token.
---
 libguile/read.h |1 -
 1 file changed, 1 deletion(-)

diff --git a/libguile/read.h b/libguile/read.h
index 4bd08fa..3c47afd 100644
--- a/libguile/read.h
+++ b/libguile/read.h
@@ -54,7 +54,6 @@ SCM_API SCM scm_sym_dot;
 
 SCM_API SCM scm_read_options (SCM setting);
 SCM_API SCM scm_read (SCM port);
-SCM_API size_t scm_read_token (int ic, SCM * tok_buf, SCM port, int weird);
 SCM_API SCM scm_read_hash_extend (SCM chr, SCM proc);
 SCM_INTERNAL char *scm_i_scan_for_encoding (SCM port);
 SCM_API SCM scm_file_encoding (SCM port);
-- 
1.7.10.4

>From a771be5c83a97ea728ba34e19114c966164e4dc2 Mon Sep 17 00:00:00 2001
From: Mark H Weaver 
Date: Sat, 13 Oct 2012 23:02:05 -0400
Subject: [PATCH 3/3] Implement per-port reader options, #!fold-case and
 #!no-fold-case.

* libguile/ports.c (scm_new_port_table_entry): Change initial values
  in 'scm_i_port_weak_hash' from SCM_BOOL_F to SCM_EOL, for use as
  an alist, where per-port reader options can be stored.

* libguile/read.c (scm_t_read_opts): New internal C struct type.

  (set_per_port_read_option, set_per_port_case_insensitive_p,
  init_read_options): New internal static functions.

  (CHAR_IS_R5RS_DELIMITER, CHAR_IS_DELIMITER): Move the '[' and ']'
  delimiters from CHAR_IS_R5RS_DELIMITER to CHAR_IS_DELIMITER.  Consult
  'opts' (assumed to be a local variable) to determine whether square
  brackets are delimiters.

  (scm_read): Call 'init_read_options' to initialize a local struct of
  type 'scm_t_read_opts'.  A pointer to this struct is passed down to
  all reader helper functions that need it.

  (flush_ws, maybe_annotate_source, read_complete_token, read_token,
  scm_read_array, scm_read_bytevector, scm_read_character,
  scm_read_commented_expression, scm_read_expression,
  scm_read_guile_bit_vector, scm_read_keyword,
  scm_read_mixed_case_symbol, scm_read_nil, scm_read_number,
  scm_read_number_and_radix, scm_read_quote, scm_read_sexp,
  scm_read_sharp, scm_read_sharp_extension, scm_read_shebang,
  scm_read_srfi4_vector, scm_read_string, scm_read_syntax,
  scm_read_vector): Add 'opts' as an additional parameter, and use it to
  look up read options.  Previously the global read options were
  consulted directly.

* doc/ref/api-evaluation.texi (Case Sensitivity, Scheme Read): Mention
  the existence of per-port reader options, and the reader directives
  #!fold-case and #!no-fold-case.

* test-suite/tests/reader.test ("per-port-read-options"): Add tests.
---
 doc/ref/api-evaluation.texi  |   23 ++-
 libguile/ports.c |5 +-
 libguile/read.c  |  422 +-
 test-suite/tests/reader.test |   13 ++
 4 files changed, 323 insertions(+), 140 deletions(-)

diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi
index 6112832..9eccb39 100644
--- a/doc/ref/api-evaluation.texi
+++ b/doc/ref/api-evaluation.texi
@@ -254,6 +254,8 @@ Encoding of Source Files}.
 
 @node Case Sen