From ee5b54822cd08c11ae1b2060d28074d36aa45954 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 28 Mar 2019 10:19:08 +0000 Subject: parse.y: show error line separately * parse.y: show compile error and the error line separately, instead of building the error message by snprintf then yyerror. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index a95337efd1..bc7fedb436 100644 --- a/parse.y +++ b/parse.y @@ -5462,11 +5462,9 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp, else if (codepoint >= 0x80) { rb_encoding *utf8 = rb_utf8_encoding(); if (*encp && utf8 != *encp) { - static const char mixed_utf8[] = "UTF-8 mixed within %s source"; - size_t len = sizeof(mixed_utf8) - 2 + strlen(rb_enc_name(*encp)); - char *mesg = alloca(len); - snprintf(mesg, len, mixed_utf8, rb_enc_name(*encp)); - yyerror0(mesg); + YYLTYPE loc = RUBY_INIT_YYLLOC(); + compile_error(p, "UTF-8 mixed within %s source", rb_enc_name(*encp)); + parser_show_error_line(p, &loc); return wide; } *encp = utf8; @@ -5791,12 +5789,10 @@ parser_update_heredoc_indent(struct parser_params *p, int c) static void parser_mixed_error(struct parser_params *p, rb_encoding *enc1, rb_encoding *enc2) { - static const char mixed_msg[] = "%s mixed within %s source"; + YYLTYPE loc = RUBY_INIT_YYLLOC(); const char *n1 = rb_enc_name(enc1), *n2 = rb_enc_name(enc2); - const size_t len = sizeof(mixed_msg) - 4 + strlen(n1) + strlen(n2); - char *errbuf = ALLOCA_N(char, len); - snprintf(errbuf, len, mixed_msg, n1, n2); - yyerror0(errbuf); + compile_error(p, "%s mixed within %s source", n1, n2); + parser_show_error_line(p, &loc); } static void @@ -7280,11 +7276,11 @@ parse_numeric(struct parser_params *p, int c) decode_num: pushback(p, c); if (nondigit) { - char tmp[30]; trailing_uc: literal_flush(p, p->lex.pcur - 1); - snprintf(tmp, sizeof(tmp), "trailing `%c' in number", nondigit); - yyerror0(tmp); + YYLTYPE loc = RUBY_INIT_YYLLOC(); + compile_error(p, "trailing `%c' in number", nondigit); + parser_show_error_line(p, &loc); } tokfix(p); if (is_float) { -- cgit v1.2.3