mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-04-27 11:40:45 -07:00
[nucl] skip whitespace in the reader
This commit is contained in:
parent
ab45a0256b
commit
5eec810592
1 changed files with 30 additions and 12 deletions
42
src/c/nucl.c
42
src/c/nucl.c
|
|
@ -345,12 +345,18 @@ comment_reader(int narg, cl_object strm, cl_object c)
|
|||
static cl_object
|
||||
lparen_reader(int narg, cl_object strm, cl_object c)
|
||||
{
|
||||
/* xxx broken recursive read */
|
||||
/* cl_object stack = nucl_accept(strm, ECL_CODE_CHAR(')')); */
|
||||
/* return nucl_stack_to_list(stack); */
|
||||
cl_object stack = nucl_read_until(strm, ')');
|
||||
ecl_stack_popu(stack);
|
||||
return ecl_cons(ECL_CODE_CHAR('L'), nucl_stack_to_string(stack));
|
||||
cl_object stack = ecl_make_stack(0), object;
|
||||
cl_object delim = ECL_CODE_CHAR(')');
|
||||
do {
|
||||
object = nucl_accept(strm, delim);
|
||||
if(Null(object))
|
||||
ecl_internal_error("Unexpected end of file");
|
||||
else if(ecl_eql(object, delim))
|
||||
break;
|
||||
else
|
||||
ecl_stack_push(stack, object);
|
||||
} while(1);
|
||||
return nucl_stack_to_list(stack);
|
||||
}
|
||||
|
||||
static cl_object
|
||||
|
|
@ -461,6 +467,21 @@ init_nucl_reader(void)
|
|||
nucl_readtable_set(rtable, ';', cat_terminating, _comment_reader);
|
||||
}
|
||||
|
||||
static cl_object
|
||||
skip_whitespace(cl_object strm, cl_object delim)
|
||||
{
|
||||
struct ecl_readtable_entry *entry = NULL;
|
||||
cl_object ch = ECL_NIL;
|
||||
do {
|
||||
ch = si_read_char(strm, delim);
|
||||
if (Null(ch) || ecl_eql(ch, delim)) return ch;
|
||||
entry = nucl_readtable_get(rtable, ECL_CHAR_CODE(ch));
|
||||
if (entry->syntax_type != cat_whitespace) {
|
||||
return ch;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
static cl_object
|
||||
nucl_accept(cl_object strm, cl_object delim)
|
||||
{
|
||||
|
|
@ -468,9 +489,9 @@ nucl_accept(cl_object strm, cl_object delim)
|
|||
cl_object stack = ecl_make_stack(0);
|
||||
cl_object ch = ECL_NIL;
|
||||
cl_object result = ECL_NIL;
|
||||
ch = si_read_char(strm, delim);
|
||||
if (ecl_eql(delim, ch)) {
|
||||
return OBJNULL;
|
||||
ch = skip_whitespace(strm, delim);
|
||||
if (Null(ch) || ecl_eql(delim, ch)) {
|
||||
return ch;
|
||||
}
|
||||
entry = nucl_readtable_get(rtable, ECL_CHAR_CODE(ch));
|
||||
switch (entry->syntax_type) {
|
||||
|
|
@ -485,9 +506,6 @@ nucl_accept(cl_object strm, cl_object delim)
|
|||
case cat_terminating:
|
||||
result = _ecl_funcall3(entry->dispatch, strm, ch);
|
||||
break;
|
||||
case cat_whitespace:
|
||||
result = OBJNULL;
|
||||
break;
|
||||
default:
|
||||
ecl_internal_error("Expecting too much, aren't we?");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue