d: tests: various style fixes

* tests/calc.at, tests/scanner.at: Here.
(yylex): Report values directly, without storing them to the union
first.
This commit is contained in:
Adela Vais
2021-01-25 17:59:06 +02:00
committed by Akim Demaille
parent b4582f1918
commit 689b184983
2 changed files with 28 additions and 39 deletions

View File

@@ -560,13 +560,10 @@ class CalcLexer(R) : Lexer
{
R input;
this(R r) {
input = r;
}
this(R r) { input = r; }
]AT_YYERROR_DEFINE[
Value value_;]AT_LOCATION_IF([[
]AT_LOCATION_IF([[
Location location;
]])[
int parseInt ()
@@ -584,7 +581,7 @@ class CalcLexer(R) : Lexer
Symbol yylex ()
{]AT_LOCATION_IF([[
location.begin = location.end;]])[
location.step();]])[
import std.uni : isWhite, isNumber;
@@ -592,9 +589,9 @@ class CalcLexer(R) : Lexer
while (!input.empty && input.front != '\n' && isWhite (input.front))
{
input.popFront;]AT_LOCATION_IF([[
location.begin.column += 1;
location.end.column += 1;]])[
}
}]AT_LOCATION_IF([[
location.step();]])[
// EOF.
if (input.empty)
@@ -602,10 +599,7 @@ class CalcLexer(R) : Lexer
// Numbers.
if (input.front.isNumber)
{
value_.ival = parseInt;
return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, value_.ival]AT_LOCATION_IF([[, location]])[);
}
return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, parseInt]AT_LOCATION_IF([[, location]])[);
// Individual characters
auto c = input.front;]AT_LOCATION_IF([[

View File

@@ -109,14 +109,10 @@ class YYLexer(R) : Lexer
{
R input;
this(R r) {
input = r;
}
this(R r) { input = r; }
]AT_YYERROR_DEFINE[
Value value_;
Symbol yylex ()
{
import std.uni : isNumber;
@@ -131,8 +127,7 @@ class YYLexer(R) : Lexer
switch (c)
{
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
value_.val = c - '0';
return Symbol(TokenKind.NUM, value_.val);
return Symbol(TokenKind.NUM, c - '0');
case '+': return Symbol(TokenKind.PLUS);
case '-': return Symbol(TokenKind.MINUS);
case '*': return Symbol(TokenKind.STAR);