Touch up source index code.

This commit is contained in:
Danila Fedorin 2020-09-09 14:20:10 -07:00
parent 67cb61c93f
commit d5536467f6

View File

@ -29,6 +29,7 @@ struct parse_driver {
void run_parse() {
file_stream.open(file_name);
if(!file_stream.good()) throw 0;
line_offsets.push_back(0);
yyscan_t scanner;
scanner_init(this, &scanner);
yy::parser parser(scanner, *this);
@ -47,15 +48,16 @@ struct parse_driver {
}
size_t get_index(int line, int column) {
assert(line-1 < line_offsets.size());
size_t file_offset = line ? 0 : line_offsets[line-1];
assert(line > 0);
assert(line <= line_offsets.size());
size_t file_offset = line_offsets[line-1];
file_offset += column - 1;
return file_offset;
}
size_t get_line_end(int line) {
assert(line < line_offsets.size());
return line_offsets[line] - 1;
if(line > line_offsets.size()) return read_file.size();
return get_index(line+1, 1);
}
};