From e176b8e1c1227435ee2002cf851a9768fa76375f Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 2 Aug 2013 14:14:18 +0000 Subject: [PATCH] parse.y: simplify numerics * parse.y (simple_numeric): integrate numeric literals and simplify numeric rules. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++- parse.y | 80 +++++++++++-------------------------------------------- 2 files changed, 20 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bb05e2e04..0fd4bc2ba1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Fri Aug 2 23:13:18 2013 Nobuyoshi Nakada +Fri Aug 2 23:14:16 2013 Nobuyoshi Nakada + + * parse.y (simple_numeric): integrate numeric literals and simplify + numeric rules. * ext/ripper/eventids2.c (ripper_init_eventids2): ripper support for new literals, tRATIONAL and tIMAGINARY. diff --git a/parse.y b/parse.y index 3da3ad0c02..ea132e7b77 100644 --- a/parse.y +++ b/parse.y @@ -761,7 +761,7 @@ static void token_info_pop(struct parser_params*, const char *token); %type singleton strings string string1 xstring regexp %type string_contents xstring_contents regexp_contents string_content %type words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word -%type literal numeric dsym cpath +%type literal numeric simple_numeric dsym cpath %type top_compstmt top_stmts top_stmt %type bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call %type expr_value arg_value primary_value fcall @@ -2110,7 +2110,7 @@ arg : lhs '=' arg $$ = dispatch3(binary, $1, ripper_intern("**"), $3); %*/ } - | tUMINUS_NUM tINTEGER tPOW arg + | tUMINUS_NUM simple_numeric tPOW arg { /*%%%*/ $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0); @@ -2119,33 +2119,6 @@ arg : lhs '=' arg $$ = dispatch2(unary, ripper_intern("-@"), $$); %*/ } - | tUMINUS_NUM tFLOAT tPOW arg - { - /*%%%*/ - $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0); - /*% - $$ = dispatch3(binary, $2, ripper_intern("**"), $4); - $$ = dispatch2(unary, ripper_intern("-@"), $$); - %*/ - } - | tUMINUS_NUM tRATIONAL tPOW arg - { - /*%%%*/ - $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0); - /*% - $$ = dispatch3(binary, $2, ripper_intern("**"), $4); - $$ = dispatch2(unary, ripper_intern("-@"), $$); - %*/ - } - | tUMINUS_NUM tIMAGINARY tPOW arg - { - /*%%%*/ - $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0); - /*% - $$ = dispatch3(binary, $2, ripper_intern("**"), $4); - $$ = dispatch2(unary, ripper_intern("-@"), $$); - %*/ - } | tUPLUS arg { /*%%%*/ @@ -4310,42 +4283,21 @@ dsym : tSYMBEG xstring_contents tSTRING_END } ; -numeric : tINTEGER +numeric : simple_numeric + | tUMINUS_NUM simple_numeric %prec tLOWEST + { + /*%%%*/ + $$ = negate_lit($2); + /*% + $$ = dispatch2(unary, ripper_intern("-@"), $2); + %*/ + } + ; + +simple_numeric : tINTEGER | tFLOAT - | tRATIONAL - | tIMAGINARY - | tUMINUS_NUM tINTEGER %prec tLOWEST - { - /*%%%*/ - $$ = negate_lit($2); - /*% - $$ = dispatch2(unary, ripper_intern("-@"), $2); - %*/ - } - | tUMINUS_NUM tFLOAT %prec tLOWEST - { - /*%%%*/ - $$ = negate_lit($2); - /*% - $$ = dispatch2(unary, ripper_intern("-@"), $2); - %*/ - } - | tUMINUS_NUM tRATIONAL %prec tLOWEST - { - /*%%%*/ - $$ = negate_lit($2); - /*% - $$ = dispatch2(unary, ripper_intern("-@"), $2); - %*/ - } - | tUMINUS_NUM tIMAGINARY %prec tLOWEST - { - /*%%%*/ - $$ = negate_lit($2); - /*% - $$ = dispatch2(unary, ripper_intern("-@"), $2); - %*/ - } + | tRATIONAL + | tIMAGINARY ; user_variable : tIDENTIFIER