mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
d: examples: calc: use of std.conv.parse for location
From Dlang v2.095.0 onwards, std.conv.parse reports the number of consumed characters. * examples/d/calc/calc.y: Here.
This commit is contained in:
committed by
Akim Demaille
parent
d53bbd5f06
commit
cd99a1a923
@@ -129,14 +129,28 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
if (input.front.isNumber)
|
||||
{
|
||||
int lenChars = 0;
|
||||
import std.compiler : version_minor;
|
||||
static if (version_minor >= 95)
|
||||
{
|
||||
// from Dlang v2.095.0 onwards std.conv.parse reports
|
||||
// the number of consumed characters
|
||||
import std.typecons : Flag, Yes;
|
||||
import std.conv : parse;
|
||||
auto parsed = parse!(int, R, Yes.doCount)(input);
|
||||
value_.ival = parsed.data;
|
||||
lenChars = cast(int) parsed.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto copy = input;
|
||||
import std.conv : parse;
|
||||
value_.ival = input.parse!int;
|
||||
value.ival = input.parse!int;
|
||||
while (!input.empty && copy.front != input.front)
|
||||
{
|
||||
lenChars++;
|
||||
copy.popFront;
|
||||
}
|
||||
}
|
||||
location.begin = location.end;
|
||||
location.end.column += lenChars;
|
||||
return Symbol(TokenKind.NUM, value_.ival, location);
|
||||
|
||||
Reference in New Issue
Block a user