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

ruby-changes:36587

From: nobu <ko1@a...>
Date: Tue, 2 Dec 2014 02:53:10 +0900 (JST)
Subject: [ruby-changes:36587] nobu:r48668 (trunk): parse.y: enable encoding pragma in ripper

nobu	2014-12-02 02:53:02 +0900 (Tue, 02 Dec 2014)

  New Revision: 48668

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

  Log:
    parse.y: enable encoding pragma in ripper
    
    * parse.y (magic_comment_encoding): enable in ripper, since the
      encoding is necessary to parse non-default encoding scripts.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ripper/test_ripper.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48667)
+++ ChangeLog	(revision 48668)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  2 02:53:00 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (magic_comment_encoding): enable in ripper, since the
+	  encoding is necessary to parse non-default encoding scripts.
+
 Tue Dec  2 02:30:25 2014  NARUSE, Yui  <naruse@r...>
 
 	* lib/uri/generic.rb (URI::Generic.build):
Index: parse.y
===================================================================
--- parse.y	(revision 48667)
+++ parse.y	(revision 48668)
@@ -6845,7 +6845,6 @@ comment_at_top(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L6845
     return 1;
 }
 
-#ifndef RIPPER
 typedef long (*rb_magic_comment_length_t)(struct parser_params *parser, const char *name, long len);
 typedef void (*rb_magic_comment_setter_t)(struct parser_params *parser, const char *name, const char *val);
 
@@ -6858,6 +6857,7 @@ magic_comment_encoding(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L6857
     parser_set_encode(parser, val);
 }
 
+#ifndef RIPPER
 static int
 parser_get_bool(struct parser_params *parser, const char *name, const char *val)
 {
@@ -6883,6 +6883,7 @@ parser_set_token_info(struct parser_para https://github.com/ruby/ruby/blob/trunk/parse.y#L6883
     int b = parser_get_bool(parser, name, val);
     if (b >= 0) parser->parser_token_info_enabled = b;
 }
+#endif
 
 struct magic_comment {
     const char *name;
@@ -6893,9 +6894,10 @@ struct magic_comment { https://github.com/ruby/ruby/blob/trunk/parse.y#L6894
 static const struct magic_comment magic_comments[] = {
     {"coding", magic_comment_encoding, parser_encode_length},
     {"encoding", magic_comment_encoding, parser_encode_length},
+#ifndef RIPPER
     {"warn_indent", parser_set_token_info},
-};
 #endif
+};
 
 static const char *
 magic_comment_marker(const char *str, long len)
@@ -6948,9 +6950,7 @@ parser_magic_comment(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6950
 
     /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
     while (len > 0) {
-#ifndef RIPPER
 	const struct magic_comment *p = magic_comments;
-#endif
 	char *s;
 	int i;
 	long n = 0;
@@ -7003,19 +7003,19 @@ parser_magic_comment(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L7003
 	for (i = 0; i < n; ++i) {
 	    if (s[i] == '-') s[i] = '_';
 	}
-#ifndef RIPPER
 	do {
 	    if (STRNCASECMP(p->name, s, n) == 0) {
 		n = vend - vbeg;
 		if (p->length) {
 		    n = (*p->length)(parser, vbeg, n);
 		}
+		if (p->func != magic_comment_encoding) break;
 		str_copy(val, vbeg, n);
 		(*p->func)(parser, s, RSTRING_PTR(val));
 		break;
 	    }
 	} while (++p < magic_comments + numberof(magic_comments));
-#else
+#ifdef RIPPER
 	str_copy(val, vbeg, vend - vbeg);
 	dispatch2(magic_comment, name, val);
 #endif
Index: test/ripper/test_ripper.rb
===================================================================
--- test/ripper/test_ripper.rb	(revision 48667)
+++ test/ripper/test_ripper.rb	(revision 48668)
@@ -21,6 +21,9 @@ class TestRipper::Ripper < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ripper/test_ripper.rb#L21
     ripper = Ripper.new('# coding: iso-8859-15')
     ripper.parse
     assert_equal Encoding::ISO_8859_15, ripper.encoding
+    ripper = Ripper.new('# -*- coding: iso-8859-15 -*-')
+    ripper.parse
+    assert_equal Encoding::ISO_8859_15, ripper.encoding
   end
 
   def test_end_seen_eh

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

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