From eb03d86b63e26d6b524a86e10359a476c83f8af0 Mon Sep 17 00:00:00 2001 From: Shevek Date: Wed, 19 Jan 2011 18:53:09 +0000 Subject: Fix line offsets in read after unget. --- src/java/org/anarres/cpp/LexerSource.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/java/org/anarres/cpp/LexerSource.java b/src/java/org/anarres/cpp/LexerSource.java index d252569..90869bc 100644 --- a/src/java/org/anarres/cpp/LexerSource.java +++ b/src/java/org/anarres/cpp/LexerSource.java @@ -151,20 +151,25 @@ public class LexerSource extends Source { private int read() throws IOException, LexerException { + int c; assert ucount <= 2 : "Illegal ucount: " + ucount; switch (ucount) { case 2: ucount = 1; - return u1; + c = u1; + break; case 1: ucount = 0; - return u0; + c = u0; + break; + default: + if (reader == null) + c = -1; + else + c = reader.read(); + break; } - if (reader == null) - return -1; - - int c = reader.read(); switch (c) { case '\r': cr = true; @@ -188,6 +193,9 @@ public class LexerSource extends Source { lastcolumn = column; column = 0; break; + case -1: + cr = false; + break; default: cr = false; column++; -- cgit v1.2.3