From fcec09900f158aa939eb1c96607aaabf4c8171ef Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 7 Mar 2015 12:07:43 +0800 Subject: Added file+line reporting to error messages --- src/parse/preproc.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/parse/preproc.cpp') diff --git a/src/parse/preproc.cpp b/src/parse/preproc.cpp index 3e2865b2..c8f0aeea 100644 --- a/src/parse/preproc.cpp +++ b/src/parse/preproc.cpp @@ -1,7 +1,10 @@ #include "preproc.hpp" #include +#include Preproc::Preproc(::std::string path): + m_path(path), + m_line(1), m_lex(path) { //ctor @@ -20,16 +23,25 @@ Token Preproc::getTokenInt() //::std::cout << "getTokenInt: tok = " << tok << ::std::endl; switch(tok.type()) { - case TOK_WHITESPACE: + case TOK_NEWLINE: + m_line ++; continue; - case TOK_COMMENT: + case TOK_WHITESPACE: continue; + case TOK_COMMENT: { + ::std::string comment = tok.str(); + m_line += ::std::count(comment.begin(), comment.end(), '\n'); + continue; } default: return tok; } } } +Position Preproc::getPosition() const +{ + return Position(m_path, m_line); +} Token Preproc::realGetToken() { return getTokenInt(); -- cgit v1.2.3