d: create alias Position for YYPosition

* data/skeletons/d.m4 (b4_public_types_declare): Here.
* data/skeletons/lalr1.d: Adjust.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Use it.
* tests/calc.at: Test it.
This commit is contained in:
Adela Vais
2020-12-18 19:53:32 +02:00
committed by Akim Demaille
parent b00fa62e95
commit 20d657c1dd
5 changed files with 16 additions and 15 deletions

View File

@@ -456,7 +456,8 @@ m4_define([b4_public_types_declare],
[[ [[
alias Symbol = ]b4_parser_class[.Symbol; alias Symbol = ]b4_parser_class[.Symbol;
alias Value = ]b4_yystype[;]b4_locations_if([[ alias Value = ]b4_yystype[;]b4_locations_if([[
alias Location = ]b4_location_type[;]])[ alias Location = ]b4_location_type[;
alias Position = ]b4_position_type[;]])[
]]) ]])

View File

@@ -57,12 +57,12 @@ public interface Lexer
/** /**
* Method to retrieve the beginning position of the last scanned token. * Method to retrieve the beginning position of the last scanned token.
* @@return the position at which the last scanned token starts. */ * @@return the position at which the last scanned token starts. */
]b4_position_type[ startPos (); Position startPos ();
/** /**
* Method to retrieve the ending position of the last scanned token. * Method to retrieve the ending position of the last scanned token.
* @@return the first position beyond the last scanned token. */ * @@return the first position beyond the last scanned token. */
]b4_position_type[ endPos (); Position endPos ();
]])[ ]])[
/** /**

View File

@@ -13847,16 +13847,16 @@ 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 {Location} {YYPosition} begin @deftypeivar {Location} {Position} begin
@deftypeivarx {Location} {YYPosition} end @deftypeivarx {Location} {Position} 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} {Location} {} this(@code{YYPosition} @var{loc}) @deftypeop {Constructor} {Location} {} this(@code{Position} @var{loc})
Create a @code{Location} 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} {Location} {} this(@code{YYPosition} @var{begin}, @code{YYPosition} @var{end}) @deftypeop {Constructor} {Location} {} this(@code{Position} @var{begin}, @code{Position} @var{end})
Create a @code{Location} from the endpoints of the range. Create a @code{Location} from the endpoints of the range.
@end deftypeop @end deftypeop
@@ -13918,7 +13918,7 @@ which also turns on verbose error messages.
@deftypemethod {YYParser} {void} yyerror(@code{string} @var{msg}) @deftypemethod {YYParser} {void} yyerror(@code{string} @var{msg})
@deftypemethodx {YYParser} {void} yyerror(@code{Location} @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{Location} and @code{YYPosition} parameters are instance in use. The @code{Location} and @code{Position} parameters are
available only if location tracking is active. available only if location tracking is active.
@end deftypemethod @end deftypemethod
@@ -14016,8 +14016,8 @@ Return the next token. The return value is of type @code{Symbol}, which
binds together the kind, the semantic value and the location. binds together the kind, the semantic value and the location.
@end deftypemethod @end deftypemethod
@deftypemethod {Lexer} {YYPosition} getStartPos() @deftypemethod {Lexer} {Position} getStartPos()
@deftypemethodx {Lexer} {YYPosition} getEndPos() @deftypemethodx {Lexer} {Position} getEndPos()
Return respectively the first position of the last token that @code{yylex} Return respectively the first position of the last token that @code{yylex}
returned, and the first position beyond it. These methods are not needed returned, and the first position beyond it. These methods are not needed
unless location tracking is active. unless location tracking is active.
@@ -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: YYPosition nonunifying @c LocalWords: nonunifying
@c Local Variables: @c Local Variables:
@c ispell-dictionary: "american" @c ispell-dictionary: "american"

View File

@@ -168,12 +168,12 @@ if (isInputRange!R && is(ElementType!R : dchar))
} }
} }
YYPosition startPos() const Position startPos() const
{ {
return location.begin; return location.begin;
} }
YYPosition endPos() const Position endPos() const
{ {
return location.end; return location.end;
} }

View File

@@ -562,12 +562,12 @@ class CalcLexer(R) : Lexer
Value semanticVal_;]AT_LOCATION_IF([[ Value semanticVal_;]AT_LOCATION_IF([[
Location location; Location location;
public final @property YYPosition startPos() public final @property Position startPos()
{ {
return location.begin; return location.begin;
} }
public final @property YYPosition endPos() public final @property Position endPos()
{ {
return location.end; return location.end;
} }