mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
d: track locations
* configure.ac (DCFLAGS): Pass -g. * data/skeletons/d.m4 (b4_locations_if): Remove, let bison.m4's one do its job. * data/skeletons/lalr1.d (position): Leave filename empty by default. (position::toString): Don't print empty file names. (location::this): New ctor. (location::toString): Match the implementations of C/C++. (yy_semantic_null): Leave undefined, the previous implementation does not compile. * tests/calc.at: Improve the implementation for D. Enable more checks, in particular using locations. * tests/local.at (AT_YYERROR_DEFINE(d)): Fix its implementation.
This commit is contained in:
@@ -141,27 +141,56 @@ class CalcLexer(R) : Lexer
|
||||
{
|
||||
R input;
|
||||
|
||||
this(R r) { input = r; }
|
||||
|
||||
public void yyerror (string s)
|
||||
{
|
||||
stderr.writeln (s);
|
||||
this(R r) {
|
||||
input = r;
|
||||
}
|
||||
|
||||
YYSemanticType semanticVal_;
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
YYSemanticType semanticVal_;]AT_LOCATION_IF([[
|
||||
YYLocation location = new YYLocation;
|
||||
|
||||
public final @property YYPosition startPos()
|
||||
{
|
||||
return location.begin;
|
||||
}
|
||||
|
||||
public final @property YYPosition endPos()
|
||||
{
|
||||
return location.end;
|
||||
}
|
||||
]])[
|
||||
public final @property YYSemanticType semanticVal()
|
||||
{
|
||||
return semanticVal_;
|
||||
}
|
||||
|
||||
int yylex ()
|
||||
int parseInt ()
|
||||
{
|
||||
auto res = 0;
|
||||
import std.uni : isNumber;
|
||||
while (input.front.isNumber)
|
||||
{
|
||||
res = res * 10 + (input.front - '0');]AT_LOCATION_IF([[
|
||||
location.end.column += 1;]])[
|
||||
input.popFront;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int yylex ()
|
||||
{]AT_LOCATION_IF([[
|
||||
location.begin = location.end;]])[
|
||||
|
||||
import std.uni : isWhite, isNumber;
|
||||
|
||||
// Skip initial spaces
|
||||
while (!input.empty && input.front != '\n' && isWhite (input.front))
|
||||
input.popFront;
|
||||
{
|
||||
input.popFront;]AT_LOCATION_IF([[
|
||||
location.begin.column += 1;
|
||||
location.end.column += 1;]])[
|
||||
}
|
||||
|
||||
// Handle EOF.
|
||||
if (input.empty)
|
||||
@@ -170,13 +199,19 @@ class CalcLexer(R) : Lexer
|
||||
// Numbers.
|
||||
if (input.front.isNumber)
|
||||
{
|
||||
import std.conv : parse;
|
||||
semanticVal_.ival = input.parse!int;
|
||||
semanticVal_.ival = parseInt;
|
||||
return YYTokenType.NUM;
|
||||
}
|
||||
|
||||
// Individual characters
|
||||
auto c = input.front;
|
||||
auto c = input.front;]AT_LOCATION_IF([[
|
||||
if (c == '\n')
|
||||
{
|
||||
location.end.line += 1;
|
||||
location.end.column = 1;
|
||||
}
|
||||
else
|
||||
location.end.column += 1;]])[
|
||||
input.popFront;
|
||||
return c;
|
||||
}
|
||||
@@ -856,13 +891,13 @@ m4_define([AT_CHECK_CALC_LALR1_D],
|
||||
[AT_CHECK_CALC([%language "D" $1], [$2])])
|
||||
|
||||
AT_CHECK_CALC_LALR1_D([])
|
||||
#AT_CHECK_CALC_LALR1_D([%locations])
|
||||
AT_CHECK_CALC_LALR1_D([%locations])
|
||||
#AT_CHECK_CALC_LALR1_D([%locations %define api.location.type {Span}])
|
||||
AT_CHECK_CALC_LALR1_D([%define parse.error verbose %define api.prefix {calc} %verbose])
|
||||
|
||||
#AT_CHECK_CALC_LALR1_D([%debug])
|
||||
AT_CHECK_CALC_LALR1_D([%debug])
|
||||
|
||||
#AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %verbose])
|
||||
AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %verbose])
|
||||
#AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.token.prefix {TOK_} %verbose])
|
||||
|
||||
#AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %verbose %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
@@ -672,10 +672,9 @@ m4_define([AT_YYERROR_DECLARE_EXTERN(d)], [])
|
||||
|
||||
m4_define([AT_YYERROR_DEFINE(d)],
|
||||
[[/* An error reporting function. */
|
||||
public void error (]AT_LOCATION_IF([[location_type l, ]])[string m)
|
||||
public void yyerror (]AT_LOCATION_IF([[YYLocation l, ]])[string m)
|
||||
{
|
||||
// FIXME: location.
|
||||
stderr.writeln (m);
|
||||
stderr.writeln (]AT_LOCATION_IF([[l, ": ", ]])[m);
|
||||
}]])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user