summaryrefslogtreecommitdiff
path: root/src/parse/preproc.cpp
blob: 781ea8bc11a3b69b379f8a2269e523b44556bea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "preproc.hpp"
#include <iostream>
#include <algorithm>

Preproc::Preproc(::std::string path):
    m_path(path),
    m_line(1),
    m_lex(path)
{
    //ctor
}

Preproc::~Preproc()
{
    //dtor
}

Token Preproc::getTokenInt()
{
    while(true)
    {
        Token tok = m_lex.getToken();
        //::std::cout << "getTokenInt: tok = " << tok << ::std::endl;
        switch(tok.type())
        {
        case TOK_NEWLINE:
            m_line ++;
            //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;
        }
    }
}

Position Preproc::getPosition() const
{
    return Position(m_path, m_line);
}
Token Preproc::realGetToken()
{
    return getTokenInt();
}