ruby-changes:55900
From: Nobuyoshi <ko1@a...>
Date: Wed, 29 May 2019 13:28:42 +0900 (JST)
Subject: [ruby-changes:55900] Nobuyoshi Nakada: cc66272e50 (trunk): parse.y: flush invalid char
https://git.ruby-lang.org/ruby.git/commit/?id=cc66272e50 From cc66272e5061020cac6864bbc2f68f7d327ecfbb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 29 May 2019 12:48:49 +0900 Subject: parse.y: flush invalid char diff --git a/lib/irb/color.rb b/lib/irb/color.rb index aa4c60a..b53cc75 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -66,9 +66,11 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L66 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 diff --git a/parse.y b/parse.y index 091efa9..c8930d8 100644 --- a/parse.y +++ b/parse.y @@ -9232,6 +9232,7 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9232 default: if (!parser_is_identchar(p)) { compile_error(p, "Invalid char `\\x%02X' in expression", c); + token_flush(p); goto retry; } diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index 727e967..0b4814a 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -24,9 +24,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L24 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 https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L969 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/