summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y37
-rw-r--r--test/ruby/test_rubyoptions.rb25
3 files changed, 63 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 35d20289d2..36d4ecefd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Nov 14 16:48:56 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (parser_set_token_info): turn on/off with directives.
+ [ruby-core:25442]
+
Sun Nov 14 12:05:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (argf_readlines): forward to current_file for arguments
diff --git a/parse.y b/parse.y
index 71359a347b..13e18f21b5 100644
--- a/parse.y
+++ b/parse.y
@@ -247,6 +247,7 @@ struct parser_params {
VALUE coverage;
int nerr;
+ int parser_token_info_enabled;
token_info *parser_token_info;
#else
/* Ripper only */
@@ -4966,7 +4967,7 @@ token_info_push(struct parser_params *parser, const char *token)
{
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 @@ token_info_pop(struct parser_params *parser, const char *token)
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 @@ yycompile0(VALUE arg, int tracing)
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 @@ magic_comment_encoding(struct parser_params *parser, const char *name, const cha
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 @@ struct magic_comment {
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
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 169f12f590..e47060f354 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -313,6 +313,31 @@ class TestRubyOptions < Test::Unit::TestCase
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