diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-05 08:32:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-05 08:32:46 +0000 |
commit | d2a03300d33ef6b24fd4492aa3917ce41b4512ae (patch) | |
tree | eb4915eacb8e1ebe6797c03d2af8e8b292fa8268 | |
parent | 71e58ad6142d7511b5114dd0aa057b3fa0a32865 (diff) | |
download | ruby-d2a03300d33ef6b24fd4492aa3917ce41b4512ae.tar.gz |
parse.y: named whitespaces
* parse.y: named escaped whitespaces to show unexpected character.
bare whitespaces should not appear outside of word_list.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | parse.y | 7 | ||||
-rw-r--r-- | test/ruby/test_parse.rb | 21 |
2 files changed, 28 insertions, 0 deletions
@@ -836,7 +836,13 @@ static void token_info_pop(struct parser_params*, const char *token, const rb_co %type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon %token END_OF_INPUT 0 "end-of-input" %token <id> '.' +/* escaped chars, should be ignored otherwise */ %token <id> '\\' "backslash" +%token <id> ' ' "escaped space" +%token <id> '\t' "escaped horizontal tab" +%token <id> '\f' "escaped form feed" +%token <id> '\r' "escaped carriage return" +%token <id> '\13' "escaped vertical tab" %token tUPLUS RUBY_TOKEN(UPLUS) "unary+" %token tUMINUS RUBY_TOKEN(UMINUS) "unary-" %token tPOW RUBY_TOKEN(POW) "**" @@ -8095,6 +8101,7 @@ parser_yylex(struct parser_params *p) dispatch_scan_event(p, tSP); goto retry; /* skip \\n */ } + if (ISSPACE(c)) return c; pushback(p, c); return '\\'; diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index e843c66242..cd1c5a3ecc 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1129,6 +1129,27 @@ x = __ENCODING__ end end + def test_whitespace_warning + assert_raise_with_message(SyntaxError, /backslash/) do + eval("\\foo") + end + assert_raise_with_message(SyntaxError, /escaped space/) do + eval("\\ ") + end + assert_raise_with_message(SyntaxError, /escaped horizontal tab/) do + eval("\\\t") + end + assert_raise_with_message(SyntaxError, /escaped form feed/) do + eval("\\\f") + end + assert_raise_with_message(SyntaxError, /escaped carriage return/) do + assert_warn(/middle of line/) {eval("\\\r")} + end + assert_raise_with_message(SyntaxError, /escaped vertical tab/) do + eval("\\\v") + end + end + =begin def test_past_scope_variable assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} |