Touch up source index code.
This commit is contained in:
parent
c648e20a02
commit
2752703038
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user