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

ruby-changes:50525

From: nobu <ko1@a...>
Date: Mon, 5 Mar 2018 17:33:00 +0900 (JST)
Subject: [ruby-changes:50525] nobu:r62663 (trunk): parse.y: named whitespaces

nobu	2018-03-05 17:32:46 +0900 (Mon, 05 Mar 2018)

  New Revision: 62663

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

  Log:
    parse.y: named whitespaces
    
    * parse.y: named escaped whitespaces to show unexpected character.
      bare whitespaces should not appear outside of word_list.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 62662)
+++ parse.y	(revision 62663)
@@ -836,7 +836,13 @@ static void token_info_pop(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L836
 %type <id>   f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon
 %token END_OF_INPUT 0	"end-of-input"
 %token <id> '.'
+/* escaped chars, should be ignored otherwise */
 %token <id> '\\'	"backslash"
+%token <id> ' ' 	"escaped space"
+%token <id> '\t' 	"escaped horizontal tab"
+%token <id> '\f'	"escaped form feed"
+%token <id> '\r'	"escaped carriage return"
+%token <id> '\13'	"escaped vertical tab"
 %token tUPLUS		RUBY_TOKEN(UPLUS)  "unary+"
 %token tUMINUS		RUBY_TOKEN(UMINUS) "unary-"
 %token tPOW		RUBY_TOKEN(POW)    "**"
@@ -8095,6 +8101,7 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L8101
 	    dispatch_scan_event(p, tSP);
 	    goto retry; /* skip \\n */
 	}
+	if (ISSPACE(c)) return c;
 	pushback(p, c);
 	return '\\';
 
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 62662)
+++ test/ruby/test_parse.rb	(revision 62663)
@@ -1129,6 +1129,27 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1129
     end
   end
 
+  def test_whitespace_warning
+    assert_raise_with_message(SyntaxError, /backslash/) do
+      eval("\\foo")
+    end
+    assert_raise_with_message(SyntaxError, /escaped space/) do
+      eval("\\ ")
+    end
+    assert_raise_with_message(SyntaxError, /escaped horizontal tab/) do
+      eval("\\\t")
+    end
+    assert_raise_with_message(SyntaxError, /escaped form feed/) do
+      eval("\\\f")
+    end
+    assert_raise_with_message(SyntaxError, /escaped carriage return/) do
+      assert_warn(/middle of line/) {eval("\\\r")}
+    end
+    assert_raise_with_message(SyntaxError, /escaped vertical tab/) do
+      eval("\\\v")
+    end
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}

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

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