diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-28 20:16:54 +1100 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-28 20:16:54 +1100 |
commit | bd913f6259896ce7317061e3607f3c8fd2371d89 (patch) | |
tree | 381476e18201debdf2b111774c5e2d266f4c336c | |
parent | 84d8ce671f485f586ee2c1f21e11854aeaaf0c7c (diff) | |
download | mrust-bd913f6259896ce7317061e3607f3c8fd2371d89.tar.gz |
Lex - Fix newline handling (possible off-by-one, but no off-by-heaps)
-rw-r--r-- | src/parse/lex.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 9b09b1d4..5657c908 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -248,17 +248,10 @@ Token Lexer::realGetToken() switch(tok.type()) { case TOK_NEWLINE: - m_line ++; - m_line_ofs = 0; - //DEBUG("m_line = " << m_line << " (NL)"); continue; case TOK_WHITESPACE: continue; case TOK_COMMENT: { - ::std::string comment = tok.str(); - unsigned int c = ::std::count(comment.begin(), comment.end(), '\n'); - m_line += c; - //DEBUG("m_line = " << m_line << " (comment w/ "<<c<<")"); continue; } default: return tok; @@ -656,7 +649,6 @@ Token Lexer::getTokenInt() } else { - if( ch == '\n') m_line ++; str += ch; } } @@ -863,7 +855,6 @@ uint32_t Lexer::parseEscape(char enclosing) return '\t'; case '\r': case '\n': - m_line ++; while( ch.isspace() ) ch = this->getc(); this->ungetc(); @@ -881,6 +872,13 @@ char Lexer::getc_byte() char rv = m_istream.get(); if( m_istream.eof() ) throw Lexer::EndOfFile(); + + if( rv == '\n' ) + { + m_line ++; + m_line_ofs = 0; + } + return rv; } Codepoint Lexer::getc() |