Add a method to print location.
This commit is contained in:
parent
d5536467f6
commit
2fa2be4b9e
|
@ -59,6 +59,19 @@ struct parse_driver {
|
|||
if(line > line_offsets.size()) return read_file.size();
|
||||
return get_index(line+1, 1);
|
||||
}
|
||||
|
||||
void print_highlighted_location(std::ostream& stream, const yy::location& loc) {
|
||||
size_t print_start = get_index(loc.begin.line, 1);
|
||||
size_t highlight_start = get_index(loc.begin.line, loc.begin.column);
|
||||
size_t highlight_end = get_index(loc.end.line, loc.end.column);
|
||||
size_t print_end = get_line_end(loc.end.line);
|
||||
const char* content = read_file.c_str();
|
||||
stream.write(content + print_start, highlight_start - print_start);
|
||||
stream << "\033[4;31m";
|
||||
stream.write(content + highlight_start, highlight_end - highlight_start);
|
||||
stream << "\033[0m";
|
||||
stream.write(content + highlight_end, print_end - highlight_end);
|
||||
}
|
||||
};
|
||||
|
||||
#define YY_DECL yy::parser::symbol_type yylex(yyscan_t yyscanner, parse_driver& drv)
|
||||
|
|
Loading…
Reference in New Issue
Block a user