bison-patches
[Top][All Lists]
Advanced

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

[PATCH] Test variants.


From: Akim Demaille
Subject: [PATCH] Test variants.
Date: Mon, 10 Nov 2008 10:04:41 -0000

        * tests/c++.at (AT_CHECK_VARIANTS): New.
        Use it with and without %define assert.
---
 ChangeLog    |    6 ++
 tests/c++.at |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 159 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 757e1fd..d7921b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-11-10  Akim Demaille  <address@hidden>
 
+       Test variants.
+       * tests/c++.at (AT_CHECK_VARIANTS): New.
+       Use it with and without %define assert.
+
+2008-11-10  Akim Demaille  <address@hidden>
+
        Add %precedence support.
        Unfortunately it is not possible to reuse the %prec directive.  This
        is because to please POSIX, we do not require to end the rules with a
diff --git a/tests/c++.at b/tests/c++.at
index 3e742ee..d351d41 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -1,5 +1,5 @@
 # Checking the output filenames.                    -*- Autotest -*-
-# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,6 +17,155 @@
 AT_BANNER([[C++ Features.]])
 
 
+## ---------- ##
+## Variants.  ##
+## ---------- ##
+
+# AT_CHECK_VARIANTS([DIRECTIVES])
+# -------------------------------
+# Check the support of variants in C++, with the additional DIRECTIVES.
+m4_define([AT_CHECK_VARIANTS],
+[AT_SETUP([Variants $1])
+
+# Store strings and integers in a list of strings.
+AT_DATA([list.yy],
+[[%debug
+%skeleton "lalr1.cc"
+%defines
+%define variant
+
+%code requires // code for the .hh file
+{
+#include <list>
+#include <string>
+typedef std::list<std::string> strings_type;
+}
+
+%code // code for the .cc file
+{
+#include <algorithm>
+#include <iostream>
+#include <iterator>
+#include <sstream>
+
+  // Prototype of the yylex function providing subsequent tokens.
+  static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
+
+  // Printing a list of strings.
+  // Koening look up will look into std, since that's an std::list.
+  namespace std
+  {
+    std::ostream&
+    operator<<(std::ostream& o, const strings_type& s)
+    {
+      std::copy(s.begin(), s.end(),
+                std::ostream_iterator<strings_type::value_type>(o, "\n"));
+      return o;
+    }
+  }
+
+  // Conversion to string.
+  template <typename T>
+    inline
+    std::string
+    string_cast (const T& t)
+  {
+    std::ostringstream o;
+    o << t;
+    return o.str();
+  }
+}
+
+%token <std::string> TEXT;
+%token <int> NUMBER;
+%printer { debug_stream() << $][$; } <int> <std::string> <strings_type>;
+%token END_OF_FILE 0;
+
+%type <std::string> item;
+%type <strings_type> list result;
+
+%%
+
+result:
+  list { std::cout << $][1; }
+;
+
+list:
+  /* nothing */        { /* Generates an empty string list */ }
+| list item    { std::swap($][$,$][1); $$.push_back($][2); }
+;
+
+item:
+  TEXT         { std::swap($][$,$][1); }
+| NUMBER       { $][$ = string_cast($][1); }
+;
+%%
+
+static
+yy::parser::token_type
+yylex(yy::parser::semantic_type* yylval)
+{
+  static int stage = 0;
+  yy::parser::token_type result;
+
+  switch (stage)
+  {
+    case 0:
+      yylval->build<std::string>() = std::string("BEGIN");
+      result = yy::parser::token::TEXT;
+      break;
+    case 1:
+    case 2:
+    case 3:
+      yylval->build<int>() = stage;
+      result = yy::parser::token::NUMBER;
+      break;
+    case 4:
+      yylval->build<std::string>() = std::string("END");
+      result = yy::parser::token::TEXT;
+      break;
+    default:
+      result = yy::parser::token::END_OF_FILE;
+      break;
+  }
+
+  ++stage;
+  return result;
+}
+
+// Mandatory error function
+void
+yy::parser::error(const yy::parser::location_type& yylloc,
+                  const std::string& message)
+{
+  std::cerr << yylloc << ": " << message << std::endl;
+}
+
+int main(int argc, char *argv[])
+{
+  yy::parser p;
+  p.set_debug_level(!!getenv("YYDEBUG"));
+  return p.parse();
+}
+]])
+
+AT_BISON_CHECK([-o list.cc list.yy], 0)
+AT_COMPILE_CXX([list])
+AT_CHECK([./list], 0,
+[BEGIN
+1
+2
+3
+END
+])
+
+AT_CLEANUP
+])
+
+AT_CHECK_VARIANTS([])
+AT_CHECK_VARIANTS([%define assert])
+
+
 ## ----------------------- ##
 ## Doxygen Documentation.  ##
 ## ----------------------- ##
@@ -100,6 +249,9 @@ m4_popdef([AT_DOXYGEN_PRIVATE])
 AT_CHECK_DOXYGEN([Public])
 AT_CHECK_DOXYGEN([Private])
 
+
+
+
 ## ------------ ##
 ## Namespaces.  ##
 ## ------------ ##
-- 
1.6.0.2.588.g3102





reply via email to

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