Index: ChangeLog from Akim Demaille * data/c.m4 (b4_location_initial_column, b4_location_initial_line): New, default to 1. * data/yacc.c, data/glr.c, data/location.cc: Use them. * NEWS, doc/bison.texinfo: The initial column and line are 1 by default. * tests/calc.at: Adjust. Index: NEWS =================================================================== RCS file: /cvsroot/bison/bison/NEWS,v retrieving revision 1.153 diff -u -r1.153 NEWS --- NEWS 23 Jun 2006 20:17:27 -0000 1.153 +++ NEWS 8 Jul 2006 20:37:19 -0000 @@ -3,6 +3,9 @@ Changes in version 2.3+: +* Locations columns and lines start at 1. + In accordance with the GNU Coding Standards and Emacs. + * Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with `-y', `--yacc', or `%yacc'), Bison no longer generates #define statements for associating token numbers with token names. Removing the #define statements Index: data/c.m4 =================================================================== RCS file: /cvsroot/bison/bison/data/c.m4,v retrieving revision 1.59 diff -u -r1.59 c.m4 --- data/c.m4 8 Jul 2006 14:24:56 -0000 1.59 +++ data/c.m4 8 Jul 2006 20:37:19 -0000 @@ -91,6 +91,11 @@ # If the %union is not named, its name is YYSTYPE. m4_define_default([b4_union_name], [YYSTYPE]) +# The initial column and line. +m4_define_default([b4_location_initial_column], [1]) +m4_define_default([b4_location_initial_line], [1]) + + ## ------------------------ ## ## Pure/impure interfaces. ## ## ------------------------ ## Index: data/glr.c =================================================================== RCS file: /cvsroot/bison/bison/data/glr.c,v retrieving revision 1.183 diff -u -r1.183 glr.c --- data/glr.c 8 Jul 2006 14:24:56 -0000 1.183 +++ data/glr.c 8 Jul 2006 20:37:20 -0000 @@ -2303,8 +2303,8 @@ yylval = yyval_default; ]b4_locations_if([ #if YYLTYPE_IS_TRIVIAL - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 0; + yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; + yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; #endif ]) m4_ifdef([b4_initial_action], [ Index: data/location.cc =================================================================== RCS file: /cvsroot/bison/bison/data/location.cc,v retrieving revision 1.12 diff -u -r1.12 location.cc --- data/location.cc 22 Jun 2006 19:46:05 -0000 1.12 +++ data/location.cc 8 Jul 2006 20:37:20 -0000 @@ -36,6 +36,7 @@ # include # include +# include namespace ]b4_namespace[ { @@ -46,7 +47,7 @@ ]m4_ifdef([b4_location_constructors], [ /// Construct a position. position () - : filename (0), line (1), column (0) + : filename (0), line (]b4_location_initial_line[), column (]b4_location_initial_column[) { } @@ -55,8 +56,8 @@ inline void initialize (]b4_filename_type[* fn) { filename = fn; - line = 1; - column = 0; + line = ]b4_location_initial_line[; + column = ]b4_location_initial_column[; } /** \name Line and Column related manipulators @@ -65,19 +66,14 @@ /// (line related) Advance to the COUNT next lines. inline void lines (int count = 1) { - column = 0; + column = ]b4_location_initial_column[; line += count; } /// (column related) Advance to the COUNT next columns. inline void columns (int count = 1) { - int leftmost = 0; - int current = column; - if (leftmost <= current + count) - column += count; - else - column = 0; + column = std::max (]b4_location_initial_column[u, column + count); } /** \} */ Index: data/yacc.c =================================================================== RCS file: /cvsroot/bison/bison/data/yacc.c,v retrieving revision 1.147 diff -u -r1.147 yacc.c --- data/yacc.c 8 Jul 2006 14:24:56 -0000 1.147 +++ data/yacc.c 8 Jul 2006 20:37:20 -0000 @@ -1064,8 +1064,8 @@ ]b4_locations_if([[ yylsp = yyls; #if YYLTYPE_IS_TRIVIAL /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 0; + yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; + yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; #endif ]]) m4_ifdef([b4_initial_action], [ Index: doc/bison.texinfo =================================================================== RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v retrieving revision 1.195 diff -u -r1.195 bison.texinfo --- doc/bison.texinfo 23 Jun 2006 20:17:27 -0000 1.195 +++ doc/bison.texinfo 8 Jul 2006 20:37:23 -0000 @@ -1998,7 +1998,9 @@ by default (@pxref{Location Type, ,Data Types of Locations}), which is a four member structure with the following integer fields: @code{first_line}, @code{first_column}, @code{last_line} and address@hidden address@hidden By conventions, and in accordance with the GNU +Coding Standards and common practice, the line and column count both +start at 1. @node Ltcalc Rules @subsection Grammar Rules for @code{ltcalc} @@ -3512,6 +3514,9 @@ @} YYLTYPE; @end example +At the beginning of the parsing, Bison initializes all these fields to 1 +for @code{yylloc}. + @node Actions and Locations @subsection Actions and Locations @cindex location actions Index: tests/calc.at =================================================================== RCS file: /cvsroot/bison/bison/tests/calc.at,v retrieving revision 1.89 diff -u -r1.89 calc.at --- tests/calc.at 10 Jun 2006 03:02:23 -0000 1.89 +++ tests/calc.at 8 Jul 2006 20:37:24 -0000 @@ -199,7 +199,7 @@ if (res == '\n') { AT_LOC.last_line++; - AT_LOC.last_column = 0; + AT_LOC.last_column = 1; } else AT_LOC.last_column++; @@ -262,7 +262,7 @@ { init = 0; ]AT_LOCATION_IF([ - AT_LOC.last_column = 0; + AT_LOC.last_column = 1; AT_LOC.last_line = 1; ])[ } @@ -476,21 +476,21 @@ # Some syntax errors. _AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15], - [1.2: syntax error, unexpected number]) + [1.3: syntax error, unexpected number]) _AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20], - [1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!']) + [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!']) _AT_CHECK_CALC_ERROR([$1], [1], [error], [5], - [1.0: syntax error, unexpected $undefined]) + [1.1: syntax error, unexpected $undefined]) _AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30], - [1.6: syntax error, unexpected '=']) + [1.7: syntax error, unexpected '=']) _AT_CHECK_CALC_ERROR([$1], [1], [ +1], [20], - [2.0: syntax error, unexpected '+']) + [2.1: syntax error, unexpected '+']) # Exercise error messages with EOF: work on an empty file. _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4], - [1.0: syntax error, unexpected end of input]) + [1.1: syntax error, unexpected end of input]) # Exercise the error token: without it, we die at the first error, # hence be sure to @@ -511,20 +511,20 @@ _AT_CHECK_CALC_ERROR([$1], [0], [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1], [250], -[1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' -1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' -1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' -1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' +[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!' +1.18: syntax error, unexpected ')', expecting number or '-' or '(' or '!' +1.23: syntax error, unexpected '*', expecting number or '-' or '(' or '!' +1.41: syntax error, unexpected '*', expecting number or '-' or '(' or '!' calc: error: 4444 != 1]) # The same, but this time exercising explicitly triggered syntax errors. # POSIX says the lookahead causing the error should not be discarded. _AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102], -[1.9: syntax error, unexpected number +[1.10: syntax error, unexpected number calc: error: 2222 != 1]) _AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113], -[1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' -1.11: syntax error, unexpected number +[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!' +1.12: syntax error, unexpected number calc: error: 2222 != 1]) AT_BISON_OPTION_POPDEFS