diff options
author | John Hodge <tpg@mutabah.net> | 2015-03-07 12:07:43 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-03-07 12:07:43 +0800 |
commit | fcec09900f158aa939eb1c96607aaabf4c8171ef (patch) | |
tree | eaac668a8d19b56fee0cdafb218ec069cdab8bc5 /src/parse/preproc.cpp | |
parent | a9692e359884672b30e1742bada368330115cc14 (diff) | |
download | mrust-fcec09900f158aa939eb1c96607aaabf4c8171ef.tar.gz |
Added file+line reporting to error messages
Diffstat (limited to 'src/parse/preproc.cpp')
-rw-r--r-- | src/parse/preproc.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
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 <iostream>
+#include <algorithm>
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();
|