diff options
author | Adela Vais <adela.vais99@gmail.com> | 2021-01-02 23:38:30 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2021-01-17 08:38:51 +0100 |
commit | cd99a1a923c652c4fc4fec8a6bc6f0db83b8b787 (patch) | |
tree | 6346c262e38b89bb5d988e8da37002170d87a139 /examples | |
parent | d53bbd5f0638033032bef9d42ab0134bb339b50b (diff) | |
download | bison-cd99a1a923c652c4fc4fec8a6bc6f0db83b8b787.tar.gz |
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.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/d/calc/calc.y | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y index 832d7788..640e246a 100644 --- a/examples/d/calc/calc.y +++ b/examples/d/calc/calc.y @@ -129,13 +129,27 @@ if (isInputRange!R && is(ElementType!R : dchar)) if (input.front.isNumber) { int lenChars = 0; - auto copy = input; - import std.conv : parse; - value_.ival = input.parse!int; - while (!input.empty && copy.front != input.front) + import std.compiler : version_minor; + static if (version_minor >= 95) { - lenChars++; - copy.popFront; + // 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; + while (!input.empty && copy.front != input.front) + { + lenChars++; + copy.popFront; + } } location.begin = location.end; location.end.column += lenChars; |