[Bug #19016] SyntaxError
with parser error messages
Raise a `SyntaxError` with the parser error message, in the case reading from a file instead of the `-e` option or standard input. So syntax_suggest can get the message from the caught error.
This commit is contained in:
parent
5b959e238e
commit
b7a0ce32da
Notes:
git
2022-11-21 15:33:39 +00:00
5
ruby.c
5
ruby.c
@ -2085,11 +2085,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
ruby_set_argv(argc, argv);
|
ruby_set_argv(argc, argv);
|
||||||
process_sflag(&opt->sflag);
|
process_sflag(&opt->sflag);
|
||||||
|
|
||||||
rb_parser_set_context(parser, 0, TRUE);
|
|
||||||
|
|
||||||
if (opt->e_script) {
|
if (opt->e_script) {
|
||||||
VALUE progname = rb_progname;
|
VALUE progname = rb_progname;
|
||||||
rb_encoding *eenc;
|
rb_encoding *eenc;
|
||||||
|
rb_parser_set_context(parser, 0, TRUE);
|
||||||
|
|
||||||
if (opt->src.enc.index >= 0) {
|
if (opt->src.enc.index >= 0) {
|
||||||
eenc = rb_enc_from_index(opt->src.enc.index);
|
eenc = rb_enc_from_index(opt->src.enc.index);
|
||||||
}
|
}
|
||||||
@ -2114,6 +2114,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
else {
|
else {
|
||||||
VALUE f;
|
VALUE f;
|
||||||
f = open_load_file(script_name, &opt->xflag);
|
f = open_load_file(script_name, &opt->xflag);
|
||||||
|
rb_parser_set_context(parser, 0, f == rb_stdin);
|
||||||
ast = load_file(parser, opt->script_name, f, 1, opt);
|
ast = load_file(parser, opt->script_name, f, 1, opt);
|
||||||
}
|
}
|
||||||
ruby_set_script_name(opt->script_name);
|
ruby_set_script_name(opt->script_name);
|
||||||
|
@ -1473,6 +1473,18 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
|
|||||||
end;
|
end;
|
||||||
pattern = /^<detail\.rb>/
|
pattern = /^<detail\.rb>/
|
||||||
assert_in_out_err(%W[-r#{dir}/detail -], "1+", [], pattern)
|
assert_in_out_err(%W[-r#{dir}/detail -], "1+", [], pattern)
|
||||||
|
|
||||||
|
File.write(File.join(dir, "main.rb"), "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
begin;
|
||||||
|
1 +
|
||||||
|
end;
|
||||||
|
assert_in_out_err(%W[-r#{dir}/detail #{dir}/main.rb]) do |stdout, stderr,|
|
||||||
|
assert_empty(stdout)
|
||||||
|
assert_not_empty(stderr.grep(pattern))
|
||||||
|
error, = stderr.grep(/unexpected end-of-input/)
|
||||||
|
assert_not_nil(error)
|
||||||
|
assert_match(/<.*unexpected end-of-input.*>/, error)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user