[前][次][番号順一覧][スレッド一覧]

ruby-changes:55151

From: nobu <ko1@a...>
Date: Thu, 28 Mar 2019 19:19:14 +0900 (JST)
Subject: [ruby-changes:55151] nobu:r67358 (trunk): parse.y: show error line separately

nobu	2019-03-28 19:19:08 +0900 (Thu, 28 Mar 2019)

  New Revision: 67358

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67358

  Log:
    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.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 67357)
+++ parse.y	(revision 67358)
@@ -5462,11 +5462,9 @@ tokadd_codepoint(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L5462
     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 pars https://github.com/ruby/ruby/blob/trunk/parse.y#L5789
 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, i https://github.com/ruby/ruby/blob/trunk/parse.y#L7276
   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) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]