parse-from-file facility
This commit is contained in:
+3
-1
@@ -4,6 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "picconf.h"
|
||||
#include "picrin/value.h"
|
||||
@@ -76,7 +77,8 @@ pic_value pic_intern_cstr(pic_state *, const char *);
|
||||
pic_value pic_str_new(pic_state *, const char *, size_t);
|
||||
pic_value pic_str_new_cstr(pic_state *, const char *);
|
||||
|
||||
bool pic_parse(pic_state *, const char *, pic_value *);
|
||||
bool pic_parse_file(pic_state *, FILE *file, pic_value *);
|
||||
bool pic_parse_cstr(pic_state *, const char *, pic_value *);
|
||||
|
||||
pic_value pic_run(pic_state *, struct pic_proc *, pic_value);
|
||||
struct pic_proc *pic_codegen(pic_state *, pic_value);
|
||||
|
||||
+26
-1
@@ -21,6 +21,7 @@ void yyerror(struct parser_control *, const char *);
|
||||
int yylex();
|
||||
int yylex_();
|
||||
void yylex_init();
|
||||
void yyset_in();
|
||||
void yy_scan_string();
|
||||
void yylex_destroy();
|
||||
%}
|
||||
@@ -175,7 +176,31 @@ yylex(YYSTYPE *yylvalp, struct parser_control *p)
|
||||
}
|
||||
|
||||
bool
|
||||
pic_parse(pic_state *pic, const char *str, pic_value *v)
|
||||
pic_parse_file(pic_state *pic, FILE *file, pic_value *v)
|
||||
{
|
||||
struct parser_control p;
|
||||
|
||||
p.pic = pic;
|
||||
p.incomp = false;
|
||||
p.yynerrs = 0;
|
||||
|
||||
yylex_init(&p.yyscanner);
|
||||
yyset_in(file, p.yyscanner);
|
||||
yyparse(&p);
|
||||
yylex_destroy(p.yyscanner);
|
||||
|
||||
if (p.yynerrs > 0) {
|
||||
p.value = pic_undef_value();
|
||||
}
|
||||
|
||||
if (! p.incomp) {
|
||||
*v = p.value;
|
||||
}
|
||||
return ! p.incomp;
|
||||
}
|
||||
|
||||
bool
|
||||
pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
|
||||
{
|
||||
struct parser_control p;
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ main(int argc, char *argv[], char **envp)
|
||||
strcat(code, line);
|
||||
|
||||
/* read */
|
||||
r = pic_parse(pic, code, &v);
|
||||
r = pic_parse_cstr(pic, code, &v);
|
||||
if (! r) { /* wait for more input */
|
||||
goto next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user