1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-28 16:00:22 +02:00

(SCM_PRINT_KEYWORD_STYLE_I, SCM_PRINT_KEYWORD_STYLE):

New.
(sym_reader): New.
(scm_print_opts): Added "quote-keywordish-symbols" option.
(quote_keywordish_symbol): New, for evaluating the option.
(scm_print_symbol_name): Use it.
(scm_init_print): Initialize new option to sym_reader.
This commit is contained in:
Marius Vollmer 2005-09-04 21:30:01 +00:00
parent 25bdfbb6cf
commit 475fa9a5d7
2 changed files with 35 additions and 5 deletions

View file

@ -68,6 +68,8 @@ static const char *iflagnames[] =
"#nil"
};
SCM_SYMBOL (sym_reader, "reader");
scm_t_option scm_print_opts[] = {
{ SCM_OPTION_SCM, "closure-hook", SCM_UNPACK (SCM_BOOL_F),
"Hook for printing closures (should handle macros as well)." },
@ -76,7 +78,12 @@ scm_t_option scm_print_opts[] = {
{ SCM_OPTION_SCM, "highlight-prefix", (unsigned long)SCM_BOOL_F,
"The string to print before highlighted values." },
{ SCM_OPTION_SCM, "highlight-suffix", (unsigned long)SCM_BOOL_F,
"The string to print after highlighted values." }
"The string to print after highlighted values." },
{ SCM_OPTION_SCM, "quote-keywordish-symbols", (unsigned long)SCM_BOOL_F,
"How to print symbols that have a colon as their first or last character. "
"The value '#f' does not quote the colons; '#t' quotes them; "
"'reader' quotes them when the reader option 'keywords' is not '#f'."
}
};
SCM_DEFINE (scm_print_options, "print-options-interface", 0, 1, 0,
@ -267,6 +274,24 @@ print_circref (SCM port, scm_print_state *pstate, SCM ref)
/* Print the name of a symbol. */
static int
quote_keywordish_symbol (const char *str, size_t len)
{
SCM option;
/* LEN is guaranteed to be > 0.
*/
if (str[0] != ':' && str[len-1] != ':')
return 0;
option = SCM_PRINT_KEYWORD_STYLE;
if (scm_is_false (option))
return 0;
if (scm_is_eq (option, sym_reader))
return scm_is_true (SCM_PACK (SCM_KEYWORD_STYLE));
return 1;
}
void
scm_print_symbol_name (const char *str, size_t len, SCM port)
{
@ -290,9 +315,10 @@ scm_print_symbol_name (const char *str, size_t len, SCM port)
int maybe_weird = 0;
size_t mw_pos = 0;
if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ',' ||
str[0] == ':' || str[len-1] == ':' || (str[0] == '.' && len == 1) ||
scm_is_true (scm_i_mem2number(str, len, 10)))
if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ','
|| quote_keywordish_symbol (str, len)
|| (str[0] == '.' && len == 1)
|| scm_is_true (scm_i_mem2number(str, len, 10)))
{
scm_lfwrite ("#{", 2, port);
weird = 1;
@ -1146,6 +1172,8 @@ scm_init_print ()
scm_set_smob_print (scm_tc16_port_with_ps, port_with_ps_print);
#include "libguile/print.x"
scm_print_opts[SCM_PRINT_KEYWORD_STYLE_I].val = SCM_UNPACK (sym_reader);
}
/*

View file

@ -32,7 +32,9 @@ SCM_API scm_t_option scm_print_opts[];
#define SCM_PRINT_SOURCE_P ((int) scm_print_opts[1].val)
#define SCM_PRINT_HIGHLIGHT_PREFIX (SCM_PACK (scm_print_opts[2].val))
#define SCM_PRINT_HIGHLIGHT_SUFFIX (SCM_PACK (scm_print_opts[3].val))
#define SCM_N_PRINT_OPTIONS 4
#define SCM_PRINT_KEYWORD_STYLE_I 4
#define SCM_PRINT_KEYWORD_STYLE (SCM_PACK (scm_print_opts[4].val))
#define SCM_N_PRINT_OPTIONS 5
/* State information passed around during printing.
*/