]> git.saurik.com Git - bison.git/commitdiff
test location_type.
authorAkim Demaille <demaille@gostai.com>
Tue, 13 Apr 2010 20:05:42 +0000 (22:05 +0200)
committerAkim Demaille <demaille@gostai.com>
Tue, 13 Apr 2010 21:31:55 +0000 (23:31 +0200)
* tests/local.at (_AT_BISON_OPTION_PUSHDEFS):
Define AT_LOCATION_TYPE_IF.
(_AT_BISON_OPTION_POPDEFS): Undefine AT_LOCATION_TYPE_IF.
* tests/calc.at (_AT_DATA_CALC_Y): When %define location_type is
used, provide a user location type and use it.
(Simple LALR1 C++ Calculator): Add a test case for location_type.

ChangeLog
tests/calc.at
tests/local.at

index bc9cbc974e7f11a654d726d42558d31b9586ca30..58f27a5cc0b49bb7cf3b9fe1cee33f8356df0b6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-04-13  Akim Demaille  <demaille@gostai.com>
+
+       test location_type.
+       * tests/local.at (_AT_BISON_OPTION_PUSHDEFS):
+       Define AT_LOCATION_TYPE_IF.
+       (_AT_BISON_OPTION_POPDEFS): Undefine AT_LOCATION_TYPE_IF.
+       * tests/calc.at (_AT_DATA_CALC_Y): When %define location_type is
+       used, provide a user location type and use it.
+       (Simple LALR1 C++ Calculator): Add a test case for location_type.
+
 2010-04-13  Akim Demaille  <demaille@gostai.com>
 
        tests: check fclose's return value.
 2010-04-13  Akim Demaille  <demaille@gostai.com>
 
        tests: check fclose's return value.
index f102f952c53724b90cc4dc35247bd88709c65098..16e40f5bb3025159e02429f49c08d92bd2cae32c 100644 (file)
@@ -160,8 +160,22 @@ AT_SKEL_CC_IF(
 [%define global_tokens_and_yystype])[
 %code requires
 {
 [%define global_tokens_and_yystype])[
 %code requires
 {
-/* Exercise pre-prologue dependency to %union.  */
-typedef int semantic_value;
+]AT_LOCATION_TYPE_IF([
+# include <iostream>
+  struct Point
+  {
+    int l;
+    int c;
+  };
+
+  struct Span
+  {
+    Point begin;
+    Point end;
+  };
+])[
+  /* Exercise pre-prologue dependency to %union.  */
+  typedef int semantic_value;
 }
 
 /* Exercise %union. */
 }
 
 /* Exercise %union. */
@@ -178,10 +192,17 @@ extern FILE *input;]AT_SKEL_CC_IF([[
 #ifndef YYLTYPE
 # define YYLTYPE ]AT_NAME_PREFIX[::parser::location_type
 #endif
 #ifndef YYLTYPE
 # define YYLTYPE ]AT_NAME_PREFIX[::parser::location_type
 #endif
-#define first_line   begin.line
-#define first_column begin.column
-#define last_line    end.line
-#define last_column  end.column]])[
+]AT_LOCATION_TYPE_IF([[
+  #define first_line   begin.l
+  #define first_column begin.c
+  #define last_line    end.l
+  #define last_column  end.c
+]], [[
+  #define first_line   begin.line
+  #define first_column begin.column
+  #define last_line    end.line
+  #define last_column  end.column
+]])])[
 }
 
 %code
 }
 
 %code
@@ -211,7 +232,7 @@ static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
 int yylex (]AT_LEX_FORMALS[);
 }
 
 int yylex (]AT_LEX_FORMALS[);
 }
 
-]AT_SKEL_CC_IF([AT_LOCATION_IF([
+]AT_SKEL_CC_IF([AT_LOCATION_IF([AT_LOCATION_TYPE_IF([], [
 /* The lalr1.cc skeleton, for backward compatibility, defines
    a constructor for position that initializes the filename.  The
    glr.cc skeleton does not (and in fact cannot: location/position
 /* The lalr1.cc skeleton, for backward compatibility, defines
    a constructor for position that initializes the filename.  The
    glr.cc skeleton does not (and in fact cannot: location/position
@@ -220,7 +241,7 @@ int yylex (]AT_LEX_FORMALS[);
 %initial-action {
   @$.initialize (0);
 }
 %initial-action {
   @$.initialize (0);
 }
-])])[
+])])])[
 
 /* Bison Declarations */
 %token CALC_EOF 0 "end of input"
 
 /* Bison Declarations */
 %token CALC_EOF 0 "end of input"
@@ -267,7 +288,20 @@ exp:
 %%
 
 ]AT_SKEL_CC_IF(
 %%
 
 ]AT_SKEL_CC_IF(
-[/* A C++ error reporting function.  */
+[AT_LOCATION_TYPE_IF([[
+  std::ostream&
+  operator<< (std::ostream& o, const Span& s)
+  {
+    o << s.begin.l << '.' << s.begin.c;
+    if (s.begin.l != s.end.l)
+      o << '-' << s.end.l << '.' << s.end.c - 1;
+    else if (s.begin.c != s.end.c - 1)
+      o << '-' << s.end.c - 1;
+    return o;
+  }
+]])
+
+/* A C++ error reporting function.  */
 void
 AT_NAME_PREFIX::parser::error (AT_LOCATION_IF([const location_type& l, ])const std::string& m)
 {
 void
 AT_NAME_PREFIX::parser::error (AT_LOCATION_IF([const location_type& l, ])const std::string& m)
 {
@@ -575,6 +609,7 @@ AT_CHECK_CALC_LALR()
 
 AT_CHECK_CALC_LALR([%defines])
 AT_CHECK_CALC_LALR([%locations])
 
 AT_CHECK_CALC_LALR([%defines])
 AT_CHECK_CALC_LALR([%locations])
+
 AT_CHECK_CALC_LALR([%name-prefix="calc"]) dnl test deprecated `='
 AT_CHECK_CALC_LALR([%verbose])
 AT_CHECK_CALC_LALR([%yacc])
 AT_CHECK_CALC_LALR([%name-prefix="calc"]) dnl test deprecated `='
 AT_CHECK_CALC_LALR([%verbose])
 AT_CHECK_CALC_LALR([%yacc])
@@ -651,6 +686,7 @@ m4_define([AT_CHECK_CALC_LALR1_CC],
 
 AT_CHECK_CALC_LALR1_CC([])
 AT_CHECK_CALC_LALR1_CC([%locations])
 
 AT_CHECK_CALC_LALR1_CC([])
 AT_CHECK_CALC_LALR1_CC([%locations])
+AT_CHECK_CALC_LALR1_CC([%locations %define location_type Span])
 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
index cbd7e596aa3c70c98944cd0781d7bb6703c47540..f8a88c965d05a2240b34feb1b37b1cdc2d291120 100644 (file)
@@ -70,10 +70,12 @@ m4_pushdef([AT_YACC_IF],
 [m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
 m4_pushdef([AT_LEXPARAM_IF],
 [m4_bmatch([$3], [%lex-param], [$1], [$2])])
 [m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
 m4_pushdef([AT_LEXPARAM_IF],
 [m4_bmatch([$3], [%lex-param], [$1], [$2])])
-m4_pushdef([AT_PARAM_IF],
-[m4_bmatch([$3], [%parse-param], [$1], [$2])])
 m4_pushdef([AT_LOCATION_IF],
 [m4_bmatch([$3], [%locations], [$1], [$2])])
 m4_pushdef([AT_LOCATION_IF],
 [m4_bmatch([$3], [%locations], [$1], [$2])])
+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])])
 m4_pushdef([AT_PURE_IF],
 [m4_bmatch([$3], [%define  *api\.pure\|%pure-parser],
            [m4_bmatch([$3], [%define  *api\.pure *"?false"?], [$2], [$1])],
 m4_pushdef([AT_PURE_IF],
 [m4_bmatch([$3], [%define  *api\.pure\|%pure-parser],
            [m4_bmatch([$3], [%define  *api\.pure *"?false"?], [$2], [$1])],
@@ -149,6 +151,7 @@ m4_popdef([AT_YYERROR_ARG_LOC_IF])
 m4_popdef([AT_NAME_PREFIX])
 m4_popdef([AT_GLR_OR_PARAM_IF])
 m4_popdef([AT_PURE_AND_LOC_IF])
 m4_popdef([AT_NAME_PREFIX])
 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_PARAM_IF])
 m4_popdef([AT_LEXPARAM_IF])
 m4_popdef([AT_LOCATION_IF])
 m4_popdef([AT_PARAM_IF])
 m4_popdef([AT_LEXPARAM_IF])