mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
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:
committed by
Akim Demaille
parent
27109d9d4a
commit
32bb53870b
@@ -53,23 +53,7 @@ import std.format;
|
|||||||
* parser <tt>]b4_parser_class[</tt>.
|
* parser <tt>]b4_parser_class[</tt>.
|
||||||
*/
|
*/
|
||||||
public interface Lexer
|
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
|
* Entry point for the scanner. Returns the token identifier corresponding
|
||||||
* to the next token and prepares to return the semantic value
|
* to the next token and prepares to return the semantic value
|
||||||
|
|||||||
@@ -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.
|
binds together the kind, the semantic value and the location.
|
||||||
@end deftypemethod
|
@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})
|
@deftypemethod {Lexer} {void} reportSyntaxError(@code{YYParser.Context} @var{ctx})
|
||||||
If you invoke @samp{%define parse.error custom} (@pxref{Bison
|
If you invoke @samp{%define parse.error custom} (@pxref{Bison
|
||||||
Declarations}), then the parser no longer passes syntax error messages to
|
Declarations}), then the parser no longer passes syntax error messages to
|
||||||
|
|||||||
@@ -108,11 +108,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
|
|
||||||
Value semanticVal_;
|
Value semanticVal_;
|
||||||
|
|
||||||
public final Value semanticVal()
|
|
||||||
{
|
|
||||||
return semanticVal_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol yylex()
|
Symbol yylex()
|
||||||
{
|
{
|
||||||
import std.uni : isWhite, isNumber;
|
import std.uni : isWhite, isNumber;
|
||||||
@@ -167,16 +162,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
default: assert(0);
|
default: assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Position startPos() const
|
|
||||||
{
|
|
||||||
return location.begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
Position endPos() const
|
|
||||||
{
|
|
||||||
return location.end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|||||||
@@ -102,13 +102,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
stderr.writeln(s);
|
stderr.writeln(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value semanticVal_;
|
|
||||||
|
|
||||||
public final Value semanticVal()
|
|
||||||
{
|
|
||||||
return semanticVal_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol yylex()
|
Symbol yylex()
|
||||||
{
|
{
|
||||||
import std.uni : isWhite, isNumber;
|
import std.uni : isWhite, isNumber;
|
||||||
|
|||||||
@@ -565,22 +565,7 @@ class CalcLexer(R) : Lexer
|
|||||||
|
|
||||||
Value semanticVal_;]AT_LOCATION_IF([[
|
Value semanticVal_;]AT_LOCATION_IF([[
|
||||||
Location location;
|
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 ()
|
int parseInt ()
|
||||||
{
|
{
|
||||||
auto res = 0;
|
auto res = 0;
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ class CalcLexer(R) : Lexer
|
|||||||
void yyerror(string s) {}
|
void yyerror(string s) {}
|
||||||
|
|
||||||
Value semanticVal_;
|
Value semanticVal_;
|
||||||
Value semanticVal() @property { return semanticVal_; }
|
|
||||||
|
|
||||||
Symbol yylex()
|
Symbol yylex()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,10 +116,6 @@ class YYLexer(R) : Lexer
|
|||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
|
|
||||||
Value semanticVal_;
|
Value semanticVal_;
|
||||||
public final @property Value semanticVal ()
|
|
||||||
{
|
|
||||||
return semanticVal_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol yylex ()
|
Symbol yylex ()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user