mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 15:53:03 +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,13 +129,27 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
if (input.front.isNumber)
|
if (input.front.isNumber)
|
||||||
{
|
{
|
||||||
int lenChars = 0;
|
int lenChars = 0;
|
||||||
auto copy = input;
|
import std.compiler : version_minor;
|
||||||
import std.conv : parse;
|
static if (version_minor >= 95)
|
||||||
value_.ival = input.parse!int;
|
|
||||||
while (!input.empty && copy.front != input.front)
|
|
||||||
{
|
{
|
||||||
lenChars++;
|
// from Dlang v2.095.0 onwards std.conv.parse reports
|
||||||
copy.popFront;
|
// 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;
|
||||||
|
while (!input.empty && copy.front != input.front)
|
||||||
|
{
|
||||||
|
lenChars++;
|
||||||
|
copy.popFront;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
location.begin = location.end;
|
location.begin = location.end;
|
||||||
location.end.column += lenChars;
|
location.end.column += lenChars;
|
||||||
|
|||||||
Reference in New Issue
Block a user