bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/6] tests: handle %parse-param in the generated yyerror


From: Akim Demaille
Subject: [PATCH 2/6] tests: handle %parse-param in the generated yyerror
Date: Mon, 5 Nov 2012 13:14:26 +0100

* tests/local.at (AT_PARSE_PARAMS): New.
(AT_YYERROR_FORMALS, AT_YYERROR_DEFINE): Use it to add the parse-param
to yyerror.
* tests/calc.at, tests/regression.at: Use AT_YYERROR_DEFINE and
AT_YYERROR_DECLARE, now that they handle properly the parse-params.
Be sure to let AT_BISON_OPTION_PUSHDEFS now what parse-params are used.
---
 tests/calc.at       | 29 +++--------------------------
 tests/local.at      | 16 +++++++++++++---
 tests/regression.at | 26 +++++++++-----------------
 3 files changed, 25 insertions(+), 46 deletions(-)

diff --git a/tests/calc.at b/tests/calc.at
index 9518c3c..2581a5b 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -280,11 +280,7 @@ AT_SKEL_CC_IF(
 FILE *input;
 static int power (int base, int exponent);
 
-]AT_SKEL_CC_IF(,
-[static void yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
-                     AT_PARAM_IF([semantic_value *result, int *count, ])
-                     const char *s
-                     );])[
+]AT_YYERROR_DECLARE[
 ]AT_YYLEX_DECLARE_EXTERN[
 }
 
@@ -365,27 +361,8 @@ power (int base, int exponent)
       o << '-' << s.last.c - 1;
     return o;
   }
-]])
-AT_YYERROR_DEFINE],
-[/* A C error reporting function.  */
-static void
-yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
-         AT_PARAM_IF([semantic_value *result, int *count, ])
-         const char *s)
-{
-AT_PARAM_IF([(void) result; (void) count;])
-AT_YYERROR_SEES_LOC_IF([
-  fprintf (stderr, "%d.%d",
-           AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);
-  if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE)
-    fprintf (stderr, "-%d.%d",
-             AT_LOC_LAST_LINE,  AT_LOC_LAST_COLUMN - 1);
-  else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1)
-    fprintf (stderr, "-%d",
-             AT_LOC_LAST_COLUMN - 1);
-  fprintf (stderr, ": ");])
-  fprintf (stderr, "%s\n", s);
-}])[
+]])])[
+]AT_YYERROR_DEFINE[
 ]AT_DEFINES_IF([],
 [AT_CALC_LEX
 AT_CALC_MAIN])])
diff --git a/tests/local.at b/tests/local.at
index 97107a5..b0ec647 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -119,6 +119,7 @@ m4_pushdef([AT_SKEL_CC_IF],
 [m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], 
[$2])])
 m4_pushdef([AT_SKEL_JAVA_IF],
 [m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], 
[$1], [$2])])
+# The target language: "c", "c++", or "java".
 m4_pushdef([AT_LANG],
 [AT_SKEL_JAVA_IF([java],
                  [AT_SKEL_CC_IF([c++],
@@ -140,6 +141,12 @@ m4_pushdef([AT_LOCATION_TYPE_IF],
 [m4_bmatch([$3], [%define location_type], [$1], [$2])])
 m4_pushdef([AT_PARAM_IF],
 [m4_bmatch([$3], [%parse-param], [$1], [$2])])
+# Comma-terminated list of formals parse-parameters.
+# E.g., %parse-param { int x } {int y} -> "int x, int y, ".
+m4_pushdef([AT_PARSE_PARAMS])
+m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}],
+             [m4_append([AT_PARSE_PARAMS], [\1, ])])
+
 m4_pushdef([AT_PURE_IF],
 [m4_bmatch([$3], [%define  *api\.pure\|%pure-parser],
            [m4_bmatch([$3], [%define  *api\.pure *"?false"?], [$2], [$1])],
@@ -241,6 +248,7 @@ m4_popdef([AT_GLR_OR_PARAM_IF])
 m4_popdef([AT_PURE_AND_LOC_IF])
 m4_popdef([AT_LOCATION_TYPE_IF])
 m4_popdef([AT_LOCATION_IF])
+m4_popdef([AT_PARSE_PARAMS])
 m4_popdef([AT_PARAM_IF])
 m4_popdef([AT_LEXPARAM_IF])
 m4_popdef([AT_YACC_IF])
@@ -350,7 +358,7 @@ static
 # Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
 m4_define([AT_YYERROR_FORMALS],
 [m4_case(AT_LANG,
-[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])[const char *msg]])[]dnl
+[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])AT_PARSE_PARAMS [const char 
*msg]])[]dnl
 ])
 
 m4_define([AT_YYERROR_PROTOTYPE],
@@ -374,8 +382,10 @@ m4_define([AT_YYERROR_DEFINE],
 /* A C error reporting function.  */
 static
 ]AT_YYERROR_PROTOTYPE[
-{
-]AT_YYERROR_SEES_LOC_IF([[
+{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
+              [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
+  YYUSE(\1);])dnl
+AT_YYERROR_SEES_LOC_IF([[
   fprintf (stderr, "%d.%d",
            ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
   if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[)
diff --git a/tests/regression.at b/tests/regression.at
index 1087379..6cf2268 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -1545,14 +1545,14 @@ AT_CLEANUP
 m4_pushdef([AT_TEST],
 [AT_SETUP([[Lex and parse params: $1]])
 
-AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1])
+AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" %parse-param { int x } 
%parse-param { int y }])
 
 ## FIXME: Improve parsing of parse-param and use the generated
 ## yyerror.
 AT_DATA_GRAMMAR([input.y],
 [[%defines
 %locations
-%skeleton $1
+%skeleton "$1"
 %union { int ival; }
 %parse-param { int x }
 // Spaces, tabs, and new lines.
@@ -1566,26 +1566,18 @@ AT_DATA_GRAMMAR([input.y],
 #include <stdio.h>
 #include <stdlib.h>
 
-]AT_SKEL_CC_IF([], [[
-static
-void
-yyerror (int x, int y, const char *msg)
-{
-  fprintf (stderr, "x: %d, y: %d, %s\n", x, y, msg);
-}]])[
-
+  ]AT_YYERROR_DECLARE[
   ]AT_YYLEX_DECLARE[
 %}
 
 %%
 exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
 %%
+]AT_YYERROR_DEFINE[
 ]AT_YYLEX_DEFINE(["a"])[
 
 ]AT_SKEL_CC_IF(
-[AT_YYERROR_DEFINE
-
-int
+[int
 yyparse (int x, int y)
 {
   yy::parser parser(x, y);
@@ -1609,9 +1601,9 @@ AT_CLEANUP
 ])
 
 ## FIXME: test Java, and iterate over skeletons.
-AT_TEST("yacc.c")
-AT_TEST("glr.c")
-AT_TEST("lalr1.cc")
-AT_TEST("glr.cc")
+AT_TEST([yacc.c])
+AT_TEST([glr.c])
+AT_TEST([lalr1.cc])
+AT_TEST([glr.cc])
 
 m4_popdef([AT_TEST])
-- 
1.8.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]