aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-24 09:43:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-24 09:43:22 +0000
commit94090b0502fc65f15495fd329145c9f998f10ee3 (patch)
tree06cf68a9e42f2c91245f5d552468eeb59d14eed7 /parse.y
parent26984290eb4f20a4a2db2b8d461cd36a4a5b0e49 (diff)
downloadruby-94090b0502fc65f15495fd329145c9f998f10ee3.tar.gz
deprecate exposed internal functions
* error.c (rb_compile_error_with_enc, rb_compile_error), (rb_compile_bug): deprecate internal functions. * parse.y (parser_yyerror): construct exception message with source code and carret. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y32
1 files changed, 17 insertions, 15 deletions
diff --git a/parse.y b/parse.y
index 59614b6936..b0c5bd9e78 100644
--- a/parse.y
+++ b/parse.y
@@ -5409,11 +5409,12 @@ parser_yyerror(struct parser_params *parser, const char *msg)
#ifndef RIPPER
const int max_line_margin = 30;
const char *p, *pe;
+ const char *pre = "", *post = "";
+ const char *code = "", *carret = "", *newline = "";
char *buf;
long len;
int i;
- compile_error(PARSER_ARG "%s", msg);
p = lex_p;
while (lex_pbeg <= p) {
if (*p == '\n') break;
@@ -5430,7 +5431,6 @@ parser_yyerror(struct parser_params *parser, const char *msg)
len = pe - p;
if (len > 4) {
char *p2;
- const char *pre = "", *post = "";
if (len > max_line_margin * 2 + 10) {
if (lex_p - p > max_line_margin) {
@@ -5443,22 +5443,24 @@ parser_yyerror(struct parser_params *parser, const char *msg)
}
len = pe - p;
}
- buf = ALLOCA_N(char, len+2);
- MEMCPY(buf, p, char, len);
- buf[len] = '\0';
- rb_compile_error_with_enc(NULL, 0, (void *)current_enc, "%s%s%s", pre, buf, post);
-
i = (int)(lex_p - p);
- p2 = buf; pe = buf + len;
-
- while (p2 < pe) {
- if (*p2 != '\t') *p2 = ' ';
- p2++;
+ buf = ALLOCA_N(char, i+2);
+ code = p;
+ carret = p2 = buf;
+ while (i-- > 0) {
+ *p2++ = *p++ == '\t' ? '\t' : ' ';
}
- buf[i] = '^';
- buf[i+1] = '\0';
- rb_compile_error_append("%s%s", pre, buf);
+ *p2++ = '^';
+ *p2 = '\0';
+ newline = "\n";
+ }
+ else {
+ len = 0;
}
+ compile_error(PARSER_ARG "%s%s""%s%.*s%s%s""%s%s",
+ msg, newline,
+ pre, (int)len, code, post, newline,
+ pre, carret);
#else
dispatch1(parse_error, STR_NEW2(msg));
ripper_error();