ruby-changes:52514
From: hsbt <ko1@a...>
Date: Thu, 13 Sep 2018 16:28:50 +0900 (JST)
Subject: [ruby-changes:52514] hsbt:r64725: Move ruby_m17n branch to tags.
hsbt 2018-09-13 16:03:26 +0900 (Thu, 13 Sep 2018) New Revision: 64725 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64725 Log: Move ruby_m17n branch to tags. Added directories: tags/ruby_m17n/ Removed directories: branches/ruby_m17n/ Index: ruby_m17n/parse.y =================================================================== --- ruby_m17n/parse.y (revision 64724) +++ ruby_m17n/parse.y (nonexistent) @@ -1,5025 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ruby_m17n/parse.y#L0 -/********************************************************************** - - parse.y - - - $Author$ - $Date$ - created at: Fri May 28 18:02:42 JST 1993 - - Copyright (C) 1993-2000 Yukihiro Matsumoto - -**********************************************************************/ - -%{ - -#define YYDEBUG 1 -#include "ruby.h" -#include "env.h" -#include "node.h" -#include "st.h" -#include <stdio.h> -#include <errno.h> - -#define ID_SCOPE_SHIFT 3 -#define ID_SCOPE_MASK 0x07 -#define ID_LOCAL 0x01 -#define ID_INSTANCE 0x02 -#define ID_GLOBAL 0x03 -#define ID_ATTRSET 0x04 -#define ID_CONST 0x05 -#define ID_CLASS 0x06 - -#define is_notop_id(id) ((id)>LAST_TOKEN) -#define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL) -#define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL) -#define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE) -#define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET) -#define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST) -#define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS) - -NODE *ruby_eval_tree_begin = 0; -NODE *ruby_eval_tree = 0; - -char *ruby_sourcefile; /* current source file */ -int ruby_sourceline; /* current line no. */ - -static int yylex(); -static int yyerror(); - -static enum lex_state { - EXPR_BEG, /* ignore newline, +/- is a sign. */ - EXPR_END, /* newline significant, +/- is a operator. */ - EXPR_PAREN, /* almost like EXPR_END, `do' works as `{'. */ - EXPR_ARG, /* newline significant, +/- is a operator. */ - EXPR_MID, /* newline significant, +/- is a operator. */ - EXPR_FNAME, /* ignore newline, no reserved words. */ - EXPR_DOT, /* right after `.' or `::', no reserved words. */ - EXPR_CLASS, /* immediate after `class', no here document. */ -} lex_state; - -static int cond_nest = 0; -static unsigned long cond_stack = 0; -#define COND_PUSH do {\ - cond_nest++;\ - cond_stack = (cond_stack<<1)|1;\ -} while(0) -#define COND_POP do {\ - cond_nest--;\ - cond_stack >>= 1;\ -} while (0) -#define IN_COND (cond_nest > 0 && (cond_stack&1)) - -static int class_nest = 0; -static int in_single = 0; -static int compile_for_eval = 0; -static ID cur_mid = 0; - -static NODE *cond(); -static NODE *logop(); - -static NODE *newline_node(); -static void fixpos(); - -static int value_expr(); -static void void_expr(); -static void void_stmts(); - -static NODE *block_append(); -static NODE *list_append(); -static NODE *list_concat(); -static NODE *arg_concat(); -static NODE *call_op(); -static int in_defined = 0; - -static NODE *arg_blk_pass(); -static NODE *new_call(); -static NODE *new_fcall(); -static NODE *new_super(); - -static NODE *gettable(); -static NODE *assignable(); -static NODE *aryset(); -static NODE *attrset(); -static void rb_backref_error(); -static NODE *node_assign(); - -static NODE *match_gen(); -static void local_push(); -static void local_pop(); -static int local_append(); -static int local_cnt(); -static int local_id(); -static ID *local_tbl(); - -static struct RVarmap *dyna_push(); -static void dyna_pop(); -static int dyna_in_block(); - -#define cref_push() NEW_CREF() -static void cref_pop(); -static NODE *cur_cref; - -static void top_local_init(); -static void top_local_setup(); -%} - -%union { - NODE *node; - VALUE val; - ID id; - int num; - struct RVarmap *vars; -} - -%token kCLASS - kMODULE - kDEF - kUNDEF - kBEGIN - kRESCUE - kENSURE - kEND - kIF - kUNLESS - kTHEN - kELSIF - kELSE - kCASE - kWHEN - kWHILE - kUNTIL - kFOR - kBREAK - kNEXT - kREDO - kRETRY - kIN - kDO - kDO2 - kRETURN - kYIELD - kSUPER - kSELF - kNIL - kTRUE - kFALSE - kAND - kOR - kNOT - kIF_MOD - kUNLESS_MOD - kWHILE_MOD - kUNTIL_MOD - kRESCUE_MOD - kALIAS - kDEFINED - klBEGIN - klEND - k__LINE__ - k__FILE__ - -%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR -%token <val> tINTEGER tFLOAT tSTRING tXSTRING tREGEXP -%token <node> tDSTRING tDXSTRING tDREGEXP tNTH_REF tBACK_REF - -%type <node> singleton string -%type <val> literal numeric -%type <node> compstmt stmts stmt expr arg primary command_call method_call -%type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure -%type <node> opt_call_args call_args ret_args args when_args -%type <node> aref_args opt_block_arg block_arg stmt_rhs -%type <node> mrhs mrhs_basic superclass generic_call block_call var_ref -%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg -%type <node> assoc_list assocs assoc undef_list backref -%type <node> block_var opt_block_var brace_block do_block lhs none -%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node -%type <id> fitem variable sym symbol operation operation2 operation3 -%type <id> cname fname op f_rest_arg -%type <num> f_norm_arg f_arg -%token tUPLUS /* unary+ */ -%token tUMINUS /* unary- */ -%token tPOW /* ** */ -%token tCMP /* <=> */ -%token tEQ /* == */ -%token tEQQ /* === */ -%token tNEQ /* != */ -%token tGEQ /* >= */ -%token tLEQ /* <= */ -%token tANDOP tOROP /* && and || */ -%token tMATCH tNMATCH /* =~ and !~ */ -%token tDOT2 tDOT3 /* .. and ... */ -%token tAREF tASET /* [] and []= */ -%token tLSHFT tRSHFT /* << and >> */ -%token tCOLON2 /* :: */ -%token tCOLON3 /* :: at EXPR_BEG */ -%token <id> tOP_ASGN /* +=, -= etc. */ -%token tASSOC /* => */ -%token tLPAREN /* ( */ -%token tLBRACK /* [ */ -%token tLBRACE /* { */ -%token tSTAR /* * */ -%token tAMPER /* & */ -%token tSYMBEG - -/* - * precedence table - */ - -%left kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD kRESCUE_MOD -%left kOR kAND -%right kNOT -%nonassoc kDEFINED -%right '=' tOP_ASGN -%right '?' ':' -%nonassoc tDOT2 tDOT3 -%left tOROP -%left tANDOP -%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH -%left '>' tGEQ '<' tLEQ -%left '|' '^' -%left '&' -%left tLSHFT tRSHFT -%left '+' '-' -%left '*' '/' '%' -%right '!' '~' tUPLUS tUMINUS -%right tPOW - -%token LAST_TOKEN - -%% -program : { - $<vars>$ = ruby_dyna_vars; - lex_state = EXPR_BEG; - top_local_init(); - NEW_CREF0(); /* initialize constant c-ref */ - if ((VALUE)ruby_class == rb_cObject) class_nest = 0; - else class_nest = 1; - } - compstmt - { - if ($2 && !compile_for_eval) { - /* last expression should not be void */ - if (nd_type($2) != NODE_BLOCK) void_expr($2); - else { - NODE *node = $2; - while (node->nd_next) { - node = node->nd_next; - } - void_expr(node->nd_head); - } - } - ruby_eval_tree = block_append(ruby_eval_tree, $2); - top_local_setup(); - cur_cref = 0; - class_nest = 0; - ruby_dyna_vars = $<vars>1; - } - -compstmt : stmts opt_terms - { - void_stmts($1); - $$ = $1; - } - -stmts : none - | stmt - { - $$ = newline_node($1); - } - | stmts terms stmt - { - $$ = block_append($1, newline_node($3)); - } - | error stmt - { - $$ = $2; - } - -stmt : block_call - | kALIAS fitem {lex_state = EXPR_FNAME;} fitem - { - if (cur_mid || in_single) - yyerror("alias within method"); - $$ = NEW_ALIAS($2, $4); - } - | kALIAS tGVAR tGVAR - { - if (cur_mid || in_single) - yyerror("alias within method"); - $$ = NEW_VALIAS($2, $3); - } - | kALIAS tGVAR tBACK_REF - { - char buf[3]; - - if (cur_mid || in_single) - yyerror("alias within method"); - sprintf(buf, "$%c", (int)$3->nd_nth); - $$ = NEW_VALIAS($2, rb_intern(buf)); - } - | kALIAS tGVAR tNTH_REF - { - yyerror("can't make alias for the number variables"); - $$ = 0; - } - | kUNDEF undef_list - { - if (cur_mid || in_single) - yyerror("undef within method"); - $$ = $2; - } - | stmt kIF_MOD expr - { - value_expr($3); - $$ = NEW_IF(cond($3), $1, 0); - fixpos($$, $3); - } - | stmt kUNLESS_MOD expr - { - value_expr($3); - $$ = NEW_UNLESS(cond($3), $1, 0); - fixpos($$, $3); - } - | stmt kWHILE_MOD expr - { - value_expr($3); - if ($1) { - if (nd_type($1) == NODE_BEGIN) { - $$ = NEW_WHILE(cond($3), $1->nd_body, 0); - } - else { - $$ = NEW_WHILE(cond($3), $1, 1); - } - } - else { - $$ = 0; - } - } - | stmt kUNTIL_MOD expr - { - value_expr($3); - if ($1) { - if (nd_type($1) == NODE_BEGIN) { - $$ = NEW_UNTIL(cond($3), $1->nd_body, 0); - } - else { - $$ = NEW_UNTIL(cond($3), $1, 1); - } - } - else { - $$ = 0; - } - } - | stmt kRESCUE_MOD stmt - { - $$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0); - } - | klBEGIN - { - if (cur_mid || in_single) { - yyerror("BEGIN in method"); - } - local_push(); - } - '{' compstmt '}' - { - ruby_eval_tree_begin = block_append(ruby_eval_tree_begin, - NEW_PREEXE($4)); - local_pop(); - $$ = 0; - } - | klEND '{' compstmt '}' - { - if (compile_for_eval && (cur_mid || in_single)) { - yyerror("END in method; use at_exit"); - } - - $$ = NEW_ITER(0, NEW_POSTEXE(), $3); - } - | lhs '=' stmt_rhs - { - value_expr($3); - $$ = node_assign($1, $3); - } - | mlhs '=' stmt_rhs - { - value_expr($3); - $1->nd_value = $3; - $$ = $1; - } - | lhs '=' mrhs_basic - { - $$ = node_assign($1, $3); - } - | expr - -expr : mlhs '=' mrhs - { - value_expr($3); - $1->nd_value = $3; - $$ = $1; - } - | kRETURN ret_args - { - if (!compile_for_eval && !cur_mid && !in_single) - yyerror("return appeared outside of method"); - $$ = NEW_RETURN($2); - } - | command_call - | expr kAND expr - { - $$ = logop(NODE_AND, $1, $3); - } - | expr kOR expr - { - $$ = logop(NODE_OR, $1, $3); - } - | kNOT expr - { - value_expr($2); - $$ = NEW_NOT(cond($2)); - } - | '!' command_call - { - $$ = NEW_NOT(cond($2)); - } - | arg - -command_call : operation call_args - { - $$ = new_fcall($1, $2); - fixpos($$, $2); - } - | primary '.' operation2 call_args - { - value_expr($1); - $$ = new_call($1, $3, $4); - fixpos($$, $1); - } - | primary tCOLON2 operation2 call_args - { - value_expr($1); - $$ = new_call($1, $3, $4); - fixpos($$, $1); - } - | kSUPER call_args - { - if (!compile_for_eval && !cur_mid && !in_single) - yyerror("super called outside of method"); - $$ = new_super($2); - fixpos($$, $2); - } - | kYIELD ret_args - { - $$ = NEW_YIELD($2); - fixpos($$, $2); - } - - -mlhs : mlhs_basic - | tLPAREN mlhs_entry ')' - { - $$ = $2; - } - -mlhs_entry : mlhs_basic - | tLPAREN mlhs_entry ')' - { - $$ = NEW_MASGN(NEW_LIST($2), 0); - } - -mlhs_basic : mlhs_head - { - $$ = NEW_MASGN($1, 0); - } - | mlhs_head mlhs_item - { - $$ = NEW_MASGN(list_append($1,$2), 0); - } - | mlhs_head tSTAR mlhs_node - { - $$ = NEW_MASGN($1, $3); - } - | mlhs_head tSTAR - { - $$ = NEW_MASGN($1, -1); - } - | tSTAR mlhs_node - { - $$ = NEW_MASGN(0, $2); - } - | tSTAR - { - $$ = NEW_MASGN(0, -1); - } - -mlhs_item : mlhs_node - | tLPAREN mlhs_entry ')' - { - $$ = $2; - } - -mlhs_head : mlhs_item ',' - { - $$ = NEW_LIST($1); - } - | mlhs_head mlhs_item ',' - { - $$ = list_append($1, $2); - } - -mlhs_node : variable - { - $$ = assignable($1, 0); - } - | primary '[' aref_args ']' - { - $$ = aryset($1, $3); - } - | primary '.' tIDENTIFIER - { - $$ = attrset($1, $3); - } - | primary tCOLON2 tIDENTIFIER - { - $$ = attrset($1, $3); - } - | primary '.' tCONSTANT - { - $$ = attrset($1, $3); - } - | backref - { - rb_backref_error($1); - $$ = 0; - } - -lhs : variable - { - $$ = assignable($1, 0); - } - | primary '[' aref_args ']' - { - $$ = aryset($1, $3); - } - | primary '.' tIDENTIFIER - { - $$ = attrset($1, $3); - } - | primary tCOLON2 tIDENTIFIER - { - $$ = attrset($1, $3); - } - | primary '.' tCONSTANT - { - $$ = attrset($1, $3); - } - | backref - { - rb_backref_error($1); - $$ = 0; - } - -cname : tIDENTIFIER - { - yyerror("class/module name must be CONSTANT"); - } - | tCONSTANT - -fname : tIDENTIFIER - | tCONSTANT - | tFID - | op - { - lex_state = EXPR_END; - $$ = $1; - } - | reswords - { - lex_state = EXPR_END; - $$ = $<id>1; - } - -fitem : fname - | symbol - -undef_list : fitem - { - $$ = NEW_UNDEF($1); - } - | undef_list ',' {lex_state = EXPR_FNAME;} fitem - { - $$ = block_append($1, NEW_UNDEF($4)); - } - -op : '|' { $$ = '|'; } - | '^' { $$ = '^'; } - | '&' { $$ = '&'; } - | tCMP { $$ = tCMP; } - | tEQ { $$ = tEQ; } - | tEQQ { $$ = tEQQ; } - | tMATCH { $$ = tMATCH; } - | '>' { $$ = '>'; } - | tGEQ { $$ = tGEQ; } - | '<' { $$ = '<'; } - | tLEQ { $$ = tLEQ; } - | tLSHFT { $$ = tLSHFT; } - | tRSHFT { $$ = tRSHFT; } - | '+' { $$ = '+'; } - | '-' { $$ = '-'; } - | '*' { $$ = '*'; } - | tSTAR { $$ = '*'; } - | '/' { $$ = '/'; } - | '%' { $$ = '%'; } - | tPOW { $$ = tPOW; } - | '~' { $$ = '~'; } - | tUPLUS { $$ = tUPLUS; } - | tUMINUS { $$ = tUMINUS; } - | tAREF { $$ = tAREF; } - | tASET { $$ = tASET; } - | '`' { $$ = '`'; } - -reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND - | kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF - | kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE - | kFOR | kIF_MOD | kIN | kMODULE | kNEXT | kNIL | kNOT - | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER - | kTHEN | kTRUE | kUNDEF | kUNLESS_MOD | kUNTIL_MOD | kWHEN - | kWHILE_MOD | kYIELD | kRESCUE_MOD - -arg : lhs '=' arg - { - value_expr($3); - $$ = node_assign($1, $3); - } - | variable tOP_ASGN {$$ = assignable($1, 0);} arg - { - if ($2 == tOROP) { - $<node>3->nd_value = $4; - $$ = NEW_OP_ASGN_OR(gettable($1), $<node>3); - } - else if ($2 == tANDOP) { - $<node>3->nd_value = $4; - $$ = NEW_OP_ASGN_AND(gettable($1), $<node>3); - } - else { - $$ = $<node>3; - if ($$) { - $$->nd_value = call_op(gettable($1),$2,1,$4); - } - } - fixpos($$, $4); - } - | primary '[' aref_args ']' tOP_ASGN arg - { - NODE *args = NEW_LIST($6); - - list_append($3, NEW_NIL()); - list_concat(args, $3); - if ($5 == tOROP) { - $5 = 0; - } - else if ($5 == tANDOP) { - $5 = 1; - } - $$ = NEW_OP_ASGN1($1, $5, args); - fixpos($$, $1); - } - | primary '.' tIDENTIFIER tOP_ASGN arg - { - if ($4 == tOROP) { - $4 = 0; - } - else if ($4 == tANDOP) { - $4 = 1; - } - $$ = NEW_OP_ASGN2($1, $3, $4, $5); - fixpos($$, $1); - } - | primary '.' tCONSTANT tOP_ASGN arg - { - if ($4 == tOROP) { - $4 = 0; - } - else if ($4 == tANDOP) { - $4 = 1; - } - $$ = NEW_OP_ASGN2($1, $3, $4, $5); - fixpos($$, $1); - } - | primary tCOLON2 tIDENTIFIER tOP_ASGN arg - { - if ($4 == tOROP) { - $4 = 0; - } - else if ($4 == tANDOP) { - $4 = 1; - } - $$ = NEW_OP_ASGN2($1, $3, $4, $5); - fixpos($$, $1); - } - | backref tOP_ASGN arg - { - rb_backref_error($1); - $$ = 0; - } - | arg tDOT2 arg - { - $$ = NEW_DOT2($1, $3); - } - | arg tDOT3 arg - { - $$ = NEW_DOT3($1, $3); - } - | arg '+' arg - { - $$ = call_op($1, '+', 1, $3); - } - | arg '-' arg - { - $$ = call_op($1, '-', 1, $3); - } - | arg '*' arg - { - $$ = call_op($1, '*', 1, $3); - } - | arg '/' arg - { - $$ = call_op($1, '/', 1, $3); - } - | arg '%' arg - { - $$ = call_op($1, '%', 1, $3); - } - | arg tPOW arg - { - int need_negate = Qfalse; - - if (nd_type($1) == NODE_LIT) { - - switch (TYPE($1->nd_lit)) { - case T_FIXNUM: - case T_FLOAT: - case T_BIGNUM: - if (RTEST(rb_funcall($1->nd_lit,'<',1,INT2FIX(0)))) { - $1->nd_lit = rb_funcall($1->nd_lit,rb_intern("-@"),0,0); - need_negate = Qtrue; - } - default: - break; - } - } - $$ = call_op($1, tPOW, 1, $3); - if (need_negate) { - $$ = call_op($$, tUMINUS, 0, 0); - } - } - | tUPLUS arg - { - if ($2 && nd_type($2) == NODE_LIT) { - $$ = $2; - } - else { - $$ = call_op($2, tUPLUS, 0, 0); - } - } - | tUMINUS arg - { - if ($2 && nd_type($2) == NODE_LIT && FIXNUM_P($2->nd_lit)) { - long i = FIX2LONG($2->nd_lit); - - $2->nd_lit = INT2FIX(-i); - $$ = $2; - } - else { - $$ = call_op($2, tUMINUS, 0, 0); - } - } - | arg '|' arg - { - $$ = call_op($1, '|', 1, $3); - } - | arg '^' arg - { - $$ = call_op($1, '^', 1, $3); - } - | arg '&' arg - { - $$ = call_op($1, '&', 1, $3); - } - | arg tCMP arg - { - $$ = call_op($1, tCMP, 1, $3); - } - | arg '>' arg - { - $$ = call_op($1, '>', 1, $3); - } - | arg tGEQ arg - { - $$ = call_op($1, tGEQ, 1, $3); - } - | arg '<' arg - { - $$ = call_op($1, '<', 1, $3); - } - | arg tLEQ arg - { - $$ = call_op($1, tLEQ, 1, $3); - } - | arg tEQ arg - { - $$ = call_op($1, tEQ, 1, $3); - } - | arg tEQQ arg - { - $$ = call_op($1, tEQQ, 1, $3); - } - | arg tNEQ arg - { - $$ = NEW_NOT(call_op($1, tEQ, 1, $3)); - } - | arg tMATCH arg - { - $$ = match_gen($1, $3); - } - | arg tNMATCH arg - { - $$ = NEW_NOT(match_gen($1, $3)); - } - | '!' arg - { - value_expr($2); - $$ = NEW_NOT(cond($2)); - } - | '~' arg - { - $$ = call_op($2, '~', 0, 0); - } - | arg tLSHFT arg - { - $$ = call_op($1, tLSHFT, 1, $3); - } - | arg tRSHFT arg - { - $$ = call_op($1, tRSHFT, 1, $3); - } - | arg tANDOP arg - { - $$ = logop(NODE_AND, $1, $3); - } - | arg tOROP arg - { - $$ = logop(NODE_OR, $1, $3); - } - | kDEFINED opt_nl {in_defined = 1;} arg - { - in_defined = 0; - $$ = NEW_DEFINED($4); - } - | arg '?' arg ':' arg - { - value_expr($1); - $$ = NEW_IF(cond($1), $3, $5); - fixpos($$, $1); - } - | primary - { - $$ = $1; - } - -aref_args : none - | command_call opt_nl - { - $$ = NEW_LIST($1); - } - | args ',' command_call opt_nl - { - $$ = list_append($1, $3); - } - | block_call opt_nl - { - $$ = NEW_LIST($1); - } - | args ',' block_call opt_nl - { - $$ = list_append($1, $3); - } - | args trailer - { - $$ = $1; - } - | args ',' tSTAR arg opt_nl - { - value_expr($4); - $$ = arg_concat($1, $4); - } - | assocs trailer - { - $$ = NEW_LIST(NEW_HASH($1)); - } - | tSTAR arg opt_nl - { - value_expr($2); - $$ = NEW_RESTARGS($2); - } - -opt_call_args : none - | call_args opt_nl - | block_call opt_nl - { - $$ = NEW_LIST($1); - } - | args ',' block_call - { - $$ = list_append($1, $3); - } - -call_args : command_call - { - $$ = NEW_LIST($1); - } - | args ',' command_call - { - $$ = (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/