cleanup
This commit is contained in:
parent
818fb41f77
commit
f0367d95a0
|
@ -24,15 +24,11 @@ enum {
|
||||||
typedef union YYSTYPE {
|
typedef union YYSTYPE {
|
||||||
int i;
|
int i;
|
||||||
double f;
|
double f;
|
||||||
struct {
|
|
||||||
char *buf;
|
|
||||||
size_t len;
|
|
||||||
} str;
|
|
||||||
char c;
|
|
||||||
struct {
|
struct {
|
||||||
char *dat;
|
char *dat;
|
||||||
size_t len, capa;
|
size_t len;
|
||||||
} blob;
|
} buf;
|
||||||
|
char c;
|
||||||
} YYSTYPE;
|
} YYSTYPE;
|
||||||
|
|
||||||
struct parser_control {
|
struct parser_control {
|
||||||
|
|
10
src/read.c
10
src/read.c
|
@ -89,7 +89,7 @@ read_datum(int tok, yyscan_t scanner)
|
||||||
|
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
case tSYMBOL:
|
case tSYMBOL:
|
||||||
return pic_symbol_value(pic_intern(pic, yylval.str.buf, yylval.str.len));
|
return pic_symbol_value(pic_intern(pic, yylval.buf.dat, yylval.buf.len));
|
||||||
|
|
||||||
case tINT:
|
case tINT:
|
||||||
return pic_int_value(yylval.i);
|
return pic_int_value(yylval.i);
|
||||||
|
@ -104,13 +104,13 @@ read_datum(int tok, yyscan_t scanner)
|
||||||
return pic_char_value(yylval.c);
|
return pic_char_value(yylval.c);
|
||||||
|
|
||||||
case tSTRING:
|
case tSTRING:
|
||||||
val = pic_obj_value(pic_str_new(pic, yylval.str.buf, yylval.str.len));
|
val = pic_obj_value(pic_str_new(pic, yylval.buf.dat, yylval.buf.len));
|
||||||
pic_free(pic, yylval.str.buf);
|
pic_free(pic, yylval.buf.dat);
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
case tBYTEVECTOR:
|
case tBYTEVECTOR:
|
||||||
val = pic_obj_value(pic_blob_new(pic, yylval.blob.dat, yylval.blob.len));
|
val = pic_obj_value(pic_blob_new(pic, yylval.buf.dat, yylval.buf.len));
|
||||||
pic_free(pic, yylval.blob.dat);
|
pic_free(pic, yylval.buf.dat);
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
case tLPAREN:
|
case tLPAREN:
|
||||||
|
|
49
src/scan.l
49
src/scan.l
|
@ -111,34 +111,34 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
{identifier} {
|
{identifier} {
|
||||||
yylval.str.buf = yytext;
|
yylval.buf.dat = yytext;
|
||||||
yylval.str.len = yyleng;
|
yylval.buf.len = yyleng;
|
||||||
return tSYMBOL;
|
return tSYMBOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
"\"" {
|
"\"" {
|
||||||
BEGIN(STRING);
|
BEGIN(STRING);
|
||||||
yylval.str.len = 0;
|
yylval.buf.len = 0;
|
||||||
yylval.str.buf = yyalloc(yylval.str.len + 1, yyscanner);
|
yylval.buf.dat = yyalloc(yylval.buf.len + 1, yyscanner);
|
||||||
strcpy(yylval.str.buf, "");
|
strcpy(yylval.buf.dat, "");
|
||||||
}
|
}
|
||||||
<STRING>[^\\"]+ {
|
<STRING>[^\\"]+ {
|
||||||
yylval.str.len += yyleng;
|
yylval.buf.len += yyleng;
|
||||||
yylval.str.buf = yyrealloc(yylval.str.buf, yylval.str.len + 1, yyscanner);
|
yylval.buf.dat = yyrealloc(yylval.buf.dat, yylval.buf.len + 1, yyscanner);
|
||||||
strcpy(yylval.str.buf + yylval.str.len - yyleng, yytext);
|
strcpy(yylval.buf.dat + yylval.buf.len - yyleng, yytext);
|
||||||
}
|
}
|
||||||
<STRING>\\. {
|
<STRING>\\. {
|
||||||
yylval.str.len += 1;
|
yylval.buf.len += 1;
|
||||||
yylval.str.buf = yyrealloc(yylval.str.buf, yylval.str.len + 1, yyscanner);
|
yylval.buf.dat = yyrealloc(yylval.buf.dat, yylval.buf.len + 1, yyscanner);
|
||||||
yylval.str.buf[yylval.str.len] = '\0';
|
yylval.buf.dat[yylval.buf.len] = '\0';
|
||||||
|
|
||||||
switch (yytext[yyleng - 1]) {
|
switch (yytext[yyleng - 1]) {
|
||||||
case 'a': yylval.str.buf[yylval.str.len - 1] = '\a'; break;
|
case 'a': yylval.buf.dat[yylval.buf.len - 1] = '\a'; break;
|
||||||
case 'b': yylval.str.buf[yylval.str.len - 1] = '\b'; break;
|
case 'b': yylval.buf.dat[yylval.buf.len - 1] = '\b'; break;
|
||||||
case 't': yylval.str.buf[yylval.str.len - 1] = '\t'; break;
|
case 't': yylval.buf.dat[yylval.buf.len - 1] = '\t'; break;
|
||||||
case 'n': yylval.str.buf[yylval.str.len - 1] = '\n'; break;
|
case 'n': yylval.buf.dat[yylval.buf.len - 1] = '\n'; break;
|
||||||
case 'r': yylval.str.buf[yylval.str.len - 1] = '\r'; break;
|
case 'r': yylval.buf.dat[yylval.buf.len - 1] = '\r'; break;
|
||||||
default: yylval.str.buf[yylval.str.len - 1] = yytext[yyleng - 1]; break;
|
default: yylval.buf.dat[yylval.buf.len - 1] = yytext[yyleng - 1]; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<STRING>\\[:blank:]*\n[:blank:]* {
|
<STRING>\\[:blank:]*\n[:blank:]* {
|
||||||
|
@ -165,9 +165,8 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
||||||
|
|
||||||
"#u8(" {
|
"#u8(" {
|
||||||
BEGIN(BYTEVECTOR);
|
BEGIN(BYTEVECTOR);
|
||||||
yylval.blob.len = 0;
|
yylval.buf.len = 0;
|
||||||
yylval.blob.capa = 10;
|
yylval.buf.dat = NULL;
|
||||||
yylval.blob.dat = yyalloc(10, yyscanner);
|
|
||||||
}
|
}
|
||||||
<BYTEVECTOR>[ \r\n\t] {
|
<BYTEVECTOR>[ \r\n\t] {
|
||||||
/* skip whitespace */
|
/* skip whitespace */
|
||||||
|
@ -175,14 +174,12 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
||||||
<BYTEVECTOR>{uinteger} {
|
<BYTEVECTOR>{uinteger} {
|
||||||
int i = atoi(yytext);
|
int i = atoi(yytext);
|
||||||
if (0 > i || i > 255) {
|
if (0 > i || i > 255) {
|
||||||
yyfree(yylval.blob.dat, yyscanner);
|
yyfree(yylval.buf.dat, yyscanner);
|
||||||
REJECT;
|
REJECT;
|
||||||
}
|
}
|
||||||
yylval.blob.dat[yylval.blob.len++] = (char)i;
|
yylval.buf.len += 1;
|
||||||
if (yylval.blob.len > yylval.blob.capa) {
|
yylval.buf.dat = yyrealloc(yylval.buf.dat, yylval.buf.len, yyscanner);
|
||||||
yylval.blob.capa *= 2;
|
yylval.buf.dat[yylval.buf.len - 1] = (char)i;
|
||||||
yylval.blob.dat = yyrealloc(yylval.blob.dat, yylval.blob.capa, yyscanner);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
<BYTEVECTOR>")" {
|
<BYTEVECTOR>")" {
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
|
|
Loading…
Reference in New Issue