Skip to content

Commit

Permalink
d: remove unnecessary methods from the Lexer interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adelavais authored and akimd committed Dec 21, 2020
1 parent 27109d9 commit 32bb538
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 69 deletions.
18 changes: 1 addition & 17 deletions data/skeletons/lalr1.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions doc/bison.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions examples/d/calc/calc.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions examples/d/simple/calc.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions tests/calc.at
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/d.at
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class CalcLexer(R) : Lexer
void yyerror(string s) {}

Value semanticVal_;
Value semanticVal() @property { return semanticVal_; }

Symbol yylex()
{
Expand Down
4 changes: 0 additions & 4 deletions tests/scanner.at
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ class YYLexer(R) : Lexer
]AT_YYERROR_DEFINE[

Value semanticVal_;
public final @property Value semanticVal ()
{
return semanticVal_;
}

Symbol yylex ()
{
Expand Down

0 comments on commit 32bb538

Please sign in to comment.