1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

parse.y: flush invalid char

This commit is contained in:
Nobuyoshi Nakada 2019-05-29 12:48:49 +09:00
parent 8552e9d696
commit cc66272e50
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 14 additions and 2 deletions

View file

@ -66,9 +66,11 @@ module IRB # :nodoc:
class Lexer < Ripper::Lexer
if method_defined?(:token)
def on_parse_error(mesg)
def on_error(mesg)
@buf.push Elem.new([lineno(), column()], __callee__, token(), state())
end
alias on_parse_error on_error
alias compile_error on_error
end
end

View file

@ -9232,6 +9232,7 @@ parser_yylex(struct parser_params *p)
default:
if (!parser_is_identchar(p)) {
compile_error(p, "Invalid char `\\x%02X' in expression", c);
token_flush(p);
goto retry;
}

View file

@ -24,9 +24,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
lexer = Ripper::Lexer.new(str)
if error
lexer.singleton_class.class_eval do
define_method(:on_parse_error) {|ev|
define_method(:on_error) {|ev|
yield __callee__, ev, token()
}
alias on_parse_error on_error
alias compile_error on_error
end
end
lexer.lex.select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
@ -967,4 +969,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
scan('tlambda_arg', '-> {}')
end
def test_invalid_char
err = nil
assert_equal ['a'], scan('ident', "\ea") {|*e| err = e}
assert_equal :compile_error, err[0]
assert_match /Invalid char/, err[1]
assert_equal "\e", err[2]
end
end if ripper_test