From: Mike D. Lowis Date: Tue, 29 May 2012 16:34:18 +0000 (-0400) Subject: Fixed line and column counting code in lexer X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1a5775e91faa2b6be48648d3f3322ea2a639551e;p=archive%2Fparse-utils.git Fixed line and column counting code in lexer --- 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); }