* 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.
This commit is contained in:
Akim Demaille
2006-07-08 20:38:14 +00:00
parent 8ec0a172bc
commit cd48d21d94
8 changed files with 48 additions and 30 deletions

View File

@@ -1,3 +1,12 @@
2006-07-08 Akim Demaille <akim@lrde.epita.fr>
* 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.
2006-07-08 Akim Demaille <akim@lrde.epita.fr>
* data/c.m4 (b4_dirname): New.

3
NEWS
View File

@@ -3,6 +3,9 @@ Bison News
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

View File

@@ -91,6 +91,11 @@ m4_define_default([b4_epilogue], [])
# 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. ##
## ------------------------ ##

View File

@@ -2303,8 +2303,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
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], [

View File

@@ -36,6 +36,7 @@ b4_copyright([Positions for Bison parsers in C++],
# include <iostream>
# include <string>
# include <algorithm>
namespace ]b4_namespace[
{
@@ -46,7 +47,7 @@ namespace ]b4_namespace[
]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 @@ namespace ]b4_namespace[
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 @@ namespace ]b4_namespace[
/// (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);
}
/** \} */

View File

@@ -1064,8 +1064,8 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
]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], [

View File

@@ -1998,7 +1998,9 @@ type for storing locations is not needed: we will use the type provided
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
@code{last_column}.
@code{last_column}. 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 @@ typedef struct YYLTYPE
@} 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

View File

@@ -199,7 +199,7 @@ get_char (]AT_LEX_FORMALS[)
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 @@ yylex (]AT_LEX_FORMALS[)
{
init = 0;
]AT_LOCATION_IF([
AT_LOC.last_column = 0;
AT_LOC.last_column = 1;
AT_LOC.last_line = 1;
])[
}
@@ -476,21 +476,21 @@ _AT_CHECK_CALC([$1],
# 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], [1], [/dev/null], [4],
_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