mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: adjust error indicator
* parse.y (parser_yylex): adjust the error indicator of unexpected fraction part. before: ~~~ 1.2.3 ^~~ ~~~ after: ~~~ 1.2.3 ^~ ~~~
This commit is contained in:
parent
5830889915
commit
2ce6365f9c
3 changed files with 15 additions and 10 deletions
18
parse.y
18
parse.y
|
@ -7106,14 +7106,6 @@ number_literal_suffix(struct parser_params *p, int mask)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
if (c == '.') {
|
|
||||||
c = peekc_n(p, 1);
|
|
||||||
if (ISDIGIT(c)) {
|
|
||||||
yyerror0("unexpected fraction part after numeric literal");
|
|
||||||
p->lex.pcur += 2;
|
|
||||||
while (parser_is_identchar(p)) nextc(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -8959,8 +8951,18 @@ parser_yylex(struct parser_params *p)
|
||||||
}
|
}
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
if (c != -1 && ISDIGIT(c)) {
|
if (c != -1 && ISDIGIT(c)) {
|
||||||
|
char prev = p->lex.pcur-1 > p->lex.pbeg ? *(p->lex.pcur-2) : 0;
|
||||||
|
parse_numeric(p, '.');
|
||||||
|
if (ISDIGIT(prev)) {
|
||||||
|
yyerror0("unexpected fraction part after numeric literal");
|
||||||
|
}
|
||||||
|
else {
|
||||||
yyerror0("no .<digit> floating literal anymore; put 0 before dot");
|
yyerror0("no .<digit> floating literal anymore; put 0 before dot");
|
||||||
}
|
}
|
||||||
|
SET_LEX_STATE(EXPR_END);
|
||||||
|
p->lex.ptok = p->lex.pcur;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
set_yylval_id('.');
|
set_yylval_id('.');
|
||||||
SET_LEX_STATE(EXPR_DOT);
|
SET_LEX_STATE(EXPR_DOT);
|
||||||
return '.';
|
return '.';
|
||||||
|
|
|
@ -35,7 +35,7 @@ module TestIRB
|
||||||
'"foo#{a} #{b}"' => "#{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}a#{RED}}#{CLEAR}#{RED} #{CLEAR}#{RED}\#{#{CLEAR}b#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
|
'"foo#{a} #{b}"' => "#{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}a#{RED}}#{CLEAR}#{RED} #{CLEAR}#{RED}\#{#{CLEAR}b#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
|
||||||
'/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e#{RED}}#{CLEAR}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}",
|
'/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e#{RED}}#{CLEAR}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}",
|
||||||
"'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}",
|
"'a\nb'" => "#{RED}'#{CLEAR}#{RED}a#{CLEAR}\n#{RED}b#{CLEAR}#{RED}'#{CLEAR}",
|
||||||
"4.5.6" => "#{MAGENTA}#{BOLD}4.5.6#{CLEAR}",
|
"4.5.6" => "4.5.6",
|
||||||
"[1]]]" => "[1]]]",
|
"[1]]]" => "[1]]]",
|
||||||
"\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n",
|
"\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n",
|
||||||
"%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}",
|
"%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}",
|
||||||
|
|
|
@ -1086,6 +1086,9 @@ x = __ENCODING__
|
||||||
assert_raise_with_message(SyntaxError, /^ \^~~\z/) do
|
assert_raise_with_message(SyntaxError, /^ \^~~\z/) do
|
||||||
eval('1.2i1.1')
|
eval('1.2i1.1')
|
||||||
end
|
end
|
||||||
|
assert_raise_with_message(SyntaxError, /^ \^~\z/) do
|
||||||
|
eval('1.2.3')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truncated_source_line
|
def test_truncated_source_line
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue