mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
committed by
Akim Demaille
parent
6692df8992
commit
8e44b24ba8
@@ -447,15 +447,18 @@ m4_define([b4_var_decls],
|
||||
m4_define([b4_var_decl],
|
||||
[ protected $1;])
|
||||
|
||||
|
||||
# b4_public_types_declare
|
||||
# -----------------------
|
||||
# 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.
|
||||
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
|
||||
# ---------------------
|
||||
# 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 ]b4_yystype[ value_;]b4_locations_if([[
|
||||
private YYLocation location_;]])[
|
||||
this(TokenKind token]b4_locations_if([[, YYLocation loc]])[)
|
||||
private Location location_;]])[
|
||||
this(TokenKind token]b4_locations_if([[, Location loc]])[)
|
||||
{
|
||||
kind = yytranslate_(token);]b4_locations_if([
|
||||
location_ = loc;])[
|
||||
}
|
||||
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);
|
||||
mixin("value_." ~ member ~ " = val;");]b4_locations_if([
|
||||
@@ -486,6 +489,6 @@ m4_define([b4_symbol_type_define],
|
||||
}
|
||||
SymbolKind token() { return kind; }
|
||||
]b4_yystype[ value() { return value_; }]b4_locations_if([[
|
||||
YYLocation location() { return location_; }]])[
|
||||
Location location() { return location_; }]])[
|
||||
}
|
||||
]])
|
||||
|
||||
@@ -13847,20 +13847,20 @@ When the directive @code{%locations} is used, the D parser supports
|
||||
location tracking, see @ref{Tracking Locations}. The position and
|
||||
the location structures are provided.
|
||||
|
||||
@deftypeivar {YYLocation} {YYPosition} begin
|
||||
@deftypeivarx {YYLocation} {YYPosition} end
|
||||
@deftypeivar {Location} {YYPosition} begin
|
||||
@deftypeivarx {Location} {YYPosition} end
|
||||
The first, inclusive, position of the range, and the first beyond.
|
||||
@end deftypeivar
|
||||
|
||||
@deftypeop {Constructor} {YYLocation} {} this(@code{YYPosition} @var{loc})
|
||||
Create a @code{YYLocation} denoting an empty range located at a given point.
|
||||
@deftypeop {Constructor} {Location} {} this(@code{YYPosition} @var{loc})
|
||||
Create a @code{Location} denoting an empty range located at a given point.
|
||||
@end deftypeop
|
||||
|
||||
@deftypeop {Constructor} {YYLocation} {} this(@code{YYPosition} @var{begin}, @code{YYPosition} @var{end})
|
||||
Create a @code{YYLocation} from the endpoints of the range.
|
||||
@deftypeop {Constructor} {Location} {} this(@code{YYPosition} @var{begin}, @code{YYPosition} @var{end})
|
||||
Create a @code{Location} from the endpoints of the range.
|
||||
@end deftypeop
|
||||
|
||||
@deftypemethod {YYLocation} {string} toString()
|
||||
@deftypemethod {Location} {string} toString()
|
||||
Prints the range represented by the location.
|
||||
@end deftypemethod
|
||||
|
||||
@@ -13916,9 +13916,9 @@ which also turns on verbose error messages.
|
||||
@end deftypemethod
|
||||
|
||||
@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
|
||||
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.
|
||||
@end deftypemethod
|
||||
|
||||
@@ -14006,7 +14006,7 @@ case.
|
||||
|
||||
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
|
||||
parameter is omitted if location tracking is not active.
|
||||
@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: colorPurple ifhtml ifnothtml situ rcex MERCHANTABILITY Wnone
|
||||
@c LocalWords: diagError diagNotice diagWarning diagOff danglingElseCex
|
||||
@c LocalWords: YYLocation YYPosition nonunifying
|
||||
@c LocalWords: YYPosition nonunifying
|
||||
|
||||
@c Local Variables:
|
||||
@c ispell-dictionary: "american"
|
||||
|
||||
@@ -95,12 +95,12 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
|
||||
this(R r) { input = r; }
|
||||
|
||||
YYLocation location;
|
||||
Location location;
|
||||
|
||||
// Should be a local in main, shared with %parse-param.
|
||||
int exit_status = 0;
|
||||
|
||||
void yyerror(const YYLocation loc, string s)
|
||||
void yyerror(const Location loc, string s)
|
||||
{
|
||||
exit_status = 1;
|
||||
stderr.writeln(loc.toString(), ": ", s);
|
||||
|
||||
@@ -560,7 +560,7 @@ class CalcLexer(R) : Lexer
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
YYSemanticType semanticVal_;]AT_LOCATION_IF([[
|
||||
YYLocation location;
|
||||
Location location;
|
||||
|
||||
public final @property YYPosition startPos()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user