mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 23:16:42 +02:00
parse.y: highlight yyerror
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
da0c6035ad
commit
d4764ef6e4
1 changed files with 35 additions and 15 deletions
50
parse.y
50
parse.y
|
@ -5351,7 +5351,7 @@ parser_yyerror(struct parser_params *parser, const YYLTYPE *yylloc, const char *
|
||||||
{
|
{
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
const int max_line_margin = 30;
|
const int max_line_margin = 30;
|
||||||
const char *p, *pe, *pt;
|
const char *p, *pe, *pt, *pb;
|
||||||
const char *pre = "", *post = "", *pend;
|
const char *pre = "", *post = "", *pend;
|
||||||
const char *code = "", *caret = "", *newline = "";
|
const char *code = "", *caret = "", *newline = "";
|
||||||
const char *lim;
|
const char *lim;
|
||||||
|
@ -5388,8 +5388,6 @@ parser_yyerror(struct parser_params *parser, const YYLTYPE *yylloc, const char *
|
||||||
|
|
||||||
len = pe - p;
|
len = pe - p;
|
||||||
if (len > 4) {
|
if (len > 4) {
|
||||||
char *p2;
|
|
||||||
|
|
||||||
if (p > lex_pbeg) {
|
if (p > lex_pbeg) {
|
||||||
p = rb_enc_prev_char(lex_pbeg, p, pt, rb_enc_get(lex_lastline));
|
p = rb_enc_prev_char(lex_pbeg, p, pt, rb_enc_get(lex_lastline));
|
||||||
if (p > lex_pbeg) pre = "...";
|
if (p > lex_pbeg) pre = "...";
|
||||||
|
@ -5398,17 +5396,42 @@ parser_yyerror(struct parser_params *parser, const YYLTYPE *yylloc, const char *
|
||||||
pe = rb_enc_prev_char(pt, pe, pend, rb_enc_get(lex_lastline));
|
pe = rb_enc_prev_char(pt, pe, pend, rb_enc_get(lex_lastline));
|
||||||
if (pe < pend) post = "...";
|
if (pe < pend) post = "...";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
pb = lex_pbeg;
|
||||||
|
if (ruby_sourceline == yylloc->first_loc.lineno) {
|
||||||
|
pb += yylloc->first_loc.column;
|
||||||
|
if (pb > pt) pb = pt;
|
||||||
|
}
|
||||||
|
if (pb < p) pb = p;
|
||||||
|
if (len <= 4 && yylloc->first_loc.lineno == yylloc->last_loc.lineno) {
|
||||||
|
compile_error(PARSER_ARG "%s", msg);
|
||||||
|
}
|
||||||
|
else if (!parser->error_buffer && rb_stderr_tty_p()) {
|
||||||
|
#define CSI_BEGIN "\033["
|
||||||
|
#define CSI_SGR "m"
|
||||||
|
compile_error(PARSER_ARG "%s\n"
|
||||||
|
CSI_BEGIN""CSI_SGR"%s" /* pre */
|
||||||
|
CSI_BEGIN"1"CSI_SGR"%.*s"
|
||||||
|
CSI_BEGIN"1;4"CSI_SGR"%.*s"
|
||||||
|
CSI_BEGIN";1"CSI_SGR"%.*s"
|
||||||
|
CSI_BEGIN""CSI_SGR"%s" /* post */,
|
||||||
|
msg, pre,
|
||||||
|
(int)(pb - p), p,
|
||||||
|
(int)(pt - pb), pb,
|
||||||
|
(int)(pe - pt), pt,
|
||||||
|
post);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char *p2;
|
||||||
|
|
||||||
len = pe - p;
|
len = pe - p;
|
||||||
lim = pt < pend ? pt : pend;
|
lim = pt < pend ? pt : pend;
|
||||||
i = (int)(lim - p);
|
i = (int)(lim - p);
|
||||||
buf = ALLOCA_N(char, i+2);
|
buf = ALLOCA_N(char, i+2);
|
||||||
code = p;
|
code = p;
|
||||||
caret = p2 = buf;
|
caret = p2 = buf;
|
||||||
pe = (ruby_sourceline == yylloc->first_loc.lineno) ?
|
if (p <= pb) {
|
||||||
parser->tokp : lex_pbeg;
|
while (p < pb) {
|
||||||
if (pe > lim) pe = lim;
|
|
||||||
if (p <= pe) {
|
|
||||||
while (p < pe) {
|
|
||||||
*p2++ = *p++ == '\t' ? '\t' : ' ';
|
*p2++ = *p++ == '\t' ? '\t' : ' ';
|
||||||
}
|
}
|
||||||
*p2++ = '^';
|
*p2++ = '^';
|
||||||
|
@ -5420,14 +5443,11 @@ parser_yyerror(struct parser_params *parser, const YYLTYPE *yylloc, const char *
|
||||||
}
|
}
|
||||||
*p2 = '\0';
|
*p2 = '\0';
|
||||||
newline = "\n";
|
newline = "\n";
|
||||||
|
compile_error(PARSER_ARG "%s%s""%s%.*s%s%s""%s%s",
|
||||||
|
msg, newline,
|
||||||
|
pre, (int)len, code, post, newline,
|
||||||
|
pre, caret);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
compile_error(PARSER_ARG "%s%s""%s%.*s%s%s""%s%s",
|
|
||||||
msg, newline,
|
|
||||||
pre, (int)len, code, post, newline,
|
|
||||||
pre, caret);
|
|
||||||
#else
|
#else
|
||||||
dispatch1(parse_error, STR_NEW2(msg));
|
dispatch1(parse_error, STR_NEW2(msg));
|
||||||
ripper_error();
|
ripper_error();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue