ruby-changes:17771
From: nobu <ko1@a...>
Date: Sun, 14 Nov 2010 16:56:06 +0900 (JST)
Subject: [ruby-changes:17771] Ruby:r29782 (trunk): * parse.y (parser_set_token_info): turn on/off with directives.
nobu 2010-11-14 16:49:06 +0900 (Sun, 14 Nov 2010) New Revision: 29782 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29782 Log: * parse.y (parser_set_token_info): turn on/off with directives. [ruby-core:25442] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_rubyoptions.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29781) +++ ChangeLog (revision 29782) @@ -1,3 +1,8 @@ +Sun Nov 14 16:48:56 2010 Nobuyoshi Nakada <nobu@r...> + + * parse.y (parser_set_token_info): turn on/off with directives. + [ruby-core:25442] + Sun Nov 14 12:05:24 2010 Nobuyoshi Nakada <nobu@r...> * io.c (argf_readlines): forward to current_file for arguments Index: parse.y =================================================================== --- parse.y (revision 29781) +++ parse.y (revision 29782) @@ -247,6 +247,7 @@ VALUE coverage; int nerr; + int parser_token_info_enabled; token_info *parser_token_info; #else /* Ripper only */ @@ -4966,7 +4967,7 @@ { token_info *ptinfo; - if (compile_for_eval) return; + if (!parser->parser_token_info_enabled) return; ptinfo = ALLOC(token_info); ptinfo->token = token; ptinfo->linenum = ruby_sourceline; @@ -4996,9 +4997,11 @@ if (token_info_has_nonspaces(parser, token) || ptinfo->nonspc) { /* SKIP */ goto finish; } - rb_compile_warning(ruby_sourcefile, linenum, - "mismatched indentations at '%s' with '%s' at %d", - token, ptinfo->token, ptinfo->linenum); + if (parser->parser_token_info_enabled) { + rb_compile_warn(ruby_sourcefile, linenum, + "mismatched indentations at '%s' with '%s' at %d", + token, ptinfo->token, ptinfo->linenum); + } finish: xfree(ptinfo); @@ -5137,6 +5140,9 @@ parser_prepare(parser); deferred_nodes = 0; +#ifndef RIPPER + parser->parser_token_info_enabled = !compile_for_eval && RTEST(ruby_verbose); +#endif n = yyparse((void*)parser); ruby_debug_lines = 0; ruby_coverage = 0; @@ -6258,6 +6264,28 @@ parser_set_encode(parser, val); } +static void +parser_set_token_info(struct parser_params *parser, const char *name, const char *val) +{ + int *p = &parser->parser_token_info_enabled; + + switch (*val) { + case 't': case 'T': + if (strcasecmp(val, "true") == 0) { + *p = TRUE; + return; + } + break; + case 'f': case 'F': + if (strcasecmp(val, "false") == 0) { + *p = FALSE; + return; + } + break; + } + rb_compile_warning(ruby_sourcefile, ruby_sourceline, "invalid value for %s: %s", name, val); +} + struct magic_comment { const char *name; rb_magic_comment_setter_t func; @@ -6267,6 +6295,7 @@ static const struct magic_comment magic_comments[] = { {"coding", magic_comment_encoding, parser_encode_length}, {"encoding", magic_comment_encoding, parser_encode_length}, + {"warn_indent", parser_set_token_info}, }; #endif Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 29781) +++ test/ruby/test_rubyoptions.rb (revision 29782) @@ -313,6 +313,31 @@ err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"] assert_in_out_err(["-w", t.path], "", [], err) assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err) + + t.open + t.puts "# -*- warn-indent: false -*-" + t.puts "begin" + t.puts " end" + t.close + assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]') + + err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 3"] + t.open + t.puts "# -*- warn-indent: false -*-" + t.puts "# -*- warn-indent: true -*-" + t.puts "begin" + t.puts " end" + t.close + assert_in_out_err(["-w", t.path], "", [], err, '[ruby-core:25442]') + + err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 2"] + t.open + t.puts "# -*- warn-indent: true -*-" + t.puts "begin" + t.puts "# -*- warn-indent: false -*-" + t.puts " end" + t.close + assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]') ensure t.close(true) if t end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/