+2004-02-08 Neil Jerram <neil@ossau.uklinux.net>
+
+ * read.c (scm_read_opts): New opts `elisp-vectors' and
+ `escaped-parens'.
+ (s_vector): New.
+ (scm_lreadr): Use scm_lreadparen1 instead of scm_lreadparen. Make
+ handling of elisp vector syntax dependent on SCM_ENABLE_ELISP and
+ `elisp-vectors' option instead of SCM_ELISP_READ_EXTENSIONS.
+ Allow "\(" and "\)" in strings when SCM_ENABLE_ELISP defined and
+ `escaped-parens' option set.
+ (scm_read_token): If elisp vector syntax active, disallow [ and ]
+ in tokens.
+ (scm_lreadparen): Rewrite as interface to scm_lreadparen1.
+ (scm_lreadparen1): New.
+
+ * read.h: Remove conditionally compiled last arg to
+ scm_lreadparen.
+ (SCM_ELISP_VECTORS_P, SCM_ESCAPED_PARENS_P): New.
+
2004-01-23 Han-Wen Nienhuys <hanwen@xs4all.nl>
* eval.c (m_expand_body): remove stray variable new_body.
"Convert symbols to lower case."},
{ SCM_OPTION_SCM, "keywords", SCM_UNPACK (SCM_BOOL_F),
"Style of keyword recognition: #f or 'prefix."}
+#if SCM_ENABLE_ELISP
+ ,
+ { SCM_OPTION_BOOLEAN, "elisp-vectors", 0,
+ "Support Elisp vector syntax, namely `[...]'."},
+ { SCM_OPTION_BOOLEAN, "escaped-parens", 0,
+ "Support `\\(' and `\\)' in strings."}
+#endif
};
/*
static SCM scm_get_hash_procedure(int c);
+static SCM scm_lreadparen1 (SCM *, SCM, char *, SCM *, char);
static char s_list[]="list";
+static char s_vector[]="vector";
SCM
scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
case '(':
return SCM_RECORD_POSITIONS_P
? scm_lreadrecparen (tok_buf, port, s_list, copy)
- : scm_lreadparen (tok_buf, port, s_list, copy SCM_ELISP_CLOSE);
+ : scm_lreadparen1 (tok_buf, port, s_list, copy, ')');
case ')':
scm_input_error (FUNC_NAME, port,"unexpected \")\"", SCM_EOL);
goto tryagain;
-#ifdef SCM_ELISP_READ_EXTENSIONS
+#if SCM_ENABLE_ELISP
case '[':
- p = scm_lreadparen (tok_buf, port, "vector", copy, ']');
- return SCM_NULLP (p) ? scm_nullvect : scm_vector (p);
+ if (SCM_ELISP_VECTORS_P)
+ {
+ p = scm_lreadparen1 (tok_buf, port, s_vector, copy, ']');
+ return SCM_NULLP (p) ? scm_nullvect : scm_vector (p);
+ }
+ goto read_token;
#endif
case '\'':
p = scm_sym_quote;
switch (c)
{
case '(':
- p = scm_lreadparen (tok_buf, port, "vector", copy SCM_ELISP_CLOSE);
+ p = scm_lreadparen1 (tok_buf, port, s_vector, copy, ')');
return SCM_NULLP (p) ? scm_nullvect : scm_vector (p);
case 't':
case '"':
case '\\':
break;
+#if SCM_ENABLE_ELISP
+ case '(':
+ case ')':
+ if (SCM_ESCAPED_PARENS_P)
+ break;
+ goto bad_escaped;
+#endif
case '\n':
continue;
case '0':
}
/* fallthrough */
default:
+#if SCM_ENABLE_ELISP
+ read_token:
+#endif
j = scm_read_token (c, tok_buf, port, 0);
/* fallthrough */
{
case '(':
case ')':
-#ifdef SCM_ELISP_READ_EXTENSIONS
+#if SCM_ENABLE_ELISP
case '[':
case ']':
#endif
case ';':
case SCM_WHITE_SPACES:
case SCM_LINE_INCREMENTORS:
- if (weird)
+ if (weird
+#if SCM_ENABLE_ELISP
+ || ((!SCM_ELISP_VECTORS_P) && ((c == '[') || (c == ']')))
+#endif
+ )
goto default_case;
scm_ungetc (c, port);
#endif
SCM
-scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy
-#ifdef SCM_ELISP_READ_EXTENSIONS
- , char term_char
-#else
-#define term_char ')'
-#endif
- )
+scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
+{
+ return scm_lreadparen1 (tok_buf, port, name, copy, ')');
+}
+
+static SCM
+scm_lreadparen1 (SCM *tok_buf, SCM port, char *name, SCM *copy, char term_char)
#define FUNC_NAME "scm_lreadparen"
{
SCM tmp;
return ans;
}
#undef FUNC_NAME
-#ifndef SCM_ELISP_READ_EXTENSIONS
-#undef term_char
-#endif
SCM
#define SCM_RECORD_POSITIONS_P scm_read_opts[1].val
#define SCM_CASE_INSENSITIVE_P scm_read_opts[2].val
#define SCM_KEYWORD_STYLE scm_read_opts[3].val
+#if SCM_ENABLE_ELISP
+#define SCM_ELISP_VECTORS_P scm_read_opts[4].val
+#define SCM_ESCAPED_PARENS_P scm_read_opts[5].val
+#define SCM_N_READ_OPTIONS 6
+#else
#define SCM_N_READ_OPTIONS 4
+#endif
\f
SCM_API int scm_casei_streq (char * s1, char * s2);
SCM_API SCM scm_lreadr (SCM * tok_buf, SCM port, SCM *copy);
SCM_API size_t scm_read_token (int ic, SCM * tok_buf, SCM port, int weird);
-SCM_API SCM scm_lreadparen (SCM * tok_buf, SCM port, char *name, SCM *copy
-#ifdef SCM_ELISP_READ_EXTENSIONS
- , char term_char
-#define SCM_ELISP_CLOSE , ')'
-#else
-#define SCM_ELISP_CLOSE
-#endif
- );
+SCM_API SCM scm_lreadparen (SCM * tok_buf, SCM port, char *name, SCM *copy);
SCM_API SCM scm_lreadrecparen (SCM * tok_buf, SCM port, char *name, SCM *copy);
SCM_API SCM scm_read_hash_extend (SCM chr, SCM proc);
SCM_API void scm_init_read (void);