]> git.saurik.com Git - bison.git/commitdiff
Test the make_TOKEN interface.
authorAkim Demaille <akim@betelgeuse.gostai.ensta.fr>
Fri, 10 Oct 2008 14:58:22 +0000 (16:58 +0200)
committerAkim Demaille <demaille@gostai.com>
Sat, 15 Nov 2008 13:23:27 +0000 (14:23 +0100)
* tests/c++.at (AT_CHECK_VARIANTS): Require and use locations.
Factor the common code in yylex.
Use it to test "%define lex_symbol".

ChangeLog
tests/c++.at

index 91b3e16dcb3ca75c561059e850d36a7abfd82e9c..8eb0ccdefd17ec0bb93b6fb843336856bb02a114 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-11-15  Akim Demaille  <akim@betelgeuse.gostai.ensta.fr>
+
+       Test the make_TOKEN interface.
+       * tests/c++.at (AT_CHECK_VARIANTS): Require and use locations.
+       Factor the common code in yylex.
+       Use it to test "%define lex_symbol".
+
 2008-11-15  Akim Demaille  <akim@betelgeuse.gostai.ensta.fr>
 
        Formatting change.
 2008-11-15  Akim Demaille  <akim@betelgeuse.gostai.ensta.fr>
 
        Formatting change.
index f00e1096d028f24abc3b3721705fdd09e8db77e6..f0abad6227d51a1aad02a02d216f182a28e25dce 100644 (file)
@@ -33,6 +33,7 @@ AT_DATA([list.yy],
 %skeleton "lalr1.cc"
 %defines
 %define variant
 %skeleton "lalr1.cc"
 %defines
 %define variant
+%locations
 ]m4_bpatsubst([$1], [\\n], [
 ])[
 
 ]m4_bpatsubst([$1], [\\n], [
 ])[
 
@@ -50,10 +51,15 @@ typedef std::list<std::string> strings_type;
 #include <iterator>
 #include <sstream>
 
 #include <iterator>
 #include <sstream>
 
-  // Prototype of the yylex function providing subsequent tokens.
-  static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
+ static
+#if defined USE_LEX_SYMBOL
+  yy::parser::symbol_type yylex ();
+#else
+  yy::parser::token_type yylex (yy::parser::semantic_type* yylval,
+                                yy::parser::location_type* yylloc);
+#endif
 
 
-  // Printing a list of strings.
+  // Printing a list of strings (for %printer).
   // Koening look up will look into std, since that's an std::list.
   namespace std
   {
   // Koening look up will look into std, since that's an std::list.
   namespace std
   {
@@ -103,45 +109,62 @@ item:
 ;
 %%
 
 ;
 %%
 
+#define STAGE_MAX 5
 static
 static
-yy::parser::token_type
-yylex(yy::parser::semantic_type* yylval)
+#if defined USE_LEX_SYMBOL
+yy::parser::symbol_type yylex()
+#else
+yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
+                             yy::parser::location_type* yylloc)
+#endif
 {
 {
-  static int stage = 0;
-  yy::parser::token_type result;
-
-  switch (stage)
-  {
-    case 0:
-    case 4:
-#ifdef ONE_STAGE_BUILD
-      yylval->build(string_cast(stage));
+  typedef yy::parser::token token;
+  typedef yy::parser::location_type location_type;
+  static int stage = -1;
+  ++stage;
+  if (stage == STAGE_MAX)
+    {
+#if defined USE_LEX_SYMBOL
+      return yy::parser::make_END_OF_FILE (location_type ());
 #else
 #else
-      yylval->build<std::string>() = string_cast(stage);
+      *yylloc = location_type ();
+      return token::END_OF_FILE;
 #endif
 #endif
-      result = yy::parser::token::TEXT;
-      break;
-    case 1:
-    case 2:
-    case 3:
-#ifdef ONE_STAGE_BUILD
-      yylval->build(stage);
+    }
+  else if (stage % 2)
+    {
+#if defined USE_LEX_SYMBOL
+      return yy::parser::make_NUMBER (stage, location_type ());
 #else
 #else
+# if defined ONE_STAGE_BUILD
+      yylval->build(stage);
+# else
       yylval->build<int>() = stage;
       yylval->build<int>() = stage;
+# endif
+      *yylloc = location_type ();
+      return token::NUMBER;
 #endif
 #endif
-      result = yy::parser::token::NUMBER;
-      break;
-    default:
-      result = yy::parser::token::END_OF_FILE;
-      break;
-  }
-
-  ++stage;
-  return result;
+    }
+  else
+    {
+#if defined USE_LEX_SYMBOL
+      return yy::parser::make_TEXT (string_cast (stage), location_type ());
+#else
+# if defined ONE_STAGE_BUILD
+      yylval->build (string_cast (stage));
+# else
+      yylval->build<std::string>() = string_cast (stage);
+# endif
+      *yylloc = location_type ();
+      return token::TEXT;
+#endif
+    }
+  abort();
 }
 
 void
 }
 
 void
-yy::parser::error(const std::string& message)
+yy::parser::error(const yy::parser::location_type&,
+                 const std::string& message)
 {
   std::cerr << message << std::endl;
 }
 {
   std::cerr << message << std::endl;
 }
@@ -171,6 +194,7 @@ AT_CLEANUP
 AT_CHECK_VARIANTS([])
 AT_CHECK_VARIANTS([%define assert])
 AT_CHECK_VARIANTS([[%define assert %code {\n#define ONE_STAGE_BUILD\n}]])
 AT_CHECK_VARIANTS([])
 AT_CHECK_VARIANTS([%define assert])
 AT_CHECK_VARIANTS([[%define assert %code {\n#define ONE_STAGE_BUILD\n}]])
+AT_CHECK_VARIANTS([[%define assert  %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n}]])
 
 
 ## ----------------------- ##
 
 
 ## ----------------------- ##