diff options
-rw-r--r-- | include/grecs/json.h | 1 | ||||
-rw-r--r-- | include/wordsplit.h | 8 | ||||
-rw-r--r-- | src/diag.c | 2 | ||||
-rw-r--r-- | src/json-gram.y | 1 | ||||
-rw-r--r-- | src/json-lex.l | 35 |
5 files changed, 31 insertions, 16 deletions
diff --git a/include/grecs/json.h b/include/grecs/json.h index f8402e7..49a6b87 100644 --- a/include/grecs/json.h +++ b/include/grecs/json.h @@ -51,12 +51,13 @@ struct json_pair { extern char const *json_err_diag; extern struct grecs_locus json_err_locus; extern struct json_value *json_return_obj; void jsonlex_setup(char const *s, size_t l); +void jsonlex_cleanup(void); void jsonlex_diag(const char *s); int json_unescape(char c, char *o); struct json_value *json_value_create(int type); struct grecs_symtab *json_assoc_create(void); void json_value_free(struct json_value *obj); diff --git a/include/wordsplit.h b/include/wordsplit.h index d13ec3c..7229df3 100644 --- a/include/wordsplit.h +++ b/include/wordsplit.h @@ -23,15 +23,17 @@ typedef struct wordsplit wordsplit_t; /* Structure used to direct the splitting. Members marked with [Input] can be defined before calling wordsplit(), those marked with [Output] provide return values when the function returns. If neither mark is used, the member is internal and must not be used by the caller. - In the comments below, the - identifiers in parentheses indicate bits that must be set (or unset, if - starting with !) in the ws_flags to initialize or use the given member. + In the comments below, the identifiers in parentheses indicate bits that + must be set (or unset, if starting with !) in ws_flags (if starting with + WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the + given member. + If not redefined explicitly, most of them are set to some reasonable default value upon entry to wordsplit(). */ struct wordsplit { size_t ws_wordc; /* [Output] Number of words in ws_wordv. */ char **ws_wordv; /* [Output] Array of parsed out words. */ @@ -34,13 +34,13 @@ default_print_diag(grecs_locus_t const *locus, int err, int errcode, fputc(' ', stderr); } if (!err) fprintf(stderr, "warning: "); fprintf(stderr, "%s", msg); if (errcode) - fprintf(stderr, ": %s", strerror(errno)); + fprintf(stderr, ": %s", strerror(errcode)); fputc('\n', stderr); } void (*grecs_print_diag_fun)(grecs_locus_t const *, int, int, const char *msg) = default_print_diag; diff --git a/src/json-gram.y b/src/json-gram.y index fe8996b..d5b0248 100644 --- a/src/json-gram.y +++ b/src/json-gram.y @@ -277,12 +277,13 @@ json_parse_string(char const *input, size_t len) { jsonlex_setup(input, len); if (yyparse()) { /* FIXME: error recovery */ return NULL; } + jsonlex_cleanup(); return json_return_obj; } struct json_value * json_value_lookup(struct json_value *obj, const char *ident) { diff --git a/src/json-lex.l b/src/json-lex.l index 169cf32..4bbdedf 100644 --- a/src/json-lex.l +++ b/src/json-lex.l @@ -52,24 +52,12 @@ struct grecs_locus json_err_locus; } \ json_current_locus_point.col += yyleng; \ yylloc.end = json_current_locus_point; \ } while (0); void -jsonlex_setup(char const *s, size_t l) -{ - input_ptr = s; - input_size = l; - json_current_locus_point.file = NULL; - json_current_locus_point.line = 1; - json_current_locus_point.col = 0; - json_err_diag = NULL; - yy_flex_debug = 0; -} - -void jsonlex_diag(const char *s) { if (!json_err_diag) { json_err_diag = s; json_err_locus = yylloc; } @@ -224,6 +212,29 @@ true { yylval.b = 1; return T_BOOL; } false { yylval.b = 0; return T_BOOL; } "{"|"}"|"["|"]"|":"|"," return yytext[0]; [ \t]* ; \n grecs_locus_point_advance_line(json_current_locus_point); . { jsonlex_diag("bogus character"); return T_ERR; } +%% +void +jsonlex_setup(char const *s, size_t l) +{ + input_ptr = s; + input_size = l; + json_current_locus_point.file = "input"; + json_current_locus_point.line = 1; + json_current_locus_point.col = 0; + json_err_diag = NULL; + yy_flex_debug = 0; + BEGIN(INITIAL); + yyrestart(NULL); +} + +void +jsonlex_cleanup(void) +{ + if (json_line_acc) { + grecs_txtacc_free(json_line_acc); + json_line_acc = NULL; + } +} |