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

parser: improve error messages

[Fix GH-2011]

From: Akim Demaille <akim.demaille@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-11-25 08:31:40 +00:00
parent 2b9448fd77
commit 87b03e8c3c
4 changed files with 53 additions and 53 deletions

98
parse.y
View file

@ -776,55 +776,55 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
} }
%token <id> %token <id>
keyword_class keyword_class "class"
keyword_module keyword_module "module"
keyword_def keyword_def "def"
keyword_undef keyword_undef "undef"
keyword_begin keyword_begin "begin"
keyword_rescue keyword_rescue "rescue"
keyword_ensure keyword_ensure "ensure"
keyword_end keyword_end "end"
keyword_if keyword_if "if"
keyword_unless keyword_unless "unless"
keyword_then keyword_then "then"
keyword_elsif keyword_elsif "elsif"
keyword_else keyword_else "else"
keyword_case keyword_case "case"
keyword_when keyword_when "when"
keyword_while keyword_while "while"
keyword_until keyword_until "until"
keyword_for keyword_for "for"
keyword_break keyword_break "break"
keyword_next keyword_next "next"
keyword_redo keyword_redo "redo"
keyword_retry keyword_retry "retry"
keyword_in keyword_in "in"
keyword_do keyword_do "do"
keyword_do_cond keyword_do_cond "do (for condition)"
keyword_do_block keyword_do_block "do (for block)"
keyword_do_LAMBDA keyword_do_LAMBDA "do (for lambda)"
keyword_return keyword_return "return"
keyword_yield keyword_yield "yield"
keyword_super keyword_super "super"
keyword_self keyword_self "self"
keyword_nil keyword_nil "nil"
keyword_true keyword_true "true"
keyword_false keyword_false "false"
keyword_and keyword_and "and"
keyword_or keyword_or "or"
keyword_not keyword_not "not"
modifier_if modifier_if "if (modifier)"
modifier_unless modifier_unless "unless (modifier)"
modifier_while modifier_while "while (modifier)"
modifier_until modifier_until "until (modifier)"
modifier_rescue modifier_rescue "rescue (modifier)"
keyword_alias keyword_alias "alias"
keyword_defined keyword_defined "defined?"
keyword_BEGIN keyword_BEGIN "BEGIN"
keyword_END keyword_END "END"
keyword__LINE__ keyword__LINE__ "__LINE__"
keyword__FILE__ keyword__FILE__ "__FILE__"
keyword__ENCODING__ keyword__ENCODING__ "__ENCODING__"
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR %token <node> tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR

View file

@ -155,7 +155,7 @@ class TestAst < Test::Unit::TestCase
end end
def test_parse_raises_syntax_error def test_parse_raises_syntax_error
assert_raise_with_message(SyntaxError, /keyword_end/) do assert_raise_with_message(SyntaxError, /\bend\b/) do
RubyVM::AbstractSyntaxTree.parse("end") RubyVM::AbstractSyntaxTree.parse("end")
end end
end end
@ -164,7 +164,7 @@ class TestAst < Test::Unit::TestCase
Tempfile.create(%w"test_ast .rb") do |f| Tempfile.create(%w"test_ast .rb") do |f|
f.puts "end" f.puts "end"
f.close f.close
assert_raise_with_message(SyntaxError, /keyword_end/) do assert_raise_with_message(SyntaxError, /\bend\b/) do
RubyVM::AbstractSyntaxTree.parse_file(f.path) RubyVM::AbstractSyntaxTree.parse_file(f.path)
end end
end end

View file

@ -256,7 +256,7 @@ class TestISeq < Test::Unit::TestCase
f.puts "end" f.puts "end"
f.close f.close
path = f.path path = f.path
assert_in_out_err(%W[- #{path}], "#{<<-"begin;"}\n#{<<-"end;"}", /keyword_end/, [], success: true) assert_in_out_err(%W[- #{path}], "#{<<-"begin;"}\n#{<<-"end;"}", /unexpected end/, [], success: true)
begin; begin;
path = ARGV[0] path = ARGV[0]
begin begin

View file

@ -989,7 +989,7 @@ eom
end end
def test_parenthesised_statement_argument def test_parenthesised_statement_argument
assert_syntax_error("foo(bar rescue nil)", /unexpected modifier_rescue/) assert_syntax_error("foo(bar rescue nil)", /unexpected rescue \(modifier\)/)
assert_valid_syntax("foo (bar rescue nil)") assert_valid_syntax("foo (bar rescue nil)")
end end