bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/3] c++: trailing end-of-lines in %parse-param


From: Akim Demaille
Subject: [PATCH 2/3] c++: trailing end-of-lines in %parse-param
Date: Tue, 31 Jul 2012 14:23:23 +0200

* src/parse-gram.y (add_param): No only skip ' ' and '\t', skip all
leading and trailing spaces.
* tests/regression.at (Lex and parse params): Check it.
* NEWS: Document it.
---
 NEWS                |  4 +++
 src/parse-gram.y    | 10 ++++---
 tests/regression.at | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index f940d8e..316abb0 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
+
+  Trailing end-of-lines in %parse-param or %lex-param would result in
+  invalid C++.  This is fixed.
 
 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
 
diff --git a/src/parse-gram.y b/src/parse-gram.y
index e6a27c5..02af75e 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -734,11 +734,13 @@ add_param (char const *type, char *decl, location loc)
 
   /* Strip the surrounding '{' and '}', and any blanks just inside
      the braces.  */
-  while (*--p == ' ' || *p == '\t')
-    continue;
+  --p;
+  while (isspace ((unsigned char) *p))
+    --p;
   p[1] = '\0';
-  while (*++decl == ' ' || *decl == '\t')
-    continue;
+  ++decl;
+  while (isspace ((unsigned char) *decl))
+    ++decl;
 
   if (! name_start)
     complain_at (loc, _("missing identifier in parameter declaration"));
diff --git a/tests/regression.at b/tests/regression.at
index ad880c7..7211618 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -1583,3 +1583,87 @@ Stack now 0
 m4_popdef([AT_LAC_CHECK])
 
 AT_CLEANUP
+
+
+## ---------------------- ##
+## Lex and parse params.  ##
+## ---------------------- ##
+
+# AT_TEST(SKELETON)
+# -----------------
+# Check that the identifier of the params is properly fetched
+# even when there are trailing blanks.
+
+m4_pushdef([AT_TEST],
+[AT_SETUP([[Lex and parse params: $1]])
+
+AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1])
+
+## FIXME: Improve parsing of parse-param and use the generated
+## yyerror.
+AT_DATA_GRAMMAR([input.y],
+[[%defines
+%locations
+%skeleton $1
+%union { int ival; }
+%parse-param { int x }
+// Spaces, tabs, and new lines.
+%parse-param { @&t@
+        int y   @&t@
+         @&t@
+ @&t@
+}
+
+%{
+#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_YYLEX_DECLARE[
+%}
+
+%%
+exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
+%%
+]AT_YYLEX_DEFINE(["a"])[
+
+]AT_SKEL_CC_IF(
+[AT_YYERROR_DEFINE
+
+int
+yyparse (int x, int y)
+{
+  yy::parser parser(x, y);
+  return parser.parse ();
+}
+])[
+
+int
+main (void)
+{
+  return !!yyparse(1, 2);
+}
+]])
+
+AT_FULL_COMPILE([input])
+AT_CHECK([./input], 0, [[x: 1, y: 2
+]])
+AT_BISON_OPTION_POPDEFS
+
+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")
+
+m4_popdef([AT_TEST])
-- 
1.7.11.3




reply via email to

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