support named characters
This commit is contained in:
parent
6de5bc7550
commit
7f35eb7daa
12
src/port.c
12
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));
|
||||
|
|
18
src/scan.l
18
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);
|
||||
}
|
||||
<CHAR>alarm { yylvalp->c = '\a'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>backspace { yylvalp->c = '\b'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>delete { yylvalp->c = 0x7f; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>escape { yylvalp->c = '\e'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>newline { yylvalp->c = '\n'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>null { yylvalp->c = '\0'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>return { yylvalp->c = '\r'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>space { yylvalp->c = ' '; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>tab { yylvalp->c = '\t'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>. { yylvalp->c = yytext[0]; BEGIN(INITIAL); return tCHAR; }
|
||||
|
||||
"#u8(" {
|
||||
BEGIN(BYTEVECTOR);
|
||||
|
|
Loading…
Reference in New Issue