diff --git a/src/port.c b/src/port.c index 9271b51b..2e17c8be 100644 --- a/src/port.c +++ b/src/port.c @@ -33,7 +33,17 @@ write(pic_state *pic, pic_value obj) printf("%s", pic_symbol_name(pic, pic_sym(obj))); break; case PIC_TT_CHAR: - printf("#\\%c", pic_char(obj)); + switch (pic_char(obj)) { + default: printf("#\\%c", pic_char(obj)); break; + case '\a': printf("#\\alarm"); break; + case '\b': printf("#\\backspace"); break; + case 0x7f: printf("#\\delete"); break; + case 0x1b: printf("#\\escape"); break; + case '\n': printf("#\\newline"); break; + case '\r': printf("#\\return"); break; + case ' ': printf("#\\space"); break; + case '\t': printf("#\\tab"); break; + } break; case PIC_TT_FLOAT: printf("%f", pic_float(obj)); diff --git a/src/scan.l b/src/scan.l index 55475c3b..b14ce18e 100644 --- a/src/scan.l +++ b/src/scan.l @@ -30,6 +30,9 @@ uinteger {digit}+ sign [+-]? infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0" + /* char */ +%x CHAR + /* string */ %x STRING @@ -84,10 +87,19 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0" } } -#\\. { - yylvalp->c = yytext[2]; - return tCHAR; +#\\ { + BEGIN(CHAR); } +alarm { yylvalp->c = '\a'; BEGIN(INITIAL); return tCHAR; } +backspace { yylvalp->c = '\b'; BEGIN(INITIAL); return tCHAR; } +delete { yylvalp->c = 0x7f; BEGIN(INITIAL); return tCHAR; } +escape { yylvalp->c = '\e'; BEGIN(INITIAL); return tCHAR; } +newline { yylvalp->c = '\n'; BEGIN(INITIAL); return tCHAR; } +null { yylvalp->c = '\0'; BEGIN(INITIAL); return tCHAR; } +return { yylvalp->c = '\r'; BEGIN(INITIAL); return tCHAR; } +space { yylvalp->c = ' '; BEGIN(INITIAL); return tCHAR; } +tab { yylvalp->c = '\t'; BEGIN(INITIAL); return tCHAR; } +. { yylvalp->c = yytext[0]; BEGIN(INITIAL); return tCHAR; } "#u8(" { BEGIN(BYTEVECTOR);