mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
add reader option for parsing [] as ().
* libguile/private-options.h: * libguile/read.c (scm_read_opts, SCM_SQUARE_BRACKETS_P): Add an option for treating [ and ] as parentheses, on by default. Note that this makes them delimiters also, so [ and ] cannot appear in a symbol name, with this read option on. (scm_read_sexp): If we start with [, we end with ]. (scm_read_expression): Add case for [.
This commit is contained in:
parent
e1138ba199
commit
5afa815c9c
2 changed files with 11 additions and 3 deletions
|
@ -4,7 +4,7 @@
|
||||||
* We put this in a private header, since layout of data structures
|
* We put this in a private header, since layout of data structures
|
||||||
* is an implementation detail that we want to hide.
|
* is an implementation detail that we want to hide.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2009 Free Software Foundation, Inc.
|
* Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -96,6 +96,7 @@ SCM_API scm_t_option scm_read_opts[];
|
||||||
#define SCM_ESCAPED_PARENS_P scm_read_opts[5].val
|
#define SCM_ESCAPED_PARENS_P scm_read_opts[5].val
|
||||||
#endif
|
#endif
|
||||||
#define SCM_R6RS_ESCAPES_P scm_read_opts[6].val
|
#define SCM_R6RS_ESCAPES_P scm_read_opts[6].val
|
||||||
|
#define SCM_SQUARE_BRACKETS_P scm_read_opts[7].val
|
||||||
|
|
||||||
#if SCM_ENABLE_ELISP
|
#if SCM_ENABLE_ELISP
|
||||||
#define SCM_N_READ_OPTIONS 7
|
#define SCM_N_READ_OPTIONS 7
|
||||||
|
|
|
@ -78,6 +78,8 @@ scm_t_option scm_read_opts[] = {
|
||||||
#endif
|
#endif
|
||||||
{ SCM_OPTION_BOOLEAN, "r6rs-hex-escapes", 0,
|
{ SCM_OPTION_BOOLEAN, "r6rs-hex-escapes", 0,
|
||||||
"Use R6RS variable-length character and string hex escapes."},
|
"Use R6RS variable-length character and string hex escapes."},
|
||||||
|
{ SCM_OPTION_BOOLEAN, "square-brackets", 1,
|
||||||
|
"Treat `[' and `]' as parentheses, for R6RS compatibility."},
|
||||||
{ 0, },
|
{ 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,7 +175,8 @@ static SCM *scm_read_hash_procedures;
|
||||||
structure''). */
|
structure''). */
|
||||||
#define CHAR_IS_R5RS_DELIMITER(c) \
|
#define CHAR_IS_R5RS_DELIMITER(c) \
|
||||||
(CHAR_IS_BLANK (c) \
|
(CHAR_IS_BLANK (c) \
|
||||||
|| (c == ')') || (c == '(') || (c == ';') || (c == '"'))
|
|| (c == ')') || (c == '(') || (c == ';') || (c == '"') \
|
||||||
|
|| (SCM_SQUARE_BRACKETS_P && ((c == '[') || (c == ']'))))
|
||||||
|
|
||||||
#define CHAR_IS_DELIMITER CHAR_IS_R5RS_DELIMITER
|
#define CHAR_IS_DELIMITER CHAR_IS_R5RS_DELIMITER
|
||||||
|
|
||||||
|
@ -332,7 +335,7 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
|
||||||
register SCM tmp;
|
register SCM tmp;
|
||||||
register SCM tl, ans = SCM_EOL;
|
register SCM tl, ans = SCM_EOL;
|
||||||
SCM tl2 = SCM_EOL, ans2 = SCM_EOL, copy = SCM_BOOL_F;
|
SCM tl2 = SCM_EOL, ans2 = SCM_EOL, copy = SCM_BOOL_F;
|
||||||
static const int terminating_char = ')';
|
const int terminating_char = ((chr == '[') ? ']' : ')');
|
||||||
|
|
||||||
/* Need to capture line and column numbers here. */
|
/* Need to capture line and column numbers here. */
|
||||||
long line = SCM_LINUM (port);
|
long line = SCM_LINUM (port);
|
||||||
|
@ -1251,6 +1254,10 @@ scm_read_expression (SCM port)
|
||||||
case ';':
|
case ';':
|
||||||
(void) scm_read_semicolon_comment (chr, port);
|
(void) scm_read_semicolon_comment (chr, port);
|
||||||
break;
|
break;
|
||||||
|
case '[':
|
||||||
|
if (!SCM_SQUARE_BRACKETS_P)
|
||||||
|
return (scm_read_mixed_case_symbol (chr, port));
|
||||||
|
/* otherwise fall through */
|
||||||
case '(':
|
case '(':
|
||||||
return (scm_read_sexp (chr, port));
|
return (scm_read_sexp (chr, port));
|
||||||
case '"':
|
case '"':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue