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

ruby-changes:44874

From: nobu <ko1@a...>
Date: Wed, 30 Nov 2016 23:43:46 +0900 (JST)
Subject: [ruby-changes:44874] nobu:r56947 (trunk): parse.y: refine error message

nobu	2016-11-30 23:43:43 +0900 (Wed, 30 Nov 2016)

  New Revision: 56947

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

  Log:
    parse.y: refine error message
    
    * parse.y (parser_tokadd_utf8): refine error message at bad char
      in unicode escape, "invalid" instead of "unterminated".

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_unicode_escape.rb
Index: parse.y
===================================================================
--- parse.y	(revision 56946)
+++ parse.y	(revision 56947)
@@ -5794,9 +5794,9 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5794
     if (regexp_literal) { tokadd('\\'); tokadd('u'); }
 
     if (peek(open_brace)) {  /* handle \u{...} form */
+	int c, last = nextc();
 	do {
-            if (regexp_literal) { tokadd(*lex_p); }
-	    nextc();
+	    if (regexp_literal) tokadd(last);
 	    codepoint = scan_hex(lex_p, 6, &numlen);
 	    if (numlen == 0)  {
 		yyerror("invalid Unicode escape");
@@ -5808,15 +5808,15 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5808
 	    }
 	    parser_tokadd_codepoint(parser, encp,string_literal, regexp_literal,
 				    codepoint, (int)numlen);
-	} while (string_literal && (peek(' ') || peek('\t')));
+	    if (ISSPACE(c = nextc())) last = c;
+	} while (string_literal && c != close_brace);
 
-	if (!peek(close_brace)) {
+	if (c != close_brace) {
 	    yyerror("unterminated Unicode escape");
 	    return 0;
 	}
 
 	if (regexp_literal) tokadd(close_brace);
-	nextc();
     }
     else {			/* handle \uxxxx form */
 	codepoint = scan_hex(lex_p, 4, &numlen);
Index: test/ruby/test_unicode_escape.rb
===================================================================
--- test/ruby/test_unicode_escape.rb	(revision 56946)
+++ test/ruby/test_unicode_escape.rb	(revision 56947)
@@ -256,6 +256,10 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_unicode_escape.rb#L256
      assert_raise(SyntaxError) { eval %q("\ughij") }       # bad hex digits
      assert_raise(SyntaxError) { eval %q("\u{ghij}") }     # bad hex digits
 
+     assert_raise_with_message(SyntaxError, /invalid/) {
+       eval %q("\u{123.}")  # bad char
+     }
+
      assert_raise(SyntaxError) { eval %q("\u{123 456 }")}  # extra space
      assert_raise(SyntaxError) { eval %q("\u{ 123 456}")}  # extra space
      assert_raise(SyntaxError) { eval %q("\u{123  456}")}  # extra space

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

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