d: examples: calc: remove Value from Lexer

The Symbol constructor does not use it, so it is easier to not use
Value at all.

* examples/d/calc/calc.y: Here.
This commit is contained in:
Adela Vais
2021-01-16 15:20:09 +02:00
committed by Akim Demaille
parent cd99a1a923
commit 5aaa93ae72

View File

@@ -108,8 +108,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
stderr.writeln(loc.toString(), ": ", s); stderr.writeln(loc.toString(), ": ", s);
} }
Value value_;
Symbol yylex() Symbol yylex()
{ {
import std.uni : isWhite, isNumber; import std.uni : isWhite, isNumber;
@@ -128,6 +126,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
// Numbers. // Numbers.
if (input.front.isNumber) if (input.front.isNumber)
{ {
int ival;
int lenChars = 0; int lenChars = 0;
import std.compiler : version_minor; import std.compiler : version_minor;
static if (version_minor >= 95) static if (version_minor >= 95)
@@ -137,14 +136,14 @@ if (isInputRange!R && is(ElementType!R : dchar))
import std.typecons : Flag, Yes; import std.typecons : Flag, Yes;
import std.conv : parse; import std.conv : parse;
auto parsed = parse!(int, R, Yes.doCount)(input); auto parsed = parse!(int, R, Yes.doCount)(input);
value_.ival = parsed.data; ival = parsed.data;
lenChars = cast(int) parsed.count; lenChars = cast(int) parsed.count;
} }
else else
{ {
auto copy = input; auto copy = input;
import std.conv : parse; import std.conv : parse;
value.ival = input.parse!int; ival = input.parse!int;
while (!input.empty && copy.front != input.front) while (!input.empty && copy.front != input.front)
{ {
lenChars++; lenChars++;
@@ -153,7 +152,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
} }
location.begin = location.end; location.begin = location.end;
location.end.column += lenChars; location.end.column += lenChars;
return Symbol(TokenKind.NUM, value_.ival, location); return Symbol(TokenKind.NUM, ival, location);
} }
// Individual characters // Individual characters