d: create alias Location for YYLocation

* data/skeletons/d.m4: Here.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Adjust.
* tests/calc.at: Test it.
This commit is contained in:
Adela Vais
2020-12-18 17:31:57 +02:00
committed by Akim Demaille
parent 6692df8992
commit 8e44b24ba8
4 changed files with 22 additions and 19 deletions

View File

@@ -447,15 +447,18 @@ m4_define([b4_var_decls],
m4_define([b4_var_decl], m4_define([b4_var_decl],
[ protected $1;]) [ protected $1;])
# b4_public_types_declare # b4_public_types_declare
# ----------------------- # -----------------------
# Define the public types: token, semantic value, location, and so forth. # Define the public types: token, semantic value, location, and so forth.
# Depending on %define token_lex, may be output in the header or source file. # Depending on %define token_lex, may be output in the header or source file.
m4_define([b4_public_types_declare], m4_define([b4_public_types_declare],
[[ [[
alias Symbol = ]b4_parser_class[.Symbol; alias Symbol = ]b4_parser_class[.Symbol;]b4_locations_if([[
alias Location = ]b4_location_type[;]])[
]]) ]])
# b4_symbol_type_define # b4_symbol_type_define
# --------------------- # ---------------------
# Define symbol_type, the external type for symbols used for symbol # Define symbol_type, the external type for symbols used for symbol
@@ -469,15 +472,15 @@ m4_define([b4_symbol_type_define],
{ {
private SymbolKind kind; private SymbolKind kind;
private ]b4_yystype[ value_;]b4_locations_if([[ private ]b4_yystype[ value_;]b4_locations_if([[
private YYLocation location_;]])[ private Location location_;]])[
this(TokenKind token]b4_locations_if([[, YYLocation loc]])[) this(TokenKind token]b4_locations_if([[, Location loc]])[)
{ {
kind = yytranslate_(token);]b4_locations_if([ kind = yytranslate_(token);]b4_locations_if([
location_ = loc;])[ location_ = loc;])[
} }
static foreach (member; __traits(allMembers, YYSemanticType)) static foreach (member; __traits(allMembers, YYSemanticType))
{ {
this(TokenKind token, typeof(mixin("YYSemanticType." ~ member)) val]b4_locations_if([[, YYLocation loc]])[) this(TokenKind token, typeof(mixin("YYSemanticType." ~ member)) val]b4_locations_if([[, Location loc]])[)
{ {
kind = yytranslate_(token); kind = yytranslate_(token);
mixin("value_." ~ member ~ " = val;");]b4_locations_if([ mixin("value_." ~ member ~ " = val;");]b4_locations_if([
@@ -486,6 +489,6 @@ m4_define([b4_symbol_type_define],
} }
SymbolKind token() { return kind; } SymbolKind token() { return kind; }
]b4_yystype[ value() { return value_; }]b4_locations_if([[ ]b4_yystype[ value() { return value_; }]b4_locations_if([[
YYLocation location() { return location_; }]])[ Location location() { return location_; }]])[
} }
]]) ]])

View File

@@ -13847,20 +13847,20 @@ When the directive @code{%locations} is used, the D parser supports
location tracking, see @ref{Tracking Locations}. The position and location tracking, see @ref{Tracking Locations}. The position and
the location structures are provided. the location structures are provided.
@deftypeivar {YYLocation} {YYPosition} begin @deftypeivar {Location} {YYPosition} begin
@deftypeivarx {YYLocation} {YYPosition} end @deftypeivarx {Location} {YYPosition} end
The first, inclusive, position of the range, and the first beyond. The first, inclusive, position of the range, and the first beyond.
@end deftypeivar @end deftypeivar
@deftypeop {Constructor} {YYLocation} {} this(@code{YYPosition} @var{loc}) @deftypeop {Constructor} {Location} {} this(@code{YYPosition} @var{loc})
Create a @code{YYLocation} denoting an empty range located at a given point. Create a @code{Location} denoting an empty range located at a given point.
@end deftypeop @end deftypeop
@deftypeop {Constructor} {YYLocation} {} this(@code{YYPosition} @var{begin}, @code{YYPosition} @var{end}) @deftypeop {Constructor} {Location} {} this(@code{YYPosition} @var{begin}, @code{YYPosition} @var{end})
Create a @code{YYLocation} from the endpoints of the range. Create a @code{Location} from the endpoints of the range.
@end deftypeop @end deftypeop
@deftypemethod {YYLocation} {string} toString() @deftypemethod {Location} {string} toString()
Prints the range represented by the location. Prints the range represented by the location.
@end deftypemethod @end deftypemethod
@@ -13916,9 +13916,9 @@ which also turns on verbose error messages.
@end deftypemethod @end deftypemethod
@deftypemethod {YYParser} {void} yyerror(@code{string} @var{msg}) @deftypemethod {YYParser} {void} yyerror(@code{string} @var{msg})
@deftypemethodx {YYParser} {void} yyerror(@code{YYLocation} @var{loc}, @code{string} @var{msg}) @deftypemethodx {YYParser} {void} yyerror(@code{Location} @var{loc}, @code{string} @var{msg})
Print an error message using the @code{yyerror} method of the scanner Print an error message using the @code{yyerror} method of the scanner
instance in use. The @code{YYLocation} and @code{YYPosition} parameters are instance in use. The @code{Location} and @code{YYPosition} parameters are
available only if location tracking is active. available only if location tracking is active.
@end deftypemethod @end deftypemethod
@@ -14006,7 +14006,7 @@ case.
In both cases, the scanner has to implement the following methods. In both cases, the scanner has to implement the following methods.
@deftypemethod {Lexer} {void} yyerror(@code{YYLocation} @var{loc}, @code{string} @var{msg}) @deftypemethod {Lexer} {void} yyerror(@code{Location} @var{loc}, @code{string} @var{msg})
This method is defined by the user to emit an error message. The first This method is defined by the user to emit an error message. The first
parameter is omitted if location tracking is not active. parameter is omitted if location tracking is not active.
@end deftypemethod @end deftypemethod
@@ -16465,7 +16465,7 @@ London, Department of Computer Science, TR-00-12 (December 2000).
@c LocalWords: colorYellow rgbRed colorRed rgbBlue colorBlue rgbPurple Ddoc @c LocalWords: colorYellow rgbRed colorRed rgbBlue colorBlue rgbPurple Ddoc
@c LocalWords: colorPurple ifhtml ifnothtml situ rcex MERCHANTABILITY Wnone @c LocalWords: colorPurple ifhtml ifnothtml situ rcex MERCHANTABILITY Wnone
@c LocalWords: diagError diagNotice diagWarning diagOff danglingElseCex @c LocalWords: diagError diagNotice diagWarning diagOff danglingElseCex
@c LocalWords: YYLocation YYPosition nonunifying @c LocalWords: YYPosition nonunifying
@c Local Variables: @c Local Variables:
@c ispell-dictionary: "american" @c ispell-dictionary: "american"

View File

@@ -95,12 +95,12 @@ if (isInputRange!R && is(ElementType!R : dchar))
this(R r) { input = r; } this(R r) { input = r; }
YYLocation location; Location location;
// Should be a local in main, shared with %parse-param. // Should be a local in main, shared with %parse-param.
int exit_status = 0; int exit_status = 0;
void yyerror(const YYLocation loc, string s) void yyerror(const Location loc, string s)
{ {
exit_status = 1; exit_status = 1;
stderr.writeln(loc.toString(), ": ", s); stderr.writeln(loc.toString(), ": ", s);

View File

@@ -560,7 +560,7 @@ class CalcLexer(R) : Lexer
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
YYSemanticType semanticVal_;]AT_LOCATION_IF([[ YYSemanticType semanticVal_;]AT_LOCATION_IF([[
YYLocation location; Location location;
public final @property YYPosition startPos() public final @property YYPosition startPos()
{ {