mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: indent at invalid identifier
* parse.y (parser_heredoc_identifier): set indent only when valid identifier, not to dedent non-existent contents later. [ruby-core:79772] [Bug #13253] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e35907a4b7
commit
6c0f395c01
2 changed files with 9 additions and 3 deletions
8
parse.y
8
parse.y
|
@ -6234,6 +6234,7 @@ parser_heredoc_identifier(struct parser_params *parser)
|
|||
int token = tSTRING_BEG;
|
||||
long len;
|
||||
int newline = 0;
|
||||
int indent = 0;
|
||||
|
||||
if (c == '-') {
|
||||
c = nextc();
|
||||
|
@ -6242,8 +6243,7 @@ parser_heredoc_identifier(struct parser_params *parser)
|
|||
else if (c == '~') {
|
||||
c = nextc();
|
||||
func = STR_FUNC_INDENT;
|
||||
heredoc_indent = INT_MAX;
|
||||
heredoc_line_indent = 0;
|
||||
indent = INT_MAX;
|
||||
}
|
||||
switch (c) {
|
||||
case '\'':
|
||||
|
@ -6282,7 +6282,7 @@ parser_heredoc_identifier(struct parser_params *parser)
|
|||
if (!parser_is_identchar()) {
|
||||
pushback(c);
|
||||
if (func & STR_FUNC_INDENT) {
|
||||
pushback(heredoc_indent > 0 ? '~' : '-');
|
||||
pushback(indent > 0 ? '~' : '-');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -6305,6 +6305,8 @@ parser_heredoc_identifier(struct parser_params *parser)
|
|||
lex_lastline); /* nd_orig */
|
||||
parser_set_line(lex_strterm, ruby_sourceline);
|
||||
ripper_flush(parser);
|
||||
heredoc_indent = indent;
|
||||
heredoc_line_indent = 0;
|
||||
return token;
|
||||
}
|
||||
|
||||
|
|
|
@ -656,6 +656,10 @@ eom
|
|||
assert_equal(expected, actual, bug7559)
|
||||
end
|
||||
|
||||
def test_dedented_heredoc_invalid_identifer
|
||||
assert_syntax_error('<<~ "#{}"', /unexpected <</)
|
||||
end
|
||||
|
||||
def test_lineno_operation_brace_block
|
||||
expected = __LINE__ + 1
|
||||
actual = caller_lineno\
|
||||
|
|
Loading…
Reference in a new issue