summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-07 14:04:49 (GMT)
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-07 14:04:49 (GMT)
commit66661034808e5e1dab0683aff4e74d72bba042cc (patch)
tree52f1e78daab93c7c25627a4c200c1c38b87a6a60 /ast.c
parentafa7bfee8f50ea1739ad198b2d1cd02a861ade46 (diff)
ast.c: Fix to raise `SyntaxError`
* ast.c: Fix to raise `SyntaxError` when `RubyVM::AST.parse` or `RubyVM::AST.parse_file` fail to parse input. * test/ruby/test_ast.rb: Add test cases for invalid syntax. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ast.c b/ast.c
index 1f0fde4..d295ff9 100644
--- a/ast.c
+++ b/ast.c
@@ -58,10 +58,13 @@ rb_ast_s_parse(VALUE module, VALUE str)
const VALUE parser = rb_parser_new();
str = rb_check_string_type(str);
- rb_parser_set_context(parser, NULL, 1);
+ rb_parser_set_context(parser, NULL, 0);
ast = rb_parser_compile_string_path(parser, rb_str_new_cstr("no file name"), str, 1);
- if (!ast->body.root) return Qnil;
+ if (!ast->body.root) {
+ rb_ast_dispose(ast);
+ rb_exc_raise(GET_EC()->errinfo);
+ }
obj = ast_new_internal(ast, (NODE *)ast->body.root);
@@ -80,12 +83,15 @@ rb_ast_s_parse_file(VALUE module, VALUE path)
FilePathValue(path);
f = rb_file_open_str(path, "r");
rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
- rb_parser_set_context(parser, NULL, 1);
+ rb_parser_set_context(parser, NULL, 0);
ast = rb_parser_compile_file_path(parser, path, f, 1);
rb_io_close(f);
- if (!ast->body.root) return Qnil;
+ if (!ast->body.root) {
+ rb_ast_dispose(ast);
+ rb_exc_raise(GET_EC()->errinfo);
+ }
obj = ast_new_internal(ast, (NODE *)ast->body.root);