Touch up source index code.
This commit is contained in:
parent
67cb61c93f
commit
d5536467f6
|
@ -29,6 +29,7 @@ struct parse_driver {
|
||||||
void run_parse() {
|
void run_parse() {
|
||||||
file_stream.open(file_name);
|
file_stream.open(file_name);
|
||||||
if(!file_stream.good()) throw 0;
|
if(!file_stream.good()) throw 0;
|
||||||
|
line_offsets.push_back(0);
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
scanner_init(this, &scanner);
|
scanner_init(this, &scanner);
|
||||||
yy::parser parser(scanner, *this);
|
yy::parser parser(scanner, *this);
|
||||||
|
@ -47,15 +48,16 @@ struct parse_driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t get_index(int line, int column) {
|
size_t get_index(int line, int column) {
|
||||||
assert(line-1 < line_offsets.size());
|
assert(line > 0);
|
||||||
size_t file_offset = line ? 0 : line_offsets[line-1];
|
assert(line <= line_offsets.size());
|
||||||
|
size_t file_offset = line_offsets[line-1];
|
||||||
file_offset += column - 1;
|
file_offset += column - 1;
|
||||||
return file_offset;
|
return file_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t get_line_end(int line) {
|
size_t get_line_end(int line) {
|
||||||
assert(line < line_offsets.size());
|
if(line > line_offsets.size()) return read_file.size();
|
||||||
return line_offsets[line] - 1;
|
return get_index(line+1, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user