From c16fcaf2fb2f7e01605232d23ee48b90ed49121c Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 2 Feb 2020 09:18:00 +0100 Subject: [PATCH] java: example: properly track the locations This example, so far, was tracking the current token number, not the current column number. This is not nice for an example... * examples/java/Calc.y (PositionReader): New. Use it. * examples/java/Calc.test: Check the output. --- examples/java/Calc.test | 2 +- examples/java/Calc.y | 78 ++++++++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/examples/java/Calc.test b/examples/java/Calc.test index 996b20e0..b0d238f1 100644 --- a/examples/java/Calc.test +++ b/examples/java/Calc.test @@ -30,4 +30,4 @@ run 0 '7 cat >input < -1) { + char c = (char)res; + if (c == '\r' || c == '\n') { + position.line += 1; + position.column = 1; + } else { + position.column += 1; + } + } + return res; + } + + public Position getPosition () { + return position; } }