From 1a5775e91faa2b6be48648d3f3322ea2a639551e Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Tue, 29 May 2012 12:34:18 -0400 Subject: [PATCH] Fixed line and column counting code in lexer --- source/lexer/ilexer.cpp | 2 +- source/lexer/llnlexer/llnlexer.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/lexer/ilexer.cpp b/source/lexer/ilexer.cpp index 66e8645..f3e684c 100644 --- a/source/lexer/ilexer.cpp +++ b/source/lexer/ilexer.cpp @@ -3,7 +3,7 @@ using namespace std; -ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in) +ILexer::ILexer(istream& in) : line(1), column(0), in_stream(in) { } diff --git a/source/lexer/llnlexer/llnlexer.cpp b/source/lexer/llnlexer/llnlexer.cpp index 9b26563..ce26d84 100644 --- a/source/lexer/llnlexer/llnlexer.cpp +++ b/source/lexer/llnlexer/llnlexer.cpp @@ -11,12 +11,23 @@ LLNLexer::~LLNLexer() void LLNLexer::consume(void) { + if( la_buffer.at(cur_idx) == '\n' ) + { + line++; + column = 0; + } + else + { + column++; + } + cur_idx++; if(cur_idx >= la_buffer.size()) { cur_idx = 0; la_buffer.clear(); } + sync(1); } -- 2.51.0