d: remove unnecessary methods from the Lexer interface

The complete symbol approach in yylex removes the need for the methods
semanticVal, startPos and endPos, which were used when the values were
reported separately.

* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Remove sections about the three methods.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Remove the unused methods.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
This commit is contained in:
Adela Vais
2020-12-21 15:49:27 +02:00
committed by Akim Demaille
parent 27109d9d4a
commit 32bb53870b
7 changed files with 1 additions and 69 deletions

View File

@@ -53,23 +53,7 @@ import std.format;
* parser <tt>]b4_parser_class[</tt>.
*/
public interface Lexer
{]b4_locations_if([[
/**
* Method to retrieve the beginning position of the last scanned token.
* @@return the position at which the last scanned token starts. */
Position startPos ();
/**
* Method to retrieve the ending position of the last scanned token.
* @@return the first position beyond the last scanned token. */
Position endPos ();
]])[
/**
* Method to retrieve the semantic value of the last scanned token.
* @@return the semantic value of the last scanned token. */
Value semanticVal ();
{
/**
* Entry point for the scanner. Returns the token identifier corresponding
* to the next token and prepares to return the semantic value

View File

@@ -14016,16 +14016,6 @@ 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} {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.
They should return new objects for each call, to avoid that all the symbol
share the same Position boundaries.
@end deftypemethod
@deftypemethod {Lexer} {void} reportSyntaxError(@code{YYParser.Context} @var{ctx})
If you invoke @samp{%define parse.error custom} (@pxref{Bison
Declarations}), then the parser no longer passes syntax error messages to

View File

@@ -108,11 +108,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
Value semanticVal_;
public final Value semanticVal()
{
return semanticVal_;
}
Symbol yylex()
{
import std.uni : isWhite, isNumber;
@@ -167,16 +162,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
default: assert(0);
}
}
Position startPos() const
{
return location.begin;
}
Position endPos() const
{
return location.end;
}
}
int main()

View File

@@ -102,13 +102,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
stderr.writeln(s);
}
Value semanticVal_;
public final Value semanticVal()
{
return semanticVal_;
}
Symbol yylex()
{
import std.uni : isWhite, isNumber;

View File

@@ -565,22 +565,7 @@ class CalcLexer(R) : Lexer
Value semanticVal_;]AT_LOCATION_IF([[
Location location;
public final @property Position startPos()
{
return location.begin;
}
public final @property Position endPos()
{
return location.end;
}
]])[
public final @property Value semanticVal()
{
return semanticVal_;
}
int parseInt ()
{
auto res = 0;

View File

@@ -79,7 +79,6 @@ class CalcLexer(R) : Lexer
void yyerror(string s) {}
Value semanticVal_;
Value semanticVal() @property { return semanticVal_; }
Symbol yylex()
{

View File

@@ -116,10 +116,6 @@ class YYLexer(R) : Lexer
]AT_YYERROR_DEFINE[
Value semanticVal_;
public final @property Value semanticVal ()
{
return semanticVal_;
}
Symbol yylex ()
{