-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexerReader.cpp
More file actions
55 lines (49 loc) · 1.02 KB
/
Copy pathLexerReader.cpp
File metadata and controls
55 lines (49 loc) · 1.02 KB
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
52
53
54
55
#include "FileLexer.h"
LexerReader::LexerReader( const std::string &filename ) : mFileName( filename )
{
mFile.open( filename.c_str() );
}
char LexerReader::operator[]( int i )
{
std::streampos p = mFile.tellg();
std::streampos orig_p = p;
p += i;
mFile.seekg( p );
char c = mFile.peek();
mFile.seekg( orig_p );
return c;
}
char LexerReader::popChar()
{
char c = mFile.get();
// Track 1-based line/column of the next unconsumed character. Every
// character consumed advances the column by one (tabs included); a
// newline advances the line and resets the column. This is the single
// consumption funnel, so multi-line strings and block comments are
// counted correctly.
if ( c == '\n' )
{
mLine += 1;
mCol = 1;
}
else
{
mCol += 1;
}
return c;
}
void LexerReader::popChar( int count )
{
for ( int i = 0; i < count; i++ )
popChar();
}
char LexerReader::peekChar()
{
return mFile.peek();
}
bool LexerReader::isEOF()
{
// called to set the EOF flag if we are at the end.
mFile.peek();
return mFile.eof();
}