mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
committed by
Akim Demaille
parent
cd99a1a923
commit
5aaa93ae72
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user