reentrant scanner
This commit is contained in:
parent
bb0bb0e186
commit
f31ddb36a2
22
src/parse.y
22
src/parse.y
|
@ -9,15 +9,20 @@
|
|||
|
||||
struct parser_control {
|
||||
pic_state *pic;
|
||||
void *yyscanner;
|
||||
pic_value value;
|
||||
bool incomp;
|
||||
int yynerrs;
|
||||
};
|
||||
|
||||
void init_scanner(const char *);
|
||||
void final_scanner(void);
|
||||
|
||||
void yyerror(struct parser_control *, const char *);
|
||||
|
||||
/* just for supressing warnings. a little bit evil */
|
||||
int yylex();
|
||||
int yylex_();
|
||||
void yylex_init();
|
||||
void yy_scan_string();
|
||||
void yylex_destroy();
|
||||
%}
|
||||
|
||||
%pure_parser
|
||||
|
@ -122,6 +127,12 @@ yyerror(struct parser_control *p, const char *msg)
|
|||
p->yynerrs++;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(YYSTYPE *yylvalp, struct parser_control *p)
|
||||
{
|
||||
return yylex_(yylvalp, p->yyscanner, p);
|
||||
}
|
||||
|
||||
bool
|
||||
pic_parse(pic_state *pic, const char *str, pic_value *v)
|
||||
{
|
||||
|
@ -131,9 +142,10 @@ pic_parse(pic_state *pic, const char *str, pic_value *v)
|
|||
p.incomp = false;
|
||||
p.yynerrs = 0;
|
||||
|
||||
init_scanner(str);
|
||||
yylex_init(&p.yyscanner);
|
||||
yy_scan_string(str, p.yyscanner);
|
||||
yyparse(&p);
|
||||
final_scanner();
|
||||
yylex_destroy(p.yyscanner);
|
||||
|
||||
if (p.yynerrs > 0) {
|
||||
p.value = pic_undef_value();
|
||||
|
|
18
src/scan.l
18
src/scan.l
|
@ -7,6 +7,7 @@
|
|||
|
||||
struct parser_control {
|
||||
pic_state *pic;
|
||||
void *yyscanner;
|
||||
pic_value value;
|
||||
bool incomp;
|
||||
int yynerrs;
|
||||
|
@ -14,9 +15,10 @@ struct parser_control {
|
|||
|
||||
static pic_value new_escaped_string(pic_state *, const char *);
|
||||
|
||||
#define YY_DECL int yylex (YYSTYPE *yylvalp, struct parser_control *p)
|
||||
#define YY_DECL int yylex_ (YYSTYPE *yylvalp, yyscan_t yyscanner, struct parser_control *p)
|
||||
%}
|
||||
|
||||
%option reentrant
|
||||
%option noinput
|
||||
%option nounput
|
||||
|
||||
|
@ -55,7 +57,7 @@ string_elem [^\"\\]|"\\\""|"\\\\"
|
|||
%%
|
||||
|
||||
int
|
||||
yywrap()
|
||||
yywrap(yyscan_t yyscanner)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -84,15 +86,3 @@ new_escaped_string(pic_state *pic, const char *str)
|
|||
pic_free(pic, new_str);
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
init_scanner(const char *str)
|
||||
{
|
||||
yy_scan_string(str);
|
||||
}
|
||||
|
||||
void
|
||||
final_scanner()
|
||||
{
|
||||
yylex_destroy();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue