From 20d657c1dd0317c6d620bfbb10186d5147bdd986 Mon Sep 17 00:00:00 2001 From: Adela Vais Date: Fri, 18 Dec 2020 19:53:32 +0200 Subject: [PATCH] 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. --- data/skeletons/d.m4 | 3 ++- data/skeletons/lalr1.d | 4 ++-- doc/bison.texi | 16 ++++++++-------- examples/d/calc/calc.y | 4 ++-- tests/calc.at | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4 index f4a4cb0b..331c06a8 100644 --- a/data/skeletons/d.m4 +++ b/data/skeletons/d.m4 @@ -456,7 +456,8 @@ m4_define([b4_public_types_declare], [[ alias Symbol = ]b4_parser_class[.Symbol; alias Value = ]b4_yystype[;]b4_locations_if([[ -alias Location = ]b4_location_type[;]])[ +alias Location = ]b4_location_type[; +alias Position = ]b4_position_type[;]])[ ]]) diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d index 23ec07cc..4a2dff38 100644 --- a/data/skeletons/lalr1.d +++ b/data/skeletons/lalr1.d @@ -57,12 +57,12 @@ public interface Lexer /** * Method to retrieve the beginning position of the last scanned token. * @@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. * @@return the first position beyond the last scanned token. */ - ]b4_position_type[ endPos (); + Position endPos (); ]])[ /** diff --git a/doc/bison.texi b/doc/bison.texi index cf2c633f..df169517 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -13847,16 +13847,16 @@ 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 {Location} {YYPosition} begin -@deftypeivarx {Location} {YYPosition} end +@deftypeivar {Location} {Position} begin +@deftypeivarx {Location} {Position} end The first, inclusive, position of the range, and the first beyond. @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. @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. @end deftypeop @@ -13918,7 +13918,7 @@ which also turns on verbose error messages. @deftypemethod {YYParser} {void} yyerror(@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{Location} and @code{YYPosition} parameters are +instance in use. The @code{Location} and @code{Position} parameters are available only if location tracking is active. @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. @end deftypemethod -@deftypemethod {Lexer} {YYPosition} getStartPos() -@deftypemethodx {Lexer} {YYPosition} getEndPos() +@deftypemethod {Lexer} {Position} getStartPos() +@deftypemethodx {Lexer} {Position} getEndPos() Return respectively the first position of the last token that @code{yylex} returned, and the first position beyond it. These methods are not needed 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: colorPurple ifhtml ifnothtml situ rcex MERCHANTABILITY Wnone @c LocalWords: diagError diagNotice diagWarning diagOff danglingElseCex -@c LocalWords: YYPosition nonunifying +@c LocalWords: nonunifying @c Local Variables: @c ispell-dictionary: "american" diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y index ab85111b..9599501f 100644 --- a/examples/d/calc/calc.y +++ b/examples/d/calc/calc.y @@ -168,12 +168,12 @@ if (isInputRange!R && is(ElementType!R : dchar)) } } - YYPosition startPos() const + Position startPos() const { return location.begin; } - YYPosition endPos() const + Position endPos() const { return location.end; } diff --git a/tests/calc.at b/tests/calc.at index ebd5768f..75b64e10 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -562,12 +562,12 @@ class CalcLexer(R) : Lexer Value semanticVal_;]AT_LOCATION_IF([[ Location location; - public final @property YYPosition startPos() + public final @property Position startPos() { return location.begin; } - public final @property YYPosition endPos() + public final @property Position endPos() { return location.end; }