[PRISM] Raise syntax errors when found
This commit is contained in:
parent
45dd8edf82
commit
44d0c5ae3f
@ -8495,6 +8495,7 @@ iseq.$(OBJEXT): $(top_srcdir)/internal/fixnum.h
|
|||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/hash.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/hash.h
|
||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
||||||
|
iseq.$(OBJEXT): $(top_srcdir)/internal/io.h
|
||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/numeric.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/numeric.h
|
||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/parse.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/parse.h
|
||||||
iseq.$(OBJEXT): $(top_srcdir)/internal/rational.h
|
iseq.$(OBJEXT): $(top_srcdir)/internal/rational.h
|
||||||
@ -8702,6 +8703,7 @@ iseq.$(OBJEXT): {$(VPATH)}internal/value_type.h
|
|||||||
iseq.$(OBJEXT): {$(VPATH)}internal/variable.h
|
iseq.$(OBJEXT): {$(VPATH)}internal/variable.h
|
||||||
iseq.$(OBJEXT): {$(VPATH)}internal/warning_push.h
|
iseq.$(OBJEXT): {$(VPATH)}internal/warning_push.h
|
||||||
iseq.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
|
iseq.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
|
||||||
|
iseq.$(OBJEXT): {$(VPATH)}io.h
|
||||||
iseq.$(OBJEXT): {$(VPATH)}iseq.c
|
iseq.$(OBJEXT): {$(VPATH)}iseq.c
|
||||||
iseq.$(OBJEXT): {$(VPATH)}iseq.h
|
iseq.$(OBJEXT): {$(VPATH)}iseq.h
|
||||||
iseq.$(OBJEXT): {$(VPATH)}method.h
|
iseq.$(OBJEXT): {$(VPATH)}method.h
|
||||||
|
18
iseq.c
18
iseq.c
@ -28,6 +28,7 @@
|
|||||||
#include "internal/file.h"
|
#include "internal/file.h"
|
||||||
#include "internal/gc.h"
|
#include "internal/gc.h"
|
||||||
#include "internal/hash.h"
|
#include "internal/hash.h"
|
||||||
|
#include "internal/io.h"
|
||||||
#include "internal/ruby_parser.h"
|
#include "internal/ruby_parser.h"
|
||||||
#include "internal/sanitizers.h"
|
#include "internal/sanitizers.h"
|
||||||
#include "internal/symbol.h"
|
#include "internal/symbol.h"
|
||||||
@ -1404,6 +1405,22 @@ static void
|
|||||||
iseqw_s_compile_prism_compile(pm_parser_t *parser, VALUE opt, rb_iseq_t *iseq, VALUE file, VALUE path, int first_lineno)
|
iseqw_s_compile_prism_compile(pm_parser_t *parser, VALUE opt, rb_iseq_t *iseq, VALUE file, VALUE path, int first_lineno)
|
||||||
{
|
{
|
||||||
pm_node_t *node = pm_parse(parser);
|
pm_node_t *node = pm_parse(parser);
|
||||||
|
|
||||||
|
if (parser->error_list.size > 0) {
|
||||||
|
pm_buffer_t buffer = { 0 };
|
||||||
|
pm_parser_errors_format(parser, &buffer, rb_stderr_tty_p());
|
||||||
|
|
||||||
|
pm_buffer_prepend_string(&buffer, "syntax errors found\n", 20);
|
||||||
|
VALUE error = rb_exc_new(rb_eSyntaxError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
|
||||||
|
|
||||||
|
pm_buffer_free(&buffer);
|
||||||
|
pm_node_destroy(parser, node);
|
||||||
|
|
||||||
|
// TODO: We need to set the backtrace based on the ISEQ.
|
||||||
|
// VALUE path = pathobj_path(ISEQ_BODY(iseq)->location.pathobj);
|
||||||
|
// rb_funcallv(error, rb_intern("set_backtrace"), 1, &path);
|
||||||
|
rb_exc_raise(error);
|
||||||
|
} else {
|
||||||
rb_code_location_t code_location;
|
rb_code_location_t code_location;
|
||||||
pm_code_location(&code_location, &parser->newline_list, &node->location);
|
pm_code_location(&code_location, &parser->newline_list, &node->location);
|
||||||
|
|
||||||
@ -1417,6 +1434,7 @@ iseqw_s_compile_prism_compile(pm_parser_t *parser, VALUE opt, rb_iseq_t *iseq, V
|
|||||||
|
|
||||||
finish_iseq_build(iseq);
|
finish_iseq_build(iseq);
|
||||||
pm_node_destroy(parser, node);
|
pm_node_destroy(parser, node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -801,12 +801,15 @@ class TestISeq < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_compile_prism_with_file
|
def test_compile_prism_with_file
|
||||||
Tempfile.create(%w"test_iseq .rb") do |f|
|
Tempfile.create(%w"test_iseq .rb") do |f|
|
||||||
f.puts "name = 'Prism'; puts 'hello"
|
f.puts "name = 'Prism'; puts 'hello'"
|
||||||
f.close
|
f.close
|
||||||
|
|
||||||
assert_nothing_raised(SyntaxError) {
|
assert_nothing_raised(TypeError) do
|
||||||
|
begin
|
||||||
RubyVM::InstructionSequence.compile_prism(f.path)
|
RubyVM::InstructionSequence.compile_prism(f.path)
|
||||||
}
|
rescue SyntaxError
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user