Code

frontend/grammar: Added sdb_fe_yyerrorf() helper.
authorSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 22:36:11 +0000 (23:36 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 22:36:11 +0000 (23:36 +0100)
src/frontend/grammar.y

index 97be55d0c7dfa5b397fade235888bafe4f505a27..4dc6cb22411ce756991d07c0a01cd078d6949abd 100644 (file)
@@ -63,6 +63,8 @@ sdb_fe_yyget_extra(sdb_fe_yyscan_t scanner);
 
 void
 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
+void
+sdb_fe_yyerrorf(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *fmt, ...);
 
 /* quick access to the current parse tree */
 #define pt sdb_fe_yyget_extra(scanner)->parsetree
@@ -181,11 +183,9 @@ statements:
                {
                        /* only accepted in default parse mode */
                        if (parser_mode != SDB_PARSE_DEFAULT) {
-                               char errmsg[1024];
-                               snprintf(errmsg, sizeof(errmsg),
+                               sdb_fe_yyerrorf(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
                                                        "expecting %s"), MODE_TO_STRING(parser_mode));
-                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
                                sdb_object_deref(SDB_OBJ($3));
                                YYABORT;
                        }
@@ -200,11 +200,9 @@ statements:
                {
                        /* only accepted in default parse mode */
                        if (parser_mode != SDB_PARSE_DEFAULT) {
-                               char errmsg[1024];
-                               snprintf(errmsg, sizeof(errmsg),
+                               sdb_fe_yyerrorf(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
                                                        "expecting %s"), MODE_TO_STRING(parser_mode));
-                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
                                sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
@@ -219,11 +217,9 @@ statements:
                {
                        /* only accepted in condition parse mode */
                        if (! (parser_mode & SDB_PARSE_COND)) {
-                               char errmsg[1024];
-                               snprintf(errmsg, sizeof(errmsg),
+                               sdb_fe_yyerrorf(&yylloc, scanner,
                                                YY_("syntax error, unexpected condition, "
                                                        "expecting %s"), MODE_TO_STRING(parser_mode));
-                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
                                sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
@@ -238,11 +234,9 @@ statements:
                {
                        /* only accepted in expression parse mode */
                        if (! (parser_mode & SDB_PARSE_EXPR)) {
-                               char errmsg[1024];
-                               snprintf(errmsg, sizeof(errmsg),
+                               sdb_fe_yyerrorf(&yylloc, scanner,
                                                YY_("syntax error, unexpected expression, "
                                                        "expecting %s"), MODE_TO_STRING(parser_mode));
-                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
                                sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
@@ -635,10 +629,8 @@ interval_elem:
 
                        unit = sdb_strpunit($2);
                        if (! unit) {
-                               char errmsg[strlen($2) + 32];
-                               snprintf(errmsg, sizeof(errmsg),
+                               sdb_fe_yyerrorf(&yylloc, scanner,
                                                YY_("invalid time unit %s"), $2);
-                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
                                free($2); $2 = NULL;
                                YYABORT;
                        }
@@ -663,6 +655,15 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg)
        sdb_log(SDB_LOG_ERR, "frontend: parse error: %s", msg);
 } /* sdb_fe_yyerror */
 
+void
+sdb_fe_yyerrorf(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       sdb_vlog(SDB_LOG_ERR, fmt, ap);
+       va_end(ap);
+} /* sdb_fe_yyerrorf */
+
 static sdb_store_matcher_t *
 name_iter_matcher(int m_type, int type, const char *cmp,
                sdb_store_expr_t *expr)