* parse.y (parser_set_token_info): turn on/off with directives.
[ruby-core:25442] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f2dd4eb3cc
commit
b5c3fb2465
@ -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>
|
Sun Nov 14 12:05:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (argf_readlines): forward to current_file for arguments
|
* io.c (argf_readlines): forward to current_file for arguments
|
||||||
|
37
parse.y
37
parse.y
@ -247,6 +247,7 @@ struct parser_params {
|
|||||||
VALUE coverage;
|
VALUE coverage;
|
||||||
int nerr;
|
int nerr;
|
||||||
|
|
||||||
|
int parser_token_info_enabled;
|
||||||
token_info *parser_token_info;
|
token_info *parser_token_info;
|
||||||
#else
|
#else
|
||||||
/* Ripper only */
|
/* Ripper only */
|
||||||
@ -4966,7 +4967,7 @@ token_info_push(struct parser_params *parser, const char *token)
|
|||||||
{
|
{
|
||||||
token_info *ptinfo;
|
token_info *ptinfo;
|
||||||
|
|
||||||
if (compile_for_eval) return;
|
if (!parser->parser_token_info_enabled) return;
|
||||||
ptinfo = ALLOC(token_info);
|
ptinfo = ALLOC(token_info);
|
||||||
ptinfo->token = token;
|
ptinfo->token = token;
|
||||||
ptinfo->linenum = ruby_sourceline;
|
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 */
|
if (token_info_has_nonspaces(parser, token) || ptinfo->nonspc) { /* SKIP */
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
rb_compile_warning(ruby_sourcefile, linenum,
|
if (parser->parser_token_info_enabled) {
|
||||||
"mismatched indentations at '%s' with '%s' at %d",
|
rb_compile_warn(ruby_sourcefile, linenum,
|
||||||
token, ptinfo->token, ptinfo->linenum);
|
"mismatched indentations at '%s' with '%s' at %d",
|
||||||
|
token, ptinfo->token, ptinfo->linenum);
|
||||||
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
xfree(ptinfo);
|
xfree(ptinfo);
|
||||||
@ -5137,6 +5140,9 @@ yycompile0(VALUE arg, int tracing)
|
|||||||
|
|
||||||
parser_prepare(parser);
|
parser_prepare(parser);
|
||||||
deferred_nodes = 0;
|
deferred_nodes = 0;
|
||||||
|
#ifndef RIPPER
|
||||||
|
parser->parser_token_info_enabled = !compile_for_eval && RTEST(ruby_verbose);
|
||||||
|
#endif
|
||||||
n = yyparse((void*)parser);
|
n = yyparse((void*)parser);
|
||||||
ruby_debug_lines = 0;
|
ruby_debug_lines = 0;
|
||||||
ruby_coverage = 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);
|
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 {
|
struct magic_comment {
|
||||||
const char *name;
|
const char *name;
|
||||||
rb_magic_comment_setter_t func;
|
rb_magic_comment_setter_t func;
|
||||||
@ -6267,6 +6295,7 @@ struct magic_comment {
|
|||||||
static const struct magic_comment magic_comments[] = {
|
static const struct magic_comment magic_comments[] = {
|
||||||
{"coding", magic_comment_encoding, parser_encode_length},
|
{"coding", magic_comment_encoding, parser_encode_length},
|
||||||
{"encoding", magic_comment_encoding, parser_encode_length},
|
{"encoding", magic_comment_encoding, parser_encode_length},
|
||||||
|
{"warn_indent", parser_set_token_info},
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -313,6 +313,31 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||||||
err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"]
|
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(["-w", t.path], "", [], err)
|
||||||
assert_in_out_err(["-wr", t.path, "-e", ""], "", [], 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
|
ensure
|
||||||
t.close(true) if t
|
t.close(true) if t
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user