add irritant to read error, fixing #310
This commit is contained in:
parent
760ac11549
commit
df1a7b5fd5
|
@ -10,11 +10,11 @@ static pic_value read(pic_state *pic, struct pic_port *port, int c);
|
|||
static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c);
|
||||
|
||||
PIC_NORETURN static void
|
||||
read_error(pic_state *pic, const char *msg)
|
||||
read_error(pic_state *pic, const char *msg, pic_value irritant)
|
||||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = pic_make_error(pic, pic_intern(pic, "read"), msg, pic_nil_value());
|
||||
e = pic_make_error(pic, pic_intern(pic, "read"), msg, irritant);
|
||||
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ read_uinteger(pic_state *pic, struct pic_port *port, int c)
|
|||
unsigned u = 0;
|
||||
|
||||
if (! isdigit(c)) {
|
||||
read_error(pic, "expected one or more digits");
|
||||
read_error(pic, "expected one or more digits", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
u = c - '0';
|
||||
|
@ -398,10 +398,10 @@ read_true(pic_state *pic, struct pic_port *port, int c)
|
|||
{
|
||||
if ((c = peek(pic, port)) == 'r') {
|
||||
if (! expect(pic, port, "rue")) {
|
||||
read_error(pic, "unexpected character while reading #true");
|
||||
read_error(pic, "unexpected character while reading #true", pic_nil_value());
|
||||
}
|
||||
} else if (! isdelim(c)) {
|
||||
read_error(pic, "non-delimiter character given after #t");
|
||||
read_error(pic, "non-delimiter character given after #t", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
return pic_true_value();
|
||||
|
@ -412,10 +412,10 @@ read_false(pic_state *pic, struct pic_port *port, int c)
|
|||
{
|
||||
if ((c = peek(pic, port)) == 'a') {
|
||||
if (! expect(pic, port, "alse")) {
|
||||
read_error(pic, "unexpected character while reading #false");
|
||||
read_error(pic, "unexpected character while reading #false", pic_nil_value());
|
||||
}
|
||||
} else if (! isdelim(c)) {
|
||||
read_error(pic, "non-delimiter character given after #f");
|
||||
read_error(pic, "non-delimiter character given after #f", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
return pic_false_value();
|
||||
|
@ -428,7 +428,7 @@ read_char(pic_state *pic, struct pic_port *port, int c)
|
|||
|
||||
if (! isdelim(peek(pic, port))) {
|
||||
switch (c) {
|
||||
default: read_error(pic, "unexpected character after char literal");
|
||||
default: read_error(pic, "unexpected character after char literal", pic_list1(pic, pic_char_value(c)));
|
||||
case 'a': c = '\a'; if (! expect(pic, port, "larm")) goto fail; break;
|
||||
case 'b': c = '\b'; if (! expect(pic, port, "ackspace")) goto fail; break;
|
||||
case 'd': c = 0x7F; if (! expect(pic, port, "elete")) goto fail; break;
|
||||
|
@ -453,7 +453,7 @@ read_char(pic_state *pic, struct pic_port *port, int c)
|
|||
return pic_char_value((char)c);
|
||||
|
||||
fail:
|
||||
read_error(pic, "unexpected character while reading character literal");
|
||||
read_error(pic, "unexpected character while reading character literal", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -516,7 +516,7 @@ read_pipe(pic_state *pic, struct pic_port *port, int c)
|
|||
i = 0;
|
||||
while ((HEX_BUF[i++] = (char)next(pic, port)) != ';') {
|
||||
if (i >= sizeof HEX_BUF)
|
||||
read_error(pic, "expected ';'");
|
||||
read_error(pic, "expected ';'", pic_list1(pic, pic_char_value(HEX_BUF[sizeof(HEX_BUF) - 1])));
|
||||
}
|
||||
c = (char)strtol(HEX_BUF, NULL, 16);
|
||||
break;
|
||||
|
@ -550,11 +550,11 @@ read_blob(pic_state *pic, struct pic_port *port, int c)
|
|||
}
|
||||
|
||||
if (nbits != 8) {
|
||||
read_error(pic, "unsupported bytevector bit width");
|
||||
read_error(pic, "unsupported bytevector bit width", pic_list1(pic, pic_int_value(nbits)));
|
||||
}
|
||||
|
||||
if (c != '(') {
|
||||
read_error(pic, "expected '(' character");
|
||||
read_error(pic, "expected '(' character", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
len = 0;
|
||||
|
@ -563,7 +563,7 @@ read_blob(pic_state *pic, struct pic_port *port, int c)
|
|||
while ((c = skip(pic, port, c)) != ')') {
|
||||
n = read_uinteger(pic, port, c);
|
||||
if (n < 0 || (1 << nbits) <= n) {
|
||||
read_error(pic, "invalid element in bytevector literal");
|
||||
read_error(pic, "invalid element in bytevector literal", pic_list1(pic, pic_int_value(n)));
|
||||
}
|
||||
len += 1;
|
||||
dat = pic_realloc(pic, dat, len);
|
||||
|
@ -585,12 +585,12 @@ read_undef_or_blob(pic_state *pic, struct pic_port *port, int c)
|
|||
{
|
||||
if ((c = peek(pic, port)) == 'n') {
|
||||
if (! expect(pic, port, "ndefined")) {
|
||||
read_error(pic, "unexpected character while reading #undefined");
|
||||
read_error(pic, "unexpected character while reading #undefined", pic_nil_value());
|
||||
}
|
||||
return pic_undef_value();
|
||||
}
|
||||
if (! isdigit(c)) {
|
||||
read_error(pic, "expect #undefined or #u8(...), but illegal character given");
|
||||
read_error(pic, "expect #undefined or #u8(...), but illegal character given", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
return read_blob(pic, port, 'u');
|
||||
}
|
||||
|
@ -616,7 +616,7 @@ read_pair(pic_state *pic, struct pic_port *port, int c)
|
|||
if (pic_invalid_p(read_nullable(pic, port, c))) {
|
||||
goto closing;
|
||||
}
|
||||
read_error(pic, "unmatched parenthesis");
|
||||
read_error(pic, "unmatched parenthesis", pic_nil_value());
|
||||
}
|
||||
return cdr;
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ read_label_ref(pic_state *pic, struct pic_port PIC_UNUSED(*port), int i)
|
|||
|
||||
it = kh_get(read, h, i);
|
||||
if (it == kh_end(h)) {
|
||||
read_error(pic, "label of given index not defined");
|
||||
read_error(pic, "label of given index not defined", pic_list1(pic, pic_int_value(i)));
|
||||
}
|
||||
return kh_val(h, it);
|
||||
}
|
||||
|
@ -735,13 +735,13 @@ read_label(pic_state *pic, struct pic_port *port, int c)
|
|||
if (c == '#') {
|
||||
return read_label_ref(pic, port, i);
|
||||
}
|
||||
read_error(pic, "broken label expression");
|
||||
read_error(pic, "broken label expression", pic_nil_value());
|
||||
}
|
||||
|
||||
static pic_value
|
||||
read_unmatch(pic_state *pic, struct pic_port PIC_UNUSED(*port), int PIC_UNUSED(c))
|
||||
{
|
||||
read_error(pic, "unmatched parenthesis");
|
||||
read_error(pic, "unmatched parenthesis", pic_nil_value());
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -750,11 +750,11 @@ read_dispatch(pic_state *pic, struct pic_port *port, int c)
|
|||
c = next(pic, port);
|
||||
|
||||
if (c == EOF) {
|
||||
read_error(pic, "unexpected EOF");
|
||||
read_error(pic, "unexpected EOF", pic_nil_value());
|
||||
}
|
||||
|
||||
if (pic->reader.dispatch[c] == NULL) {
|
||||
read_error(pic, "invalid character at the seeker head");
|
||||
read_error(pic, "invalid character at the seeker head", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
return pic->reader.dispatch[c](pic, port, c);
|
||||
|
@ -766,11 +766,11 @@ read_nullable(pic_state *pic, struct pic_port *port, int c)
|
|||
c = skip(pic, port, c);
|
||||
|
||||
if (c == EOF) {
|
||||
read_error(pic, "unexpected EOF");
|
||||
read_error(pic, "unexpected EOF", pic_nil_value());
|
||||
}
|
||||
|
||||
if (pic->reader.table[c] == NULL) {
|
||||
read_error(pic, "invalid character at the seeker head");
|
||||
read_error(pic, "invalid character at the seeker head", pic_list1(pic, pic_char_value(c)));
|
||||
}
|
||||
|
||||
return pic->reader.table[c](pic, port, c);
|
||||
|
|
Loading…
Reference in New Issue