mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix scanner event at invalid syntax
* parse.y (parser_yyerror, parser_compile_error): revert
r67224 (e5d10cda07
) "Flush erred
token".
This commit is contained in:
parent
f20af9543f
commit
02b39daef8
4 changed files with 21 additions and 8 deletions
2
parse.y
2
parse.y
|
@ -5558,7 +5558,6 @@ parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg)
|
|||
{
|
||||
dispatch1(parse_error, STR_NEW2(msg));
|
||||
ripper_error(p);
|
||||
token_flush(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -12260,7 +12259,6 @@ parser_compile_error(struct parser_params *p, const char *fmt, ...)
|
|||
rb_long2int(p->lex.pcur - p->lex.pbeg),
|
||||
p->enc, fmt, ap);
|
||||
va_end(ap);
|
||||
token_flush(p);
|
||||
}
|
||||
|
||||
static size_t
|
||||
|
|
|
@ -35,7 +35,7 @@ module TestIRB
|
|||
'"foo#{a} #{b}"' => "#{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}a#{RED}}#{CLEAR}#{RED} #{CLEAR}#{RED}\#{#{CLEAR}b#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
|
||||
'/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e#{RED}}#{CLEAR}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}",
|
||||
"'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}",
|
||||
"4.5.6" => "4.5.6",
|
||||
"4.5.6" => "#{MAGENTA}#{BOLD}4.5.6#{CLEAR}",
|
||||
"[1]]]" => "[1]]]",
|
||||
"\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n",
|
||||
"%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}",
|
||||
|
|
|
@ -19,9 +19,16 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def scan(target, str)
|
||||
def scan(target, str, &error)
|
||||
sym = "on_#{target}".intern
|
||||
Ripper.lex(str).select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
|
||||
lexer = Ripper::Lexer.new(str)
|
||||
if error
|
||||
lexer.singleton_class.class_eval do
|
||||
define_method(:compile_error, error)
|
||||
define_method(:on_parse_error, error)
|
||||
end
|
||||
end
|
||||
lexer.lex.select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
|
||||
end
|
||||
|
||||
def test_tokenize
|
||||
|
@ -927,6 +934,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
|||
scan('CHAR', "?a")
|
||||
assert_equal [],
|
||||
scan('CHAR', "@ivar")
|
||||
|
||||
assert_equal ["?\\M-H"], scan('CHAR', '?\\M-H')
|
||||
err = nil
|
||||
assert_equal ["?\\M"], scan('CHAR', '?\\M ') {|e| err = [__callee__, e]}
|
||||
assert_equal([:on_parse_error, "Invalid escape character syntax"], err)
|
||||
end
|
||||
|
||||
def test_label
|
||||
|
|
|
@ -246,9 +246,12 @@ class TestISeq < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
assert_equal([m1, e1.message], [m2, e2.message], feature11951)
|
||||
e1, *, e2 = e1.message.lines
|
||||
assert_send([e1, :start_with?, __FILE__])
|
||||
assert_send([e2, :start_with?, __FILE__])
|
||||
message = e1.message.each_line
|
||||
message.with_index(1) do |line, i|
|
||||
next if /^ / =~ line
|
||||
assert_send([line, :start_with?, __FILE__],
|
||||
proc {message.map {|l, j| (i == j ? ">" : " ") + l}.join("")})
|
||||
end
|
||||
end
|
||||
|
||||
def test_compile_file_error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue