mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-31 01:10:24 +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:
parent
25bdfbb6cf
commit
475fa9a5d7
2 changed files with 35 additions and 5 deletions
|
@ -68,6 +68,8 @@ static const char *iflagnames[] =
|
||||||
"#nil"
|
"#nil"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SCM_SYMBOL (sym_reader, "reader");
|
||||||
|
|
||||||
scm_t_option scm_print_opts[] = {
|
scm_t_option scm_print_opts[] = {
|
||||||
{ SCM_OPTION_SCM, "closure-hook", SCM_UNPACK (SCM_BOOL_F),
|
{ SCM_OPTION_SCM, "closure-hook", SCM_UNPACK (SCM_BOOL_F),
|
||||||
"Hook for printing closures (should handle macros as well)." },
|
"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,
|
{ SCM_OPTION_SCM, "highlight-prefix", (unsigned long)SCM_BOOL_F,
|
||||||
"The string to print before highlighted values." },
|
"The string to print before highlighted values." },
|
||||||
{ SCM_OPTION_SCM, "highlight-suffix", (unsigned long)SCM_BOOL_F,
|
{ 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,
|
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. */
|
/* 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
|
void
|
||||||
scm_print_symbol_name (const char *str, size_t len, SCM port)
|
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;
|
int maybe_weird = 0;
|
||||||
size_t mw_pos = 0;
|
size_t mw_pos = 0;
|
||||||
|
|
||||||
if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ',' ||
|
if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ','
|
||||||
str[0] == ':' || str[len-1] == ':' || (str[0] == '.' && len == 1) ||
|
|| quote_keywordish_symbol (str, len)
|
||||||
scm_is_true (scm_i_mem2number(str, len, 10)))
|
|| (str[0] == '.' && len == 1)
|
||||||
|
|| scm_is_true (scm_i_mem2number(str, len, 10)))
|
||||||
{
|
{
|
||||||
scm_lfwrite ("#{", 2, port);
|
scm_lfwrite ("#{", 2, port);
|
||||||
weird = 1;
|
weird = 1;
|
||||||
|
@ -1146,6 +1172,8 @@ scm_init_print ()
|
||||||
scm_set_smob_print (scm_tc16_port_with_ps, port_with_ps_print);
|
scm_set_smob_print (scm_tc16_port_with_ps, port_with_ps_print);
|
||||||
|
|
||||||
#include "libguile/print.x"
|
#include "libguile/print.x"
|
||||||
|
|
||||||
|
scm_print_opts[SCM_PRINT_KEYWORD_STYLE_I].val = SCM_UNPACK (sym_reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -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_SOURCE_P ((int) scm_print_opts[1].val)
|
||||||
#define SCM_PRINT_HIGHLIGHT_PREFIX (SCM_PACK (scm_print_opts[2].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_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.
|
/* State information passed around during printing.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue