From 8e44b24ba844df5c94b0eca380a694a07a9484d2 Mon Sep 17 00:00:00 2001 From: Adela Vais Date: Fri, 18 Dec 2020 17:31:57 +0200 Subject: [PATCH] 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. --- data/skeletons/d.m4 | 13 ++++++++----- doc/bison.texi | 22 +++++++++++----------- examples/d/calc/calc.y | 4 ++-- tests/calc.at | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4 index ee0d85a1..22a95440 100644 --- a/data/skeletons/d.m4 +++ b/data/skeletons/d.m4 @@ -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_; }]])[ } ]]) diff --git a/doc/bison.texi b/doc/bison.texi index 83612251..cf2c633f 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -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" diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y index c9a7df96..4353237b 100644 --- a/examples/d/calc/calc.y +++ b/examples/d/calc/calc.y @@ -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); diff --git a/tests/calc.at b/tests/calc.at index 9abf263d..976cea0a 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -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() {