diff --git a/core/syntax.y b/core/syntax.y index b7666c9f..33ff6528 100644 --- a/core/syntax.y +++ b/core/syntax.y @@ -223,7 +223,7 @@ dec = < ('0' | [1-9][0-9]*) { $$ = YY_TNUM; } ('.' [0-9]+ { $$ = YY_TDEC; })? ('e' [-+] [0-9]+ { $$ = YY_TDEC })? > -q1 = ['] +q1 = ['] # ' emacs highlight problems c1 = < (!q1 utf8)+ > { P->pbuf = potion_asm_write(P, P->pbuf, yytext, yyleng); } str1 = q1 { P->pbuf = potion_asm_clear(P, P->pbuf); } < (q1 q1 { P->pbuf = potion_asm_write(P, P->pbuf, "'", 1); } | c1)* > @@ -294,6 +294,9 @@ arg-sep = '.' - { P->source = PN_PUSH(P->source, PN_NUM('.')); } PN potion_parse(Potion *P, PN code, char *filename) { GREG *G = YY_NAME(parse_new)(P); + int oldyypos = P->yypos; + PN oldinput = P->input; + PN oldsource = P->source; P->yypos = 0; P->input = code; P->source = PN_NIL; @@ -308,7 +311,9 @@ PN potion_parse(Potion *P, PN code, char *filename) { YY_NAME(parse_free)(G); code = P->source; - P->source = PN_NIL; + P->source = oldsource; + P->yypos = oldyypos; + P->input = oldinput; return code; } @@ -318,6 +323,9 @@ PN potion_sig(Potion *P, char *fmt) { if (fmt[0] == '\0') return PN_FALSE; // empty signature, no args GREG *G = YY_NAME(parse_new)(P); + int oldyypos = P->yypos; + PN oldinput = P->input; + PN oldsource = P->source; P->yypos = 0; P->input = potion_byte_str(P, fmt); P->source = out = PN_TUP0(); @@ -332,7 +340,9 @@ PN potion_sig(Potion *P, char *fmt) { YY_NAME(parse_free)(G); out = P->source; - P->source = PN_NIL; + P->source = oldsource; + P->yypos = oldyypos; + P->input = oldinput; return out; } diff --git a/test/flow/eval.pn b/test/flow/eval.pn new file mode 100644 index 00000000..dcc051a3 --- /dev/null +++ b/test/flow/eval.pn @@ -0,0 +1,3 @@ +# issue 9 - GC-safe re-entrant parser +1 to 1000000(): 'x = Object()' eval. +#=> 1000000