[270] | 1 | /*
|
---|
| 2 | ** parse.y - mruby parser
|
---|
| 3 | **
|
---|
| 4 | ** See Copyright Notice in mruby.h
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | %{
|
---|
| 8 | // can first specify namespace
|
---|
| 9 | // could specify using directives
|
---|
| 10 | // [this has not been done here to stress-test the skeleton]
|
---|
| 11 | using System;
|
---|
| 12 | using Bridge;
|
---|
| 13 | using Bridge.Html5;
|
---|
| 14 |
|
---|
| 15 | namespace WebMrbc
|
---|
| 16 | {
|
---|
| 17 | public enum MrbTokens
|
---|
| 18 | {
|
---|
| 19 | %}
|
---|
| 20 |
|
---|
| 21 | %token <int>
|
---|
| 22 | keyword_class
|
---|
| 23 | keyword_module
|
---|
| 24 | keyword_def
|
---|
| 25 | keyword_begin
|
---|
| 26 | keyword_if
|
---|
| 27 | keyword_unless
|
---|
| 28 | keyword_while
|
---|
| 29 | keyword_until
|
---|
| 30 | keyword_for
|
---|
| 31 |
|
---|
| 32 | %token
|
---|
| 33 | keyword_undef
|
---|
| 34 | keyword_rescue
|
---|
| 35 | keyword_ensure
|
---|
| 36 | keyword_end
|
---|
| 37 | keyword_then
|
---|
| 38 | keyword_elsif
|
---|
| 39 | keyword_else
|
---|
| 40 | keyword_case
|
---|
| 41 | keyword_when
|
---|
| 42 | keyword_break
|
---|
| 43 | keyword_next
|
---|
| 44 | keyword_redo
|
---|
| 45 | keyword_retry
|
---|
| 46 | keyword_in
|
---|
| 47 | keyword_do
|
---|
| 48 | keyword_do_cond
|
---|
| 49 | keyword_do_block
|
---|
| 50 | keyword_do_LAMBDA
|
---|
| 51 | keyword_return
|
---|
| 52 | keyword_yield
|
---|
| 53 | keyword_super
|
---|
| 54 | keyword_self
|
---|
| 55 | keyword_nil
|
---|
| 56 | keyword_true
|
---|
| 57 | keyword_false
|
---|
| 58 | keyword_and
|
---|
| 59 | keyword_or
|
---|
| 60 | keyword_not
|
---|
| 61 | modifier_if
|
---|
| 62 | modifier_unless
|
---|
| 63 | modifier_while
|
---|
| 64 | modifier_until
|
---|
| 65 | modifier_rescue
|
---|
| 66 | keyword_alias
|
---|
| 67 | keyword_BEGIN
|
---|
| 68 | keyword_END
|
---|
| 69 | keyword__LINE__
|
---|
| 70 | keyword__FILE__
|
---|
| 71 | keyword__ENCODING__
|
---|
| 72 |
|
---|
| 73 | %token <mrb_sym> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
|
---|
| 74 | %token <node> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP
|
---|
| 75 | %token <node> tSTRING tSTRING_PART tSTRING_MID tLABEL_END
|
---|
| 76 | %token <node> tNTH_REF tBACK_REF
|
---|
| 77 | %token <int> tREGEXP_END
|
---|
| 78 |
|
---|
| 79 | %type <node> singleton string string_rep string_interp xstring regexp
|
---|
| 80 | %type <node> literal numeric cpath symbol
|
---|
| 81 | %type <node> top_compstmt top_stmts top_stmt
|
---|
| 82 | %type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
---|
| 83 | %type <node> expr_value arg_rhs primary_value
|
---|
| 84 | %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
|
---|
| 85 | %type <node> args call_args opt_call_args
|
---|
| 86 | %type <node> paren_args opt_paren_args variable
|
---|
| 87 | %type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
|
---|
| 88 | %type <node> command_asgn command_rhs mrhs superclass block_call block_command
|
---|
| 89 | %type <node> f_block_optarg f_block_opt
|
---|
| 90 | %type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
|
---|
| 91 | %type <node> assoc_list assocs assoc undef_list backref for_var
|
---|
| 92 | %type <node> block_param opt_block_param block_param_def f_opt
|
---|
| 93 | %type <node> bv_decls opt_bv_decl bvar f_larglist lambda_body
|
---|
| 94 | %type <node> brace_block cmd_brace_block do_block lhs none f_bad_arg
|
---|
| 95 | %type <node> mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner
|
---|
| 96 | %type <mrb_sym> fsym sym basic_symbol operation operation2 operation3
|
---|
| 97 | %type <mrb_sym> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_opt_asgn
|
---|
| 98 | %type <node> heredoc words symbols
|
---|
| 99 | %type <MrbTokens> call_op call_op2 /* 0:'&.', 1:'.', 2:'::' */
|
---|
| 100 |
|
---|
| 101 | %token tUPLUS /* unary+ */
|
---|
| 102 | %token tUMINUS /* unary- */
|
---|
| 103 | %token tPOW /* ** */
|
---|
| 104 | %token tCMP /* <=> */
|
---|
| 105 | %token tEQ /* == */
|
---|
| 106 | %token tEQQ /* === */
|
---|
| 107 | %token tNEQ /* != */
|
---|
| 108 | %token tGEQ /* >= */
|
---|
| 109 | %token tLEQ /* <= */
|
---|
| 110 | %token tANDOP tOROP /* && and || */
|
---|
| 111 | %token tMATCH tNMATCH /* =~ and !~ */
|
---|
| 112 | %token tDOT2 tDOT3 /* .. and ... */
|
---|
| 113 | %token tAREF tASET /* [] and []= */
|
---|
| 114 | %token tLSHFT tRSHFT /* << and >> */
|
---|
| 115 | %token tCOLON2 /* :: */
|
---|
| 116 | %token tCOLON3 /* :: at EXPR_BEG */
|
---|
| 117 | %token <mrb_sym> tOP_ASGN /* +=, -= etc. */
|
---|
| 118 | %token tASSOC /* => */
|
---|
| 119 | %token tLPAREN /* ( */
|
---|
| 120 | %token tLPAREN_ARG /* ( */
|
---|
| 121 | %token tRPAREN /* ) */
|
---|
| 122 | %token tLBRACK /* [ */
|
---|
| 123 | %token tLBRACE /* { */
|
---|
| 124 | %token tLBRACE_ARG /* { */
|
---|
| 125 | %token tSTAR /* * */
|
---|
| 126 | %token tAMPER /* & */
|
---|
| 127 | %token tLAMBDA /* -> */
|
---|
| 128 | %token tANDDOT /* &. */
|
---|
| 129 | %token tSYMBEG tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG
|
---|
| 130 | %token tSTRING_BEG tXSTRING_BEG tSTRING_DVAR tLAMBEG
|
---|
| 131 | %token <node> tHEREDOC_BEG /* <<, <<- */
|
---|
| 132 | %token tHEREDOC_END tLITERAL_DELIM tHD_LITERAL_DELIM
|
---|
| 133 | %token <node> tHD_STRING_PART tHD_STRING_MID
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * precedence table
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | %nonassoc tLOWEST
|
---|
| 140 | %nonassoc tLBRACE_ARG
|
---|
| 141 |
|
---|
| 142 | %nonassoc modifier_if modifier_unless modifier_while modifier_until
|
---|
| 143 | %left keyword_or keyword_and
|
---|
| 144 | %right keyword_not
|
---|
| 145 | %right '=' tOP_ASGN
|
---|
| 146 | %left modifier_rescue
|
---|
| 147 | %right '?' ':'
|
---|
| 148 | %nonassoc tDOT2 tDOT3
|
---|
| 149 | %left tOROP
|
---|
| 150 | %left tANDOP
|
---|
| 151 | %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
---|
| 152 | %left '>' tGEQ '<' tLEQ
|
---|
| 153 | %left '|' '^'
|
---|
| 154 | %left '&'
|
---|
| 155 | %left tLSHFT tRSHFT
|
---|
| 156 | %left '+' '-'
|
---|
| 157 | %left '*' '/' '%'
|
---|
| 158 | %right tUMINUS_NUM tUMINUS
|
---|
| 159 | %right tPOW
|
---|
| 160 | %right '!' '~' tUPLUS
|
---|
| 161 |
|
---|
| 162 | %token tLAST_TOKEN
|
---|
| 163 |
|
---|
| 164 | %%
|
---|
| 165 |
|
---|
| 166 | %{
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /// <summary>
|
---|
| 170 | /// start with an argument to trace
|
---|
| 171 | /// </summary>
|
---|
| 172 | public partial class MrbParser
|
---|
| 173 | {
|
---|
| 174 | // must specify class header
|
---|
| 175 | // must not use yy[A-Z].* as identifiers
|
---|
| 176 | // could overwrite some methods named yy[A-Z].* in subclass
|
---|
| 177 |
|
---|
| 178 | const int yyErrorCode = (int)MrbTokens.yyErrorCode;
|
---|
| 179 | %}
|
---|
| 180 |
|
---|
| 181 | program : {
|
---|
| 182 | this.lstate = mrb_lex_state_enum.EXPR_BEG;
|
---|
| 183 | if (this.locals == null) this.locals = new locals_node(null);
|
---|
| 184 | }
|
---|
| 185 | top_compstmt
|
---|
| 186 | {
|
---|
| 187 | this.tree = new_scope($2);
|
---|
| 188 | this.tree.NODE_LINENO($2);
|
---|
| 189 | }
|
---|
| 190 | ;
|
---|
| 191 |
|
---|
| 192 | top_compstmt : top_stmts opt_terms
|
---|
| 193 | {
|
---|
| 194 | $$ = $1;
|
---|
| 195 | }
|
---|
| 196 | ;
|
---|
| 197 |
|
---|
| 198 | top_stmts : none
|
---|
| 199 | {
|
---|
| 200 | $$ = new_begin(null);
|
---|
| 201 | }
|
---|
| 202 | | top_stmt
|
---|
| 203 | {
|
---|
| 204 | $$ = new_begin($1);
|
---|
| 205 | $<node>$.NODE_LINENO($1);
|
---|
| 206 | }
|
---|
| 207 | | top_stmts terms top_stmt
|
---|
| 208 | {
|
---|
| 209 | $$ = push($1, newline_node($3));
|
---|
| 210 | }
|
---|
| 211 | | error top_stmt
|
---|
| 212 | {
|
---|
| 213 | $$ = new_begin(null);
|
---|
| 214 | }
|
---|
| 215 | ;
|
---|
| 216 |
|
---|
| 217 | top_stmt : stmt
|
---|
| 218 | | keyword_BEGIN
|
---|
| 219 | {
|
---|
| 220 | $$ = local_switch();
|
---|
| 221 | }
|
---|
| 222 | '{' top_compstmt '}'
|
---|
| 223 | {
|
---|
| 224 | yyError("BEGIN not supported");
|
---|
| 225 | local_resume($<locals_node>2);
|
---|
| 226 | $$ = null;
|
---|
| 227 | }
|
---|
| 228 | ;
|
---|
| 229 |
|
---|
| 230 | bodystmt : compstmt
|
---|
| 231 | opt_rescue
|
---|
| 232 | opt_else
|
---|
| 233 | opt_ensure
|
---|
| 234 | {
|
---|
| 235 | if ($2 != null) {
|
---|
| 236 | $$ = new_rescue($1, $2, $3);
|
---|
| 237 | $<node>$.NODE_LINENO($1);
|
---|
| 238 | }
|
---|
| 239 | else if ($3 != null) {
|
---|
| 240 | yyWarning("else without rescue is useless");
|
---|
| 241 | $$ = push($1, $3);
|
---|
| 242 | }
|
---|
| 243 | else {
|
---|
| 244 | $$ = $1;
|
---|
| 245 | }
|
---|
| 246 | if ($4 != null) {
|
---|
| 247 | if ($$ != null) {
|
---|
| 248 | $$ = new_ensure($<node>$, $4);
|
---|
| 249 | }
|
---|
| 250 | else {
|
---|
| 251 | $$ = push($4, new_nil());
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 | ;
|
---|
| 256 |
|
---|
| 257 | compstmt : stmts opt_terms
|
---|
| 258 | {
|
---|
| 259 | $$ = $1;
|
---|
| 260 | }
|
---|
| 261 | ;
|
---|
| 262 |
|
---|
| 263 | stmts : none
|
---|
| 264 | {
|
---|
| 265 | $$ = new_begin(null);
|
---|
| 266 | }
|
---|
| 267 | | stmt
|
---|
| 268 | {
|
---|
| 269 | $$ = new_begin($1);
|
---|
| 270 | $<node>$.NODE_LINENO($1);
|
---|
| 271 | }
|
---|
| 272 | | stmts terms stmt
|
---|
| 273 | {
|
---|
| 274 | $$ = push($1, newline_node($3));
|
---|
| 275 | }
|
---|
| 276 | | error stmt
|
---|
| 277 | {
|
---|
| 278 | $$ = new_begin($2);
|
---|
| 279 | }
|
---|
| 280 | ;
|
---|
| 281 |
|
---|
| 282 | stmt : keyword_alias fsym {this.lstate = mrb_lex_state_enum.EXPR_FNAME;} fsym
|
---|
| 283 | {
|
---|
| 284 | $$ = new_alias($2, $4);
|
---|
| 285 | }
|
---|
| 286 | | keyword_undef undef_list
|
---|
| 287 | {
|
---|
| 288 | $$ = $2;
|
---|
| 289 | }
|
---|
| 290 | | stmt modifier_if expr_value
|
---|
| 291 | {
|
---|
| 292 | $$ = new_if(cond($3), $1, null);
|
---|
| 293 | }
|
---|
| 294 | | stmt modifier_unless expr_value
|
---|
| 295 | {
|
---|
| 296 | $$ = new_unless(cond($3), $1, null);
|
---|
| 297 | }
|
---|
| 298 | | stmt modifier_while expr_value
|
---|
| 299 | {
|
---|
| 300 | $$ = new_while(cond($3), $1);
|
---|
| 301 | }
|
---|
| 302 | | stmt modifier_until expr_value
|
---|
| 303 | {
|
---|
| 304 | $$ = new_until(cond($3), $1);
|
---|
| 305 | }
|
---|
| 306 | | stmt modifier_rescue stmt
|
---|
| 307 | {
|
---|
| 308 | $$ = new_mod_rescue($1, $3);
|
---|
| 309 | }
|
---|
| 310 | | keyword_END '{' compstmt '}'
|
---|
| 311 | {
|
---|
| 312 | yyError("END not supported");
|
---|
| 313 | $$ = new_postexe($3);
|
---|
| 314 | }
|
---|
| 315 | | command_asgn
|
---|
| 316 | | mlhs '=' command_call
|
---|
| 317 | {
|
---|
| 318 | $$ = new_masgn($1, $3);
|
---|
| 319 | }
|
---|
| 320 | | lhs '=' mrhs
|
---|
| 321 | {
|
---|
| 322 | $$ = new_asgn($1, new_array($3));
|
---|
| 323 | }
|
---|
| 324 | | mlhs '=' arg
|
---|
| 325 | {
|
---|
| 326 | $$ = new_masgn($1, $3);
|
---|
| 327 | }
|
---|
| 328 | | mlhs '=' mrhs
|
---|
| 329 | {
|
---|
| 330 | $$ = new_masgn($1, new_array($3));
|
---|
| 331 | }
|
---|
| 332 | | expr
|
---|
| 333 | ;
|
---|
| 334 |
|
---|
| 335 | command_asgn : lhs '=' command_rhs
|
---|
| 336 | {
|
---|
| 337 | $$ = new_asgn($1, $3);
|
---|
| 338 | }
|
---|
| 339 | | var_lhs tOP_ASGN command_rhs
|
---|
| 340 | {
|
---|
| 341 | $$ = new_op_asgn($1, $2, $3);
|
---|
| 342 | }
|
---|
| 343 | | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs
|
---|
| 344 | {
|
---|
| 345 | $$ = new_op_asgn(new_call($1, intern("[]",2), $3, (MrbTokens)'.'), $5, $6);
|
---|
| 346 | }
|
---|
| 347 | | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
|
---|
| 348 | {
|
---|
| 349 | $$ = new_op_asgn(new_call($1, $3, null, $2), $4, $5);
|
---|
| 350 | }
|
---|
| 351 | | primary_value call_op tCONSTANT tOP_ASGN command_rhs
|
---|
| 352 | {
|
---|
| 353 | $$ = new_op_asgn(new_call($1, $3, null, $2), $4, $5);
|
---|
| 354 | }
|
---|
| 355 | | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
|
---|
| 356 | {
|
---|
| 357 | yyError("constant re-assignment");
|
---|
| 358 | $$ = null;
|
---|
| 359 | }
|
---|
| 360 | | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
|
---|
| 361 | {
|
---|
| 362 | $$ = new_op_asgn(new_call($1, $3, null, MrbTokens.tCOLON2), $4, $5);
|
---|
| 363 | }
|
---|
| 364 | | backref tOP_ASGN command_rhs
|
---|
| 365 | {
|
---|
| 366 | backref_error($1);
|
---|
| 367 | $$ = new_begin(null);
|
---|
| 368 | }
|
---|
| 369 | ;
|
---|
| 370 |
|
---|
| 371 | command_rhs : command_call %prec tOP_ASGN
|
---|
| 372 | | command_call modifier_rescue stmt
|
---|
| 373 | {
|
---|
| 374 | $$ = new_mod_rescue($1, $3);
|
---|
| 375 | }
|
---|
| 376 | | command_asgn
|
---|
| 377 | ;
|
---|
| 378 |
|
---|
| 379 |
|
---|
| 380 | expr : command_call
|
---|
| 381 | | expr keyword_and expr
|
---|
| 382 | {
|
---|
| 383 | $$ = new_and($1, $3);
|
---|
| 384 | }
|
---|
| 385 | | expr keyword_or expr
|
---|
| 386 | {
|
---|
| 387 | $$ = new_or($1, $3);
|
---|
| 388 | }
|
---|
| 389 | | keyword_not opt_nl expr
|
---|
| 390 | {
|
---|
| 391 | $$ = call_uni_op(cond($3), "!");
|
---|
| 392 | }
|
---|
| 393 | | '!' command_call
|
---|
| 394 | {
|
---|
| 395 | $$ = call_uni_op(cond($2), "!");
|
---|
| 396 | }
|
---|
| 397 | | arg
|
---|
| 398 | ;
|
---|
| 399 |
|
---|
| 400 | expr_value : expr
|
---|
| 401 | {
|
---|
| 402 | if ($1 == null) $$ = new_nil();
|
---|
| 403 | else{
|
---|
| 404 | void_expr_error($1);
|
---|
| 405 | $$ = $1;
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | ;
|
---|
| 409 |
|
---|
| 410 | command_call : command
|
---|
| 411 | | block_command
|
---|
| 412 | ;
|
---|
| 413 |
|
---|
| 414 | block_command : block_call
|
---|
| 415 | | block_call call_op2 operation2 command_args
|
---|
| 416 | ;
|
---|
| 417 |
|
---|
| 418 | cmd_brace_block : tLBRACE_ARG
|
---|
| 419 | {
|
---|
| 420 | local_nest();
|
---|
| 421 | }
|
---|
| 422 | opt_block_param
|
---|
| 423 | compstmt
|
---|
| 424 | '}'
|
---|
| 425 | {
|
---|
| 426 | $$ = new_block($3, $4, true);
|
---|
| 427 | local_unnest();
|
---|
| 428 | }
|
---|
| 429 | ;
|
---|
| 430 |
|
---|
| 431 | command : operation command_args %prec tLOWEST
|
---|
| 432 | {
|
---|
| 433 | $$ = new_fcall($1, $2);
|
---|
| 434 | }
|
---|
| 435 | | operation command_args cmd_brace_block
|
---|
| 436 | {
|
---|
| 437 | args_with_block($2, $3);
|
---|
| 438 | $$ = new_fcall($1, $2);
|
---|
| 439 | }
|
---|
| 440 | | primary_value call_op operation2 command_args %prec tLOWEST
|
---|
| 441 | {
|
---|
| 442 | $$ = new_call($1, $3, $4, $2);
|
---|
| 443 | }
|
---|
| 444 | | primary_value call_op operation2 command_args cmd_brace_block
|
---|
| 445 | {
|
---|
| 446 | args_with_block($4, $5);
|
---|
| 447 | $$ = new_call($1, $3, $4, $2);
|
---|
| 448 | }
|
---|
| 449 | | primary_value tCOLON2 operation2 command_args %prec tLOWEST
|
---|
| 450 | {
|
---|
| 451 | $$ = new_call($1, $3, $4, MrbTokens.tCOLON2);
|
---|
| 452 | }
|
---|
| 453 | | primary_value tCOLON2 operation2 command_args cmd_brace_block
|
---|
| 454 | {
|
---|
| 455 | args_with_block($4, $5);
|
---|
| 456 | $$ = new_call($1, $3, $4, MrbTokens.tCOLON2);
|
---|
| 457 | }
|
---|
| 458 | | keyword_super command_args
|
---|
| 459 | {
|
---|
| 460 | $$ = new_super($2);
|
---|
| 461 | }
|
---|
| 462 | | keyword_yield command_args
|
---|
| 463 | {
|
---|
| 464 | $$ = new_yield($2);
|
---|
| 465 | }
|
---|
| 466 | | keyword_return call_args
|
---|
| 467 | {
|
---|
| 468 | $$ = new_return(ret_args($2));
|
---|
| 469 | }
|
---|
| 470 | | keyword_break call_args
|
---|
| 471 | {
|
---|
| 472 | $$ = new_break(ret_args($2));
|
---|
| 473 | }
|
---|
| 474 | | keyword_next call_args
|
---|
| 475 | {
|
---|
| 476 | $$ = new_next(ret_args($2));
|
---|
| 477 | }
|
---|
| 478 | ;
|
---|
| 479 |
|
---|
| 480 | mlhs : mlhs_basic
|
---|
| 481 | {
|
---|
| 482 | $$ = $1;
|
---|
| 483 | }
|
---|
| 484 | | tLPAREN mlhs_inner rparen
|
---|
| 485 | {
|
---|
| 486 | $$ = $2;
|
---|
| 487 | }
|
---|
| 488 | ;
|
---|
| 489 |
|
---|
| 490 | mlhs_inner : mlhs_basic
|
---|
| 491 | | tLPAREN mlhs_inner rparen
|
---|
| 492 | {
|
---|
| 493 | $$ = $2;
|
---|
| 494 | }
|
---|
| 495 | ;
|
---|
| 496 |
|
---|
| 497 | mlhs_basic : mlhs_list
|
---|
| 498 | {
|
---|
| 499 | $$ = list1($1);
|
---|
| 500 | }
|
---|
| 501 | | mlhs_list mlhs_item
|
---|
| 502 | {
|
---|
| 503 | $$ = list1(push($1, $2));
|
---|
| 504 | }
|
---|
| 505 | | mlhs_list tSTAR mlhs_node
|
---|
| 506 | {
|
---|
| 507 | $$ = list2($1, $3);
|
---|
| 508 | }
|
---|
| 509 | | mlhs_list tSTAR mlhs_node ',' mlhs_post
|
---|
| 510 | {
|
---|
| 511 | $$ = list3($1, $3, $5);
|
---|
| 512 | }
|
---|
| 513 | | mlhs_list tSTAR
|
---|
| 514 | {
|
---|
| 515 | $$ = list2($1, new_nil());
|
---|
| 516 | }
|
---|
| 517 | | mlhs_list tSTAR ',' mlhs_post
|
---|
| 518 | {
|
---|
| 519 | $$ = list3($1, new_nil(), $4);
|
---|
| 520 | }
|
---|
| 521 | | tSTAR mlhs_node
|
---|
| 522 | {
|
---|
| 523 | $$ = list2(null, $2);
|
---|
| 524 | }
|
---|
| 525 | | tSTAR mlhs_node ',' mlhs_post
|
---|
| 526 | {
|
---|
| 527 | $$ = list3(null, $2, $4);
|
---|
| 528 | }
|
---|
| 529 | | tSTAR
|
---|
| 530 | {
|
---|
| 531 | $$ = list2(null, new_nil());
|
---|
| 532 | }
|
---|
| 533 | | tSTAR ',' mlhs_post
|
---|
| 534 | {
|
---|
| 535 | $$ = list3(null, new_nil(), $3);
|
---|
| 536 | }
|
---|
| 537 | ;
|
---|
| 538 |
|
---|
| 539 | mlhs_item : mlhs_node
|
---|
| 540 | | tLPAREN mlhs_inner rparen
|
---|
| 541 | {
|
---|
| 542 | $$ = new_masgn($2, null);
|
---|
| 543 | }
|
---|
| 544 | ;
|
---|
| 545 |
|
---|
| 546 | mlhs_list : mlhs_item ','
|
---|
| 547 | {
|
---|
| 548 | $$ = list1($1);
|
---|
| 549 | }
|
---|
| 550 | | mlhs_list mlhs_item ','
|
---|
| 551 | {
|
---|
| 552 | $$ = push($1, $2);
|
---|
| 553 | }
|
---|
| 554 | ;
|
---|
| 555 |
|
---|
| 556 | mlhs_post : mlhs_item
|
---|
| 557 | {
|
---|
| 558 | $$ = list1($1);
|
---|
| 559 | }
|
---|
| 560 | | mlhs_list mlhs_item
|
---|
| 561 | {
|
---|
| 562 | $$ = push($1, $2);
|
---|
| 563 | }
|
---|
| 564 | ;
|
---|
| 565 |
|
---|
| 566 | mlhs_node : variable
|
---|
| 567 | {
|
---|
| 568 | assignable($1);
|
---|
| 569 | }
|
---|
| 570 | | primary_value '[' opt_call_args rbracket
|
---|
| 571 | {
|
---|
| 572 | $$ = new_call($1, intern("[]",2), $3, (MrbTokens)'.');
|
---|
| 573 | }
|
---|
| 574 | | primary_value call_op tIDENTIFIER
|
---|
| 575 | {
|
---|
| 576 | $$ = new_call($1, $3, null, $2);
|
---|
| 577 | }
|
---|
| 578 | | primary_value tCOLON2 tIDENTIFIER
|
---|
| 579 | {
|
---|
| 580 | $$ = new_call($1, $3, null, MrbTokens.tCOLON2);
|
---|
| 581 | }
|
---|
| 582 | | primary_value call_op tCONSTANT
|
---|
| 583 | {
|
---|
| 584 | $$ = new_call($1, $3, null, $2);
|
---|
| 585 | }
|
---|
| 586 | | primary_value tCOLON2 tCONSTANT
|
---|
| 587 | {
|
---|
| 588 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 589 | yyError("dynamic constant assignment");
|
---|
| 590 | $$ = new_colon2($1, $3);
|
---|
| 591 | }
|
---|
| 592 | | tCOLON3 tCONSTANT
|
---|
| 593 | {
|
---|
| 594 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 595 | yyError("dynamic constant assignment");
|
---|
| 596 | $$ = new_colon3($2);
|
---|
| 597 | }
|
---|
| 598 | | backref
|
---|
| 599 | {
|
---|
| 600 | backref_error($1);
|
---|
| 601 | $$ = null;
|
---|
| 602 | }
|
---|
| 603 | ;
|
---|
| 604 |
|
---|
| 605 | lhs : variable
|
---|
| 606 | {
|
---|
| 607 | assignable($1);
|
---|
| 608 | }
|
---|
| 609 | | primary_value '[' opt_call_args rbracket
|
---|
| 610 | {
|
---|
| 611 | $$ = new_call($1, intern("[]",2), $3, (MrbTokens)'.');
|
---|
| 612 | }
|
---|
| 613 | | primary_value call_op tIDENTIFIER
|
---|
| 614 | {
|
---|
| 615 | $$ = new_call($1, $3, null, $2);
|
---|
| 616 | }
|
---|
| 617 | | primary_value tCOLON2 tIDENTIFIER
|
---|
| 618 | {
|
---|
| 619 | $$ = new_call($1, $3, null, MrbTokens.tCOLON2);
|
---|
| 620 | }
|
---|
| 621 | | primary_value call_op tCONSTANT
|
---|
| 622 | {
|
---|
| 623 | $$ = new_call($1, $3, null, $2);
|
---|
| 624 | }
|
---|
| 625 | | primary_value tCOLON2 tCONSTANT
|
---|
| 626 | {
|
---|
| 627 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 628 | yyError("dynamic constant assignment");
|
---|
| 629 | $$ = new_colon2($1, $3);
|
---|
| 630 | }
|
---|
| 631 | | tCOLON3 tCONSTANT
|
---|
| 632 | {
|
---|
| 633 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 634 | yyError("dynamic constant assignment");
|
---|
| 635 | $$ = new_colon3($2);
|
---|
| 636 | }
|
---|
| 637 | | backref
|
---|
| 638 | {
|
---|
| 639 | backref_error($1);
|
---|
| 640 | $$ = null;
|
---|
| 641 | }
|
---|
| 642 | ;
|
---|
| 643 |
|
---|
| 644 | cname : tIDENTIFIER
|
---|
| 645 | {
|
---|
| 646 | yyError("class/module name must be CONSTANT");
|
---|
| 647 | }
|
---|
| 648 | | tCONSTANT
|
---|
| 649 | ;
|
---|
| 650 |
|
---|
| 651 | cpath : tCOLON3 cname
|
---|
| 652 | {
|
---|
| 653 | $$ = cons(1, $2);
|
---|
| 654 | }
|
---|
| 655 | | cname
|
---|
| 656 | {
|
---|
| 657 | $$ = cons(0, $1);
|
---|
| 658 | }
|
---|
| 659 | | primary_value tCOLON2 cname
|
---|
| 660 | {
|
---|
| 661 | $$ = cons($1, $3);
|
---|
| 662 | }
|
---|
| 663 | ;
|
---|
| 664 |
|
---|
| 665 | fname : tIDENTIFIER
|
---|
| 666 | | tCONSTANT
|
---|
| 667 | | tFID
|
---|
| 668 | | op
|
---|
| 669 | {
|
---|
| 670 | this.lstate = mrb_lex_state_enum.EXPR_ENDFN;
|
---|
| 671 | $$ = $1;
|
---|
| 672 | }
|
---|
| 673 | | reswords
|
---|
| 674 | {
|
---|
| 675 | this.lstate = mrb_lex_state_enum.EXPR_ENDFN;
|
---|
| 676 | $$ = $<mrb_sym>1;
|
---|
| 677 | }
|
---|
| 678 | ;
|
---|
| 679 |
|
---|
| 680 | fsym : fname
|
---|
| 681 | | basic_symbol
|
---|
| 682 | ;
|
---|
| 683 |
|
---|
| 684 | undef_list : fsym
|
---|
| 685 | {
|
---|
| 686 | $$ = new_undef($1);
|
---|
| 687 | }
|
---|
| 688 | | undef_list ',' {this.lstate = mrb_lex_state_enum.EXPR_FNAME;} fsym
|
---|
| 689 | {
|
---|
| 690 | $$ = push($1, $4);
|
---|
| 691 | }
|
---|
| 692 | ;
|
---|
| 693 |
|
---|
| 694 | op : '|' { $$ = intern_c('|'); }
|
---|
| 695 | | '^' { $$ = intern_c('^'); }
|
---|
| 696 | | '&' { $$ = intern_c('&'); }
|
---|
| 697 | | tCMP { $$ = intern("<=>",3); }
|
---|
| 698 | | tEQ { $$ = intern("==",2); }
|
---|
| 699 | | tEQQ { $$ = intern("===",3); }
|
---|
| 700 | | tMATCH { $$ = intern("=~",2); }
|
---|
| 701 | | tNMATCH { $$ = intern("!~",2); }
|
---|
| 702 | | '>' { $$ = intern_c('>'); }
|
---|
| 703 | | tGEQ { $$ = intern(">=",2); }
|
---|
| 704 | | '<' { $$ = intern_c('<'); }
|
---|
| 705 | | tLEQ { $$ = intern("<=",2); }
|
---|
| 706 | | tNEQ { $$ = intern("!=",2); }
|
---|
| 707 | | tLSHFT { $$ = intern("<<",2); }
|
---|
| 708 | | tRSHFT { $$ = intern(">>",2); }
|
---|
| 709 | | '+' { $$ = intern_c('+'); }
|
---|
| 710 | | '-' { $$ = intern_c('-'); }
|
---|
| 711 | | '*' { $$ = intern_c('*'); }
|
---|
| 712 | | tSTAR { $$ = intern_c('*'); }
|
---|
| 713 | | '/' { $$ = intern_c('/'); }
|
---|
| 714 | | '%' { $$ = intern_c('%'); }
|
---|
| 715 | | tPOW { $$ = intern("**",2); }
|
---|
| 716 | | '!' { $$ = intern_c('!'); }
|
---|
| 717 | | '~' { $$ = intern_c('~'); }
|
---|
| 718 | | tUPLUS { $$ = intern("+@",2); }
|
---|
| 719 | | tUMINUS { $$ = intern("-@",2); }
|
---|
| 720 | | tAREF { $$ = intern("[]",2); }
|
---|
| 721 | | tASET { $$ = intern("[]=",3); }
|
---|
| 722 | | '`' { $$ = intern_c('`'); }
|
---|
| 723 | ;
|
---|
| 724 |
|
---|
| 725 | reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
|
---|
| 726 | | keyword_BEGIN | keyword_END
|
---|
| 727 | | keyword_alias | keyword_and | keyword_begin
|
---|
| 728 | | keyword_break | keyword_case | keyword_class | keyword_def
|
---|
| 729 | | keyword_do | keyword_else | keyword_elsif
|
---|
| 730 | | keyword_end | keyword_ensure | keyword_false
|
---|
| 731 | | keyword_for | keyword_in | keyword_module | keyword_next
|
---|
| 732 | | keyword_nil | keyword_not | keyword_or | keyword_redo
|
---|
| 733 | | keyword_rescue | keyword_retry | keyword_return | keyword_self
|
---|
| 734 | | keyword_super | keyword_then | keyword_true | keyword_undef
|
---|
| 735 | | keyword_when | keyword_yield | keyword_if | keyword_unless
|
---|
| 736 | | keyword_while | keyword_until
|
---|
| 737 | ;
|
---|
| 738 |
|
---|
| 739 | arg : lhs '=' arg_rhs
|
---|
| 740 | {
|
---|
| 741 | $$ = new_asgn($1, $3);
|
---|
| 742 | }
|
---|
| 743 | | var_lhs tOP_ASGN arg_rhs
|
---|
| 744 | {
|
---|
| 745 | $$ = new_op_asgn($1, $2, $3);
|
---|
| 746 | }
|
---|
| 747 | | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs
|
---|
| 748 | {
|
---|
| 749 | $$ = new_op_asgn(new_call($1, intern("[]",2), $3, (MrbTokens)'.'), $5, $6);
|
---|
| 750 | }
|
---|
| 751 | | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
|
---|
| 752 | {
|
---|
| 753 | $$ = new_op_asgn(new_call($1, $3, null, $2), $4, $5);
|
---|
| 754 | }
|
---|
| 755 | | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
|
---|
| 756 | {
|
---|
| 757 | $$ = new_op_asgn(new_call($1, $3, null, $2), $4, $5);
|
---|
| 758 | }
|
---|
| 759 | | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
|
---|
| 760 | {
|
---|
| 761 | $$ = new_op_asgn(new_call($1, $3, null, MrbTokens.tCOLON2), $4, $5);
|
---|
| 762 | }
|
---|
| 763 | | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
|
---|
| 764 | {
|
---|
| 765 | yyError("constant re-assignment");
|
---|
| 766 | $$ = new_begin(null);
|
---|
| 767 | }
|
---|
| 768 | | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
|
---|
| 769 | {
|
---|
| 770 | yyError("constant re-assignment");
|
---|
| 771 | $$ = new_begin(null);
|
---|
| 772 | }
|
---|
| 773 | | backref tOP_ASGN arg_rhs
|
---|
| 774 | {
|
---|
| 775 | backref_error($1);
|
---|
| 776 | $$ = new_begin(null);
|
---|
| 777 | }
|
---|
| 778 | | arg tDOT2 arg
|
---|
| 779 | {
|
---|
| 780 | $$ = new_dot2($1, $3);
|
---|
| 781 | }
|
---|
| 782 | | arg tDOT3 arg
|
---|
| 783 | {
|
---|
| 784 | $$ = new_dot3($1, $3);
|
---|
| 785 | }
|
---|
| 786 | | arg '+' arg
|
---|
| 787 | {
|
---|
| 788 | $$ = call_bin_op($1, "+", $3);
|
---|
| 789 | }
|
---|
| 790 | | arg '-' arg
|
---|
| 791 | {
|
---|
| 792 | $$ = call_bin_op($1, "-", $3);
|
---|
| 793 | }
|
---|
| 794 | | arg '*' arg
|
---|
| 795 | {
|
---|
| 796 | $$ = call_bin_op($1, "*", $3);
|
---|
| 797 | }
|
---|
| 798 | | arg '/' arg
|
---|
| 799 | {
|
---|
| 800 | $$ = call_bin_op($1, "/", $3);
|
---|
| 801 | }
|
---|
| 802 | | arg '%' arg
|
---|
| 803 | {
|
---|
| 804 | $$ = call_bin_op($1, "%", $3);
|
---|
| 805 | }
|
---|
| 806 | | arg tPOW arg
|
---|
| 807 | {
|
---|
| 808 | $$ = call_bin_op($1, "**", $3);
|
---|
| 809 | }
|
---|
| 810 | | tUMINUS_NUM tINTEGER tPOW arg
|
---|
| 811 | {
|
---|
| 812 | $$ = call_uni_op(call_bin_op($2, "**", $4), "-@");
|
---|
| 813 | }
|
---|
| 814 | | tUMINUS_NUM tFLOAT tPOW arg
|
---|
| 815 | {
|
---|
| 816 | $$ = call_uni_op(call_bin_op($2, "**", $4), "-@");
|
---|
| 817 | }
|
---|
| 818 | | tUPLUS arg
|
---|
| 819 | {
|
---|
| 820 | $$ = call_uni_op($2, "+@");
|
---|
| 821 | }
|
---|
| 822 | | tUMINUS arg
|
---|
| 823 | {
|
---|
| 824 | $$ = call_uni_op($2, "-@");
|
---|
| 825 | }
|
---|
| 826 | | arg '|' arg
|
---|
| 827 | {
|
---|
| 828 | $$ = call_bin_op($1, "|", $3);
|
---|
| 829 | }
|
---|
| 830 | | arg '^' arg
|
---|
| 831 | {
|
---|
| 832 | $$ = call_bin_op($1, "^", $3);
|
---|
| 833 | }
|
---|
| 834 | | arg '&' arg
|
---|
| 835 | {
|
---|
| 836 | $$ = call_bin_op($1, "&", $3);
|
---|
| 837 | }
|
---|
| 838 | | arg tCMP arg
|
---|
| 839 | {
|
---|
| 840 | $$ = call_bin_op($1, "<=>", $3);
|
---|
| 841 | }
|
---|
| 842 | | arg '>' arg
|
---|
| 843 | {
|
---|
| 844 | $$ = call_bin_op($1, ">", $3);
|
---|
| 845 | }
|
---|
| 846 | | arg tGEQ arg
|
---|
| 847 | {
|
---|
| 848 | $$ = call_bin_op($1, ">=", $3);
|
---|
| 849 | }
|
---|
| 850 | | arg '<' arg
|
---|
| 851 | {
|
---|
| 852 | $$ = call_bin_op($1, "<", $3);
|
---|
| 853 | }
|
---|
| 854 | | arg tLEQ arg
|
---|
| 855 | {
|
---|
| 856 | $$ = call_bin_op($1, "<=", $3);
|
---|
| 857 | }
|
---|
| 858 | | arg tEQ arg
|
---|
| 859 | {
|
---|
| 860 | $$ = call_bin_op($1, "==", $3);
|
---|
| 861 | }
|
---|
| 862 | | arg tEQQ arg
|
---|
| 863 | {
|
---|
| 864 | $$ = call_bin_op($1, "===", $3);
|
---|
| 865 | }
|
---|
| 866 | | arg tNEQ arg
|
---|
| 867 | {
|
---|
| 868 | $$ = call_bin_op($1, "!=", $3);
|
---|
| 869 | }
|
---|
| 870 | | arg tMATCH arg
|
---|
| 871 | {
|
---|
| 872 | $$ = call_bin_op($1, "=~", $3);
|
---|
| 873 | }
|
---|
| 874 | | arg tNMATCH arg
|
---|
| 875 | {
|
---|
| 876 | $$ = call_bin_op($1, "!~", $3);
|
---|
| 877 | }
|
---|
| 878 | | '!' arg
|
---|
| 879 | {
|
---|
| 880 | $$ = call_uni_op(cond($2), "!");
|
---|
| 881 | }
|
---|
| 882 | | '~' arg
|
---|
| 883 | {
|
---|
| 884 | $$ = call_uni_op(cond($2), "~");
|
---|
| 885 | }
|
---|
| 886 | | arg tLSHFT arg
|
---|
| 887 | {
|
---|
| 888 | $$ = call_bin_op($1, "<<", $3);
|
---|
| 889 | }
|
---|
| 890 | | arg tRSHFT arg
|
---|
| 891 | {
|
---|
| 892 | $$ = call_bin_op($1, ">>", $3);
|
---|
| 893 | }
|
---|
| 894 | | arg tANDOP arg
|
---|
| 895 | {
|
---|
| 896 | $$ = new_and($1, $3);
|
---|
| 897 | }
|
---|
| 898 | | arg tOROP arg
|
---|
| 899 | {
|
---|
| 900 | $$ = new_or($1, $3);
|
---|
| 901 | }
|
---|
| 902 | | arg '?' arg opt_nl ':' arg
|
---|
| 903 | {
|
---|
| 904 | $$ = new_if(cond($1), $3, $6, true);
|
---|
| 905 | }
|
---|
| 906 | | primary
|
---|
| 907 | {
|
---|
| 908 | $$ = $1;
|
---|
| 909 | }
|
---|
| 910 | ;
|
---|
| 911 |
|
---|
| 912 | aref_args : none
|
---|
| 913 | | args trailer
|
---|
| 914 | {
|
---|
| 915 | $$ = $1;
|
---|
| 916 | $<node>$.NODE_LINENO($1);
|
---|
| 917 | }
|
---|
| 918 | | args comma assocs trailer
|
---|
| 919 | {
|
---|
| 920 | $$ = push($1, new_hash($3));
|
---|
| 921 | }
|
---|
| 922 | | assocs trailer
|
---|
| 923 | {
|
---|
| 924 | $$ = cons(new_hash($1), null);
|
---|
| 925 | $<node>$.NODE_LINENO($1);
|
---|
| 926 | }
|
---|
| 927 | ;
|
---|
| 928 |
|
---|
| 929 | arg_rhs : arg %prec tOP_ASGN
|
---|
| 930 | {
|
---|
| 931 | void_expr_error($1);
|
---|
| 932 | $$ = $1;
|
---|
| 933 | }
|
---|
| 934 | | arg modifier_rescue arg
|
---|
| 935 | {
|
---|
| 936 | void_expr_error($1);
|
---|
| 937 | $$ = new_mod_rescue($1, $3);
|
---|
| 938 | }
|
---|
| 939 | ;
|
---|
| 940 |
|
---|
| 941 | paren_args : '(' opt_call_args rparen
|
---|
| 942 | {
|
---|
| 943 | $$ = $2;
|
---|
| 944 | }
|
---|
| 945 | ;
|
---|
| 946 |
|
---|
| 947 | opt_paren_args : none
|
---|
| 948 | | paren_args
|
---|
| 949 | ;
|
---|
| 950 |
|
---|
| 951 | opt_call_args : none
|
---|
| 952 | | call_args
|
---|
| 953 | | args ','
|
---|
| 954 | {
|
---|
| 955 | $$ = cons($1, null);
|
---|
| 956 | $<node>$.NODE_LINENO($1);
|
---|
| 957 | }
|
---|
| 958 | | args comma assocs ','
|
---|
| 959 | {
|
---|
| 960 | $$ = cons(push($1, new_hash($3)), null);
|
---|
| 961 | $<node>$.NODE_LINENO($1);
|
---|
| 962 | }
|
---|
| 963 | | assocs ','
|
---|
| 964 | {
|
---|
| 965 | $$ = cons(list1(new_hash($1)), null);
|
---|
| 966 | $<node>$.NODE_LINENO($1);
|
---|
| 967 | }
|
---|
| 968 | ;
|
---|
| 969 |
|
---|
| 970 | call_args : command
|
---|
| 971 | {
|
---|
| 972 | $$ = cons(list1($1), null);
|
---|
| 973 | $<node>$.NODE_LINENO($1);
|
---|
| 974 | }
|
---|
| 975 | | args opt_block_arg
|
---|
| 976 | {
|
---|
| 977 | $$ = cons($1, $2);
|
---|
| 978 | $<node>$.NODE_LINENO($1);
|
---|
| 979 | }
|
---|
| 980 | | assocs opt_block_arg
|
---|
| 981 | {
|
---|
| 982 | $$ = cons(list1(new_hash($1)), $2);
|
---|
| 983 | $<node>$.NODE_LINENO($1);
|
---|
| 984 | }
|
---|
| 985 | | args comma assocs opt_block_arg
|
---|
| 986 | {
|
---|
| 987 | $$ = cons(push($1, new_hash($3)), $4);
|
---|
| 988 | $<node>$.NODE_LINENO($1);
|
---|
| 989 | }
|
---|
| 990 | | block_arg
|
---|
| 991 | {
|
---|
| 992 | $$ = cons(null, $1);
|
---|
| 993 | $<node>$.NODE_LINENO($1);
|
---|
| 994 | }
|
---|
| 995 | ;
|
---|
| 996 |
|
---|
| 997 | command_args : {
|
---|
| 998 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 999 | CMDARG_PUSH(1);
|
---|
| 1000 | }
|
---|
| 1001 | call_args
|
---|
| 1002 | {
|
---|
| 1003 | this.cmdarg_stack = $<stack_type>1;
|
---|
| 1004 | $$ = $2;
|
---|
| 1005 | }
|
---|
| 1006 | ;
|
---|
| 1007 |
|
---|
| 1008 | block_arg : tAMPER arg
|
---|
| 1009 | {
|
---|
| 1010 | $$ = new_block_arg((node)$2);
|
---|
| 1011 | }
|
---|
| 1012 | ;
|
---|
| 1013 |
|
---|
| 1014 | opt_block_arg : comma block_arg
|
---|
| 1015 | {
|
---|
| 1016 | $$ = $2;
|
---|
| 1017 | }
|
---|
| 1018 | | none
|
---|
| 1019 | {
|
---|
| 1020 | $$ = null;
|
---|
| 1021 | }
|
---|
| 1022 | ;
|
---|
| 1023 |
|
---|
| 1024 | comma : ','
|
---|
| 1025 | | ',' heredoc_bodies
|
---|
| 1026 | ;
|
---|
| 1027 |
|
---|
| 1028 | args : arg
|
---|
| 1029 | {
|
---|
| 1030 | void_expr_error($1);
|
---|
| 1031 | $$ = cons($1, null);
|
---|
| 1032 | $<node>$.NODE_LINENO($1);
|
---|
| 1033 | }
|
---|
| 1034 | | tSTAR arg
|
---|
| 1035 | {
|
---|
| 1036 | void_expr_error($2);
|
---|
| 1037 | $$ = cons(new_splat($2), null);
|
---|
| 1038 | $<node>$.NODE_LINENO($2);
|
---|
| 1039 | }
|
---|
| 1040 | | args comma arg
|
---|
| 1041 | {
|
---|
| 1042 | void_expr_error($3);
|
---|
| 1043 | $$ = push($1, $3);
|
---|
| 1044 | }
|
---|
| 1045 | | args comma tSTAR arg
|
---|
| 1046 | {
|
---|
| 1047 | void_expr_error($4);
|
---|
| 1048 | $$ = push($1, new_splat($4));
|
---|
| 1049 | }
|
---|
| 1050 | ;
|
---|
| 1051 |
|
---|
| 1052 | mrhs : args comma arg
|
---|
| 1053 | {
|
---|
| 1054 | void_expr_error($3);
|
---|
| 1055 | $$ = push($1, $3);
|
---|
| 1056 | }
|
---|
| 1057 | | args comma tSTAR arg
|
---|
| 1058 | {
|
---|
| 1059 | void_expr_error($4);
|
---|
| 1060 | $$ = push($1, new_splat($4));
|
---|
| 1061 | }
|
---|
| 1062 | | tSTAR arg
|
---|
| 1063 | {
|
---|
| 1064 | void_expr_error($2);
|
---|
| 1065 | $$ = list1(new_splat($2));
|
---|
| 1066 | }
|
---|
| 1067 | ;
|
---|
| 1068 |
|
---|
| 1069 | primary : literal
|
---|
| 1070 | | string
|
---|
| 1071 | | xstring
|
---|
| 1072 | | regexp
|
---|
| 1073 | | heredoc
|
---|
| 1074 | | var_ref
|
---|
| 1075 | | backref
|
---|
| 1076 | | tFID
|
---|
| 1077 | {
|
---|
| 1078 | $$ = new_fcall($1, null);
|
---|
| 1079 | }
|
---|
| 1080 | | keyword_begin
|
---|
| 1081 | {
|
---|
| 1082 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 1083 | this.cmdarg_stack = 0;
|
---|
| 1084 | }
|
---|
| 1085 | bodystmt
|
---|
| 1086 | keyword_end
|
---|
| 1087 | {
|
---|
| 1088 | this.cmdarg_stack = $<stack_type>2;
|
---|
| 1089 | $$ = $3;
|
---|
| 1090 | }
|
---|
| 1091 | | tLPAREN_ARG
|
---|
| 1092 | {
|
---|
| 1093 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 1094 | this.cmdarg_stack = 0;
|
---|
| 1095 | }
|
---|
| 1096 | stmt {this.lstate = mrb_lex_state_enum.EXPR_ENDARG;} rparen
|
---|
| 1097 | {
|
---|
| 1098 | this.cmdarg_stack = $<stack_type>2;
|
---|
| 1099 | $$ = $3;
|
---|
| 1100 | }
|
---|
| 1101 | | tLPAREN_ARG {this.lstate = mrb_lex_state_enum.EXPR_ENDARG;} rparen
|
---|
| 1102 | {
|
---|
| 1103 | $$ = new_nil();
|
---|
| 1104 | }
|
---|
| 1105 | | tLPAREN compstmt ')'
|
---|
| 1106 | {
|
---|
| 1107 | $$ = $2;
|
---|
| 1108 | }
|
---|
| 1109 | | primary_value tCOLON2 tCONSTANT
|
---|
| 1110 | {
|
---|
| 1111 | $$ = new_colon2($1, $3);
|
---|
| 1112 | }
|
---|
| 1113 | | tCOLON3 tCONSTANT
|
---|
| 1114 | {
|
---|
| 1115 | $$ = new_colon3($2);
|
---|
| 1116 | }
|
---|
| 1117 | | tLBRACK aref_args ']'
|
---|
| 1118 | {
|
---|
| 1119 | $$ = new_array($2);
|
---|
| 1120 | $<node>$.NODE_LINENO($2);
|
---|
| 1121 | }
|
---|
| 1122 | | tLBRACE assoc_list '}'
|
---|
| 1123 | {
|
---|
| 1124 | $$ = new_hash($2);
|
---|
| 1125 | $<node>$.NODE_LINENO($2);
|
---|
| 1126 | }
|
---|
| 1127 | | keyword_return
|
---|
| 1128 | {
|
---|
| 1129 | $$ = new_return(null);
|
---|
| 1130 | }
|
---|
| 1131 | | keyword_yield opt_paren_args
|
---|
| 1132 | {
|
---|
| 1133 | $$ = new_yield($2);
|
---|
| 1134 | }
|
---|
| 1135 | | keyword_not '(' expr rparen
|
---|
| 1136 | {
|
---|
| 1137 | $$ = call_uni_op(cond($3), "!");
|
---|
| 1138 | }
|
---|
| 1139 | | keyword_not '(' rparen
|
---|
| 1140 | {
|
---|
| 1141 | $$ = call_uni_op(new_nil(), "!");
|
---|
| 1142 | }
|
---|
| 1143 | | operation brace_block
|
---|
| 1144 | {
|
---|
| 1145 | $$ = new_fcall($1, cons(null, $2));
|
---|
| 1146 | }
|
---|
| 1147 | | method_call
|
---|
| 1148 | | method_call brace_block
|
---|
| 1149 | {
|
---|
| 1150 | call_with_block($1, $2);
|
---|
| 1151 | $$ = $1;
|
---|
| 1152 | }
|
---|
| 1153 | | tLAMBDA
|
---|
| 1154 | {
|
---|
| 1155 | local_nest();
|
---|
| 1156 | $$ = (int)this.lpar_beg;
|
---|
| 1157 | this.lpar_beg = ++this.paren_nest;
|
---|
| 1158 | }
|
---|
| 1159 | f_larglist
|
---|
| 1160 | {
|
---|
| 1161 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 1162 | this.cmdarg_stack = 0;
|
---|
| 1163 | }
|
---|
| 1164 | lambda_body
|
---|
| 1165 | {
|
---|
| 1166 | this.lpar_beg = $<int>2;
|
---|
| 1167 | $$ = new_lambda($3, $5);
|
---|
| 1168 | local_unnest();
|
---|
| 1169 | this.cmdarg_stack = $<stack_type>4;
|
---|
| 1170 | CMDARG_LEXPOP();
|
---|
| 1171 | }
|
---|
| 1172 | | keyword_if expr_value then
|
---|
| 1173 | compstmt
|
---|
| 1174 | if_tail
|
---|
| 1175 | keyword_end
|
---|
| 1176 | {
|
---|
| 1177 | $$ = new_if(cond($2), $4, $5);
|
---|
| 1178 | $<node>$.SET_LINENO($1);
|
---|
| 1179 | }
|
---|
| 1180 | | keyword_unless expr_value then
|
---|
| 1181 | compstmt
|
---|
| 1182 | opt_else
|
---|
| 1183 | keyword_end
|
---|
| 1184 | {
|
---|
| 1185 | $$ = new_unless(cond($2), $4, $5);
|
---|
| 1186 | $<node>$.SET_LINENO($1);
|
---|
| 1187 | }
|
---|
| 1188 | | keyword_while {COND_PUSH(1);} expr_value do {COND_POP();}
|
---|
| 1189 | compstmt
|
---|
| 1190 | keyword_end
|
---|
| 1191 | {
|
---|
| 1192 | $$ = new_while(cond($3), $6);
|
---|
| 1193 | $<node>$.SET_LINENO($1);
|
---|
| 1194 | }
|
---|
| 1195 | | keyword_until {COND_PUSH(1);} expr_value do {COND_POP();}
|
---|
| 1196 | compstmt
|
---|
| 1197 | keyword_end
|
---|
| 1198 | {
|
---|
| 1199 | $$ = new_until(cond($3), $6);
|
---|
| 1200 | $<node>$.SET_LINENO($1);
|
---|
| 1201 | }
|
---|
| 1202 | | keyword_case expr_value opt_terms
|
---|
| 1203 | case_body
|
---|
| 1204 | keyword_end
|
---|
| 1205 | {
|
---|
| 1206 | $$ = new_case($2, $4);
|
---|
| 1207 | }
|
---|
| 1208 | | keyword_case opt_terms case_body keyword_end
|
---|
| 1209 | {
|
---|
| 1210 | $$ = new_case(null, $3);
|
---|
| 1211 | }
|
---|
| 1212 | | keyword_for for_var keyword_in
|
---|
| 1213 | {COND_PUSH(1);}
|
---|
| 1214 | expr_value do
|
---|
| 1215 | {COND_POP();}
|
---|
| 1216 | compstmt
|
---|
| 1217 | keyword_end
|
---|
| 1218 | {
|
---|
| 1219 | $$ = new_for($2, $5, $8);
|
---|
| 1220 | $<node>$.SET_LINENO($1);
|
---|
| 1221 | }
|
---|
| 1222 | | keyword_class
|
---|
| 1223 | cpath superclass
|
---|
| 1224 | {
|
---|
| 1225 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 1226 | yyError("class definition in method body");
|
---|
| 1227 | $$ = local_switch();
|
---|
| 1228 | }
|
---|
| 1229 | bodystmt
|
---|
| 1230 | keyword_end
|
---|
| 1231 | {
|
---|
| 1232 | $$ = new_class($2, $3, $5);
|
---|
| 1233 | $<node>$.SET_LINENO($1);
|
---|
| 1234 | local_resume($<locals_node>4);
|
---|
| 1235 | }
|
---|
| 1236 | | keyword_class
|
---|
| 1237 | tLSHFT expr
|
---|
| 1238 | {
|
---|
| 1239 | $$ = (int)this.in_def;
|
---|
| 1240 | this.in_def = 0;
|
---|
| 1241 | }
|
---|
| 1242 | term
|
---|
| 1243 | {
|
---|
| 1244 | $$ = cons(local_switch(), this.in_single);
|
---|
| 1245 | this.in_single = 0;
|
---|
| 1246 | }
|
---|
| 1247 | bodystmt
|
---|
| 1248 | keyword_end
|
---|
| 1249 | {
|
---|
| 1250 | $$ = new_sclass($3, $7);
|
---|
| 1251 | $<node>$.SET_LINENO($1);
|
---|
| 1252 | local_resume((locals_node)$<node>6.car);
|
---|
| 1253 | this.in_def = $<int>4;
|
---|
| 1254 | this.in_single = (int)($<node>6.cdr);
|
---|
| 1255 | }
|
---|
| 1256 | | keyword_module
|
---|
| 1257 | cpath
|
---|
| 1258 | {
|
---|
| 1259 | if (this.in_def != 0 || this.in_single != 0)
|
---|
| 1260 | yyError("module definition in method body");
|
---|
| 1261 | $$ = local_switch();
|
---|
| 1262 | }
|
---|
| 1263 | bodystmt
|
---|
| 1264 | keyword_end
|
---|
| 1265 | {
|
---|
| 1266 | $$ = new_module($2, $4);
|
---|
| 1267 | $<node>$.SET_LINENO($1);
|
---|
| 1268 | local_resume($<locals_node>3);
|
---|
| 1269 | }
|
---|
| 1270 | | keyword_def fname
|
---|
| 1271 | {
|
---|
| 1272 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 1273 | this.cmdarg_stack = 0;
|
---|
| 1274 | }
|
---|
| 1275 | {
|
---|
| 1276 | this.in_def++;
|
---|
| 1277 | $$ = local_switch();
|
---|
| 1278 | }
|
---|
| 1279 | f_arglist
|
---|
| 1280 | bodystmt
|
---|
| 1281 | keyword_end
|
---|
| 1282 | {
|
---|
| 1283 | $$ = new_def($2, $5, $6);
|
---|
| 1284 | $<node>$.SET_LINENO($1);
|
---|
| 1285 | local_resume($<locals_node>4);
|
---|
| 1286 | this.in_def--;
|
---|
| 1287 | this.cmdarg_stack = $<stack_type>3;
|
---|
| 1288 | }
|
---|
| 1289 | | keyword_def singleton dot_or_colon
|
---|
| 1290 | {
|
---|
| 1291 | this.lstate = mrb_lex_state_enum.EXPR_FNAME;
|
---|
| 1292 | $$ = (stack_type)this.cmdarg_stack;
|
---|
| 1293 | this.cmdarg_stack = 0;
|
---|
| 1294 | }
|
---|
| 1295 | fname
|
---|
| 1296 | {
|
---|
| 1297 | this.in_single++;
|
---|
| 1298 | this.lstate = mrb_lex_state_enum.EXPR_ENDFN; /* force for args */
|
---|
| 1299 | $$ = local_switch();
|
---|
| 1300 | }
|
---|
| 1301 | f_arglist
|
---|
| 1302 | bodystmt
|
---|
| 1303 | keyword_end
|
---|
| 1304 | {
|
---|
| 1305 | $$ = new_sdef($2, $5, $7, $8);
|
---|
| 1306 | $<node>$.SET_LINENO($1);
|
---|
| 1307 | local_resume($<locals_node>6);
|
---|
| 1308 | this.in_single--;
|
---|
| 1309 | this.cmdarg_stack = $<stack_type>4;
|
---|
| 1310 | }
|
---|
| 1311 | | keyword_break
|
---|
| 1312 | {
|
---|
| 1313 | $$ = new_break(null);
|
---|
| 1314 | }
|
---|
| 1315 | | keyword_next
|
---|
| 1316 | {
|
---|
| 1317 | $$ = new_next(null);
|
---|
| 1318 | }
|
---|
| 1319 | | keyword_redo
|
---|
| 1320 | {
|
---|
| 1321 | $$ = new_redo();
|
---|
| 1322 | }
|
---|
| 1323 | | keyword_retry
|
---|
| 1324 | {
|
---|
| 1325 | $$ = new_retry();
|
---|
| 1326 | }
|
---|
| 1327 | ;
|
---|
| 1328 |
|
---|
| 1329 | primary_value : primary
|
---|
| 1330 | {
|
---|
| 1331 | $$ = $1;
|
---|
| 1332 | if ($$ == null) $$ = new_nil();
|
---|
| 1333 | }
|
---|
| 1334 | ;
|
---|
| 1335 |
|
---|
| 1336 | then : term
|
---|
| 1337 | | keyword_then
|
---|
| 1338 | | term keyword_then
|
---|
| 1339 | ;
|
---|
| 1340 |
|
---|
| 1341 | do : term
|
---|
| 1342 | | keyword_do_cond
|
---|
| 1343 | ;
|
---|
| 1344 |
|
---|
| 1345 | if_tail : opt_else
|
---|
| 1346 | | keyword_elsif expr_value then
|
---|
| 1347 | compstmt
|
---|
| 1348 | if_tail
|
---|
| 1349 | {
|
---|
| 1350 | $$ = new_if(cond($2), $4, $5);
|
---|
| 1351 | }
|
---|
| 1352 | ;
|
---|
| 1353 |
|
---|
| 1354 | opt_else : none
|
---|
| 1355 | | keyword_else compstmt
|
---|
| 1356 | {
|
---|
| 1357 | $$ = $2;
|
---|
| 1358 | }
|
---|
| 1359 | ;
|
---|
| 1360 |
|
---|
| 1361 | for_var : lhs
|
---|
| 1362 | {
|
---|
| 1363 | $$ = list1(list1($1));
|
---|
| 1364 | }
|
---|
| 1365 | | mlhs
|
---|
| 1366 | ;
|
---|
| 1367 |
|
---|
| 1368 | f_marg : f_norm_arg
|
---|
| 1369 | {
|
---|
| 1370 | $$ = new_arg($1);
|
---|
| 1371 | }
|
---|
| 1372 | | tLPAREN f_margs rparen
|
---|
| 1373 | {
|
---|
| 1374 | $$ = new_masgn($2, null);
|
---|
| 1375 | }
|
---|
| 1376 | ;
|
---|
| 1377 |
|
---|
| 1378 | f_marg_list : f_marg
|
---|
| 1379 | {
|
---|
| 1380 | $$ = list1($1);
|
---|
| 1381 | }
|
---|
| 1382 | | f_marg_list ',' f_marg
|
---|
| 1383 | {
|
---|
| 1384 | $$ = push($1, $3);
|
---|
| 1385 | }
|
---|
| 1386 | ;
|
---|
| 1387 |
|
---|
| 1388 | f_margs : f_marg_list
|
---|
| 1389 | {
|
---|
| 1390 | $$ = list3($1, null, null);
|
---|
| 1391 | }
|
---|
| 1392 | | f_marg_list ',' tSTAR f_norm_arg
|
---|
| 1393 | {
|
---|
| 1394 | $$ = list3($1, new_arg($4), null);
|
---|
| 1395 | }
|
---|
| 1396 | | f_marg_list ',' tSTAR f_norm_arg ',' f_marg_list
|
---|
| 1397 | {
|
---|
| 1398 | $$ = list3($1, new_arg($4), $6);
|
---|
| 1399 | }
|
---|
| 1400 | | f_marg_list ',' tSTAR
|
---|
| 1401 | {
|
---|
| 1402 | $$ = list3($1, -1, null);
|
---|
| 1403 | }
|
---|
| 1404 | | f_marg_list ',' tSTAR ',' f_marg_list
|
---|
| 1405 | {
|
---|
| 1406 | $$ = list3($1, -1, $5);
|
---|
| 1407 | }
|
---|
| 1408 | | tSTAR f_norm_arg
|
---|
| 1409 | {
|
---|
| 1410 | $$ = list3(null, new_arg($2), null);
|
---|
| 1411 | }
|
---|
| 1412 | | tSTAR f_norm_arg ',' f_marg_list
|
---|
| 1413 | {
|
---|
| 1414 | $$ = list3(null, new_arg($2), $4);
|
---|
| 1415 | }
|
---|
| 1416 | | tSTAR
|
---|
| 1417 | {
|
---|
| 1418 | $$ = list3(null, -1, null);
|
---|
| 1419 | }
|
---|
| 1420 | | tSTAR ',' f_marg_list
|
---|
| 1421 | {
|
---|
| 1422 | $$ = list3(null, -1, $3);
|
---|
| 1423 | }
|
---|
| 1424 | ;
|
---|
| 1425 |
|
---|
| 1426 | block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_f_block_arg
|
---|
| 1427 | {
|
---|
| 1428 | $$ = new_args($1, $3, $5, null, $6);
|
---|
| 1429 | }
|
---|
| 1430 | | f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 1431 | {
|
---|
| 1432 | $$ = new_args($1, $3, $5, $7, $8);
|
---|
| 1433 | }
|
---|
| 1434 | | f_arg ',' f_block_optarg opt_f_block_arg
|
---|
| 1435 | {
|
---|
| 1436 | $$ = new_args($1, $3, 0, null, $4);
|
---|
| 1437 | }
|
---|
| 1438 | | f_arg ',' f_block_optarg ',' f_arg opt_f_block_arg
|
---|
| 1439 | {
|
---|
| 1440 | $$ = new_args($1, $3, 0, $5, $6);
|
---|
| 1441 | }
|
---|
| 1442 | | f_arg ',' f_rest_arg opt_f_block_arg
|
---|
| 1443 | {
|
---|
| 1444 | $$ = new_args($1, null, $3, null, $4);
|
---|
| 1445 | }
|
---|
| 1446 | | f_arg ','
|
---|
| 1447 | {
|
---|
| 1448 | $$ = new_args($1, null, (mrb_sym)0, null, 0);
|
---|
| 1449 | }
|
---|
| 1450 | | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 1451 | {
|
---|
| 1452 | $$ = new_args($1, null, $3, $5, $6);
|
---|
| 1453 | }
|
---|
| 1454 | | f_arg opt_f_block_arg
|
---|
| 1455 | {
|
---|
| 1456 | $$ = new_args($1, null, 0, null, $2);
|
---|
| 1457 | }
|
---|
| 1458 | | f_block_optarg ',' f_rest_arg opt_f_block_arg
|
---|
| 1459 | {
|
---|
| 1460 | $$ = new_args(null, $1, $3, null, $4);
|
---|
| 1461 | }
|
---|
| 1462 | | f_block_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 1463 | {
|
---|
| 1464 | $$ = new_args(null, $1, $3, $5, $6);
|
---|
| 1465 | }
|
---|
| 1466 | | f_block_optarg opt_f_block_arg
|
---|
| 1467 | {
|
---|
| 1468 | $$ = new_args(null, $1, 0, null, $2);
|
---|
| 1469 | }
|
---|
| 1470 | | f_block_optarg ',' f_arg opt_f_block_arg
|
---|
| 1471 | {
|
---|
| 1472 | $$ = new_args(null, $1, 0, $3, $4);
|
---|
| 1473 | }
|
---|
| 1474 | | f_rest_arg opt_f_block_arg
|
---|
| 1475 | {
|
---|
| 1476 | $$ = new_args(null, null, $1, null, $2);
|
---|
| 1477 | }
|
---|
| 1478 | | f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 1479 | {
|
---|
| 1480 | $$ = new_args(null, null, $1, $3, $4);
|
---|
| 1481 | }
|
---|
| 1482 | | f_block_arg
|
---|
| 1483 | {
|
---|
| 1484 | $$ = new_args(null, null, 0, null, $1);
|
---|
| 1485 | }
|
---|
| 1486 | ;
|
---|
| 1487 |
|
---|
| 1488 | opt_block_param : none
|
---|
| 1489 | | block_param_def
|
---|
| 1490 | {
|
---|
| 1491 | this.cmd_start = true;
|
---|
| 1492 | $$ = $1;
|
---|
| 1493 | }
|
---|
| 1494 | ;
|
---|
| 1495 |
|
---|
| 1496 | block_param_def : '|' opt_bv_decl '|'
|
---|
| 1497 | {
|
---|
| 1498 | $$ = null;
|
---|
| 1499 | }
|
---|
| 1500 | | tOROP
|
---|
| 1501 | {
|
---|
| 1502 | $$ = null;
|
---|
| 1503 | }
|
---|
| 1504 | | '|' block_param opt_bv_decl '|'
|
---|
| 1505 | {
|
---|
| 1506 | $$ = $2;
|
---|
| 1507 | }
|
---|
| 1508 | ;
|
---|
| 1509 |
|
---|
| 1510 |
|
---|
| 1511 | opt_bv_decl : opt_nl
|
---|
| 1512 | {
|
---|
| 1513 | $$ = null;
|
---|
| 1514 | }
|
---|
| 1515 | | opt_nl ';' bv_decls opt_nl
|
---|
| 1516 | {
|
---|
| 1517 | $$ = null;
|
---|
| 1518 | }
|
---|
| 1519 | ;
|
---|
| 1520 |
|
---|
| 1521 | bv_decls : bvar
|
---|
| 1522 | | bv_decls ',' bvar
|
---|
| 1523 | ;
|
---|
| 1524 |
|
---|
| 1525 | bvar : tIDENTIFIER
|
---|
| 1526 | {
|
---|
| 1527 | local_add_f($1);
|
---|
| 1528 | new_bv($1);
|
---|
| 1529 | }
|
---|
| 1530 | | f_bad_arg
|
---|
| 1531 | ;
|
---|
| 1532 |
|
---|
| 1533 | f_larglist : '(' f_args opt_bv_decl ')'
|
---|
| 1534 | {
|
---|
| 1535 | $$ = $2;
|
---|
| 1536 | }
|
---|
| 1537 | | f_args
|
---|
| 1538 | {
|
---|
| 1539 | $$ = $1;
|
---|
| 1540 | }
|
---|
| 1541 | ;
|
---|
| 1542 |
|
---|
| 1543 | lambda_body : tLAMBEG compstmt '}'
|
---|
| 1544 | {
|
---|
| 1545 | $$ = $2;
|
---|
| 1546 | }
|
---|
| 1547 | | keyword_do_LAMBDA compstmt keyword_end
|
---|
| 1548 | {
|
---|
| 1549 | $$ = $2;
|
---|
| 1550 | }
|
---|
| 1551 | ;
|
---|
| 1552 |
|
---|
| 1553 | do_block : keyword_do_block
|
---|
| 1554 | {
|
---|
| 1555 | local_nest();
|
---|
| 1556 | }
|
---|
| 1557 | opt_block_param
|
---|
| 1558 | compstmt
|
---|
| 1559 | keyword_end
|
---|
| 1560 | {
|
---|
| 1561 | $$ = new_block($3, $4, false);
|
---|
| 1562 | local_unnest();
|
---|
| 1563 | }
|
---|
| 1564 | ;
|
---|
| 1565 |
|
---|
| 1566 | block_call : command do_block
|
---|
| 1567 | {
|
---|
| 1568 | if ((node_type)$1.car == node_type.NODE_YIELD) {
|
---|
| 1569 | yyError("block given to yield");
|
---|
| 1570 | }
|
---|
| 1571 | else {
|
---|
| 1572 | call_with_block($1, $2);
|
---|
| 1573 | }
|
---|
| 1574 | $$ = $1;
|
---|
| 1575 | }
|
---|
| 1576 | | block_call call_op2 operation2 opt_paren_args
|
---|
| 1577 | {
|
---|
| 1578 | $$ = new_call($1, $3, $4, $2);
|
---|
| 1579 | }
|
---|
| 1580 | | block_call call_op2 operation2 opt_paren_args brace_block
|
---|
| 1581 | {
|
---|
| 1582 | $$ = new_call($1, $3, $4, $2);
|
---|
| 1583 | call_with_block((node)$$, $5);
|
---|
| 1584 | }
|
---|
| 1585 | | block_call call_op2 operation2 command_args do_block
|
---|
| 1586 | {
|
---|
| 1587 | $$ = new_call($1, $3, $4, $2);
|
---|
| 1588 | call_with_block((node)$$, $5);
|
---|
| 1589 | }
|
---|
| 1590 | ;
|
---|
| 1591 |
|
---|
| 1592 | method_call : operation paren_args
|
---|
| 1593 | {
|
---|
| 1594 | $$ = new_fcall($1, $2);
|
---|
| 1595 | }
|
---|
| 1596 | | primary_value call_op operation2 opt_paren_args
|
---|
| 1597 | {
|
---|
| 1598 | $$ = new_call($1, $3, $4, $2);
|
---|
| 1599 | }
|
---|
| 1600 | | primary_value tCOLON2 operation2 paren_args
|
---|
| 1601 | {
|
---|
| 1602 | $$ = new_call($1, $3, $4, MrbTokens.tCOLON2);
|
---|
| 1603 | }
|
---|
| 1604 | | primary_value tCOLON2 operation3
|
---|
| 1605 | {
|
---|
| 1606 | $$ = new_call($1, $3, null, MrbTokens.tCOLON2);
|
---|
| 1607 | }
|
---|
| 1608 | | primary_value call_op paren_args
|
---|
| 1609 | {
|
---|
| 1610 | $$ = new_call($1, intern("call",4), $3, $2);
|
---|
| 1611 | }
|
---|
| 1612 | | primary_value tCOLON2 paren_args
|
---|
| 1613 | {
|
---|
| 1614 | $$ = new_call($1, intern("call",4), $3, MrbTokens.tCOLON2);
|
---|
| 1615 | }
|
---|
| 1616 | | keyword_super paren_args
|
---|
| 1617 | {
|
---|
| 1618 | $$ = new_super($2);
|
---|
| 1619 | }
|
---|
| 1620 | | keyword_super
|
---|
| 1621 | {
|
---|
| 1622 | $$ = new_zsuper();
|
---|
| 1623 | }
|
---|
| 1624 | | primary_value '[' opt_call_args rbracket
|
---|
| 1625 | {
|
---|
| 1626 | $$ = new_call($1, intern("[]",2), $3, (MrbTokens)'.');
|
---|
| 1627 | }
|
---|
| 1628 | ;
|
---|
| 1629 |
|
---|
| 1630 | brace_block : '{'
|
---|
| 1631 | {
|
---|
| 1632 | local_nest();
|
---|
| 1633 | $$ = (int)this.lineno;
|
---|
| 1634 | }
|
---|
| 1635 | opt_block_param
|
---|
| 1636 | compstmt '}'
|
---|
| 1637 | {
|
---|
| 1638 | $$ = new_block($3, $4, true);
|
---|
| 1639 | $<node>$.SET_LINENO($<int>2);
|
---|
| 1640 | local_unnest();
|
---|
| 1641 | }
|
---|
| 1642 | | keyword_do
|
---|
| 1643 | {
|
---|
| 1644 | local_nest();
|
---|
| 1645 | $$ = (int)this.lineno;
|
---|
| 1646 | }
|
---|
| 1647 | opt_block_param
|
---|
| 1648 | compstmt keyword_end
|
---|
| 1649 | {
|
---|
| 1650 | $$ = new_block($3, $4, false);
|
---|
| 1651 | $<node>$.SET_LINENO($<int>2);
|
---|
| 1652 | local_unnest();
|
---|
| 1653 | }
|
---|
| 1654 | ;
|
---|
| 1655 |
|
---|
| 1656 | case_body : keyword_when args then
|
---|
| 1657 | compstmt
|
---|
| 1658 | cases
|
---|
| 1659 | {
|
---|
| 1660 | $$ = cons(cons($2, $4), $5);
|
---|
| 1661 | }
|
---|
| 1662 | ;
|
---|
| 1663 |
|
---|
| 1664 | cases : opt_else
|
---|
| 1665 | {
|
---|
| 1666 | if ($1 != null) {
|
---|
| 1667 | $$ = cons(cons(null, $1), null);
|
---|
| 1668 | }
|
---|
| 1669 | else {
|
---|
| 1670 | $$ = null;
|
---|
| 1671 | }
|
---|
| 1672 | }
|
---|
| 1673 | | case_body
|
---|
| 1674 | ;
|
---|
| 1675 |
|
---|
| 1676 | opt_rescue : keyword_rescue exc_list exc_var then
|
---|
| 1677 | compstmt
|
---|
| 1678 | opt_rescue
|
---|
| 1679 | {
|
---|
| 1680 | $$ = list1(list3($2, $3, $5));
|
---|
| 1681 | if ($6 != null) $$ = append($<node>$, $6);
|
---|
| 1682 | }
|
---|
| 1683 | | none
|
---|
| 1684 | ;
|
---|
| 1685 |
|
---|
| 1686 | exc_list : arg
|
---|
| 1687 | {
|
---|
| 1688 | $$ = list1($1);
|
---|
| 1689 | }
|
---|
| 1690 | | mrhs
|
---|
| 1691 | | none
|
---|
| 1692 | ;
|
---|
| 1693 |
|
---|
| 1694 | exc_var : tASSOC lhs
|
---|
| 1695 | {
|
---|
| 1696 | $$ = $2;
|
---|
| 1697 | }
|
---|
| 1698 | | none
|
---|
| 1699 | ;
|
---|
| 1700 |
|
---|
| 1701 | opt_ensure : keyword_ensure compstmt
|
---|
| 1702 | {
|
---|
| 1703 | $$ = $2;
|
---|
| 1704 | }
|
---|
| 1705 | | none
|
---|
| 1706 | ;
|
---|
| 1707 |
|
---|
| 1708 | literal : numeric
|
---|
| 1709 | | symbol
|
---|
| 1710 | | words
|
---|
| 1711 | | symbols
|
---|
| 1712 | ;
|
---|
| 1713 |
|
---|
| 1714 | string : tCHAR
|
---|
| 1715 | | tSTRING
|
---|
| 1716 | | tSTRING_BEG tSTRING
|
---|
| 1717 | {
|
---|
| 1718 | $$ = $2;
|
---|
| 1719 | }
|
---|
| 1720 | | tSTRING_BEG string_rep tSTRING
|
---|
| 1721 | {
|
---|
| 1722 | $$ = new_dstr(push($2, $3));
|
---|
| 1723 | }
|
---|
| 1724 | ;
|
---|
| 1725 |
|
---|
| 1726 | string_rep : string_interp
|
---|
| 1727 | | string_rep string_interp
|
---|
| 1728 | {
|
---|
| 1729 | $$ = append($1, $2);
|
---|
| 1730 | }
|
---|
| 1731 | ;
|
---|
| 1732 |
|
---|
| 1733 | string_interp : tSTRING_MID
|
---|
| 1734 | {
|
---|
| 1735 | $$ = list1($1);
|
---|
| 1736 | }
|
---|
| 1737 | | tSTRING_PART
|
---|
| 1738 | {
|
---|
| 1739 | $$ = (node)this.lex_strterm;
|
---|
| 1740 | this.lex_strterm = null;
|
---|
| 1741 | }
|
---|
| 1742 | compstmt
|
---|
| 1743 | '}'
|
---|
| 1744 | {
|
---|
| 1745 | this.lex_strterm = $<node>2;
|
---|
| 1746 | $$ = list2($1, $3);
|
---|
| 1747 | }
|
---|
| 1748 | | tLITERAL_DELIM
|
---|
| 1749 | {
|
---|
| 1750 | $$ = list1(new_literal_delim());
|
---|
| 1751 | }
|
---|
| 1752 | | tHD_LITERAL_DELIM heredoc_bodies
|
---|
| 1753 | {
|
---|
| 1754 | $$ = list1(new_literal_delim());
|
---|
| 1755 | }
|
---|
| 1756 | ;
|
---|
| 1757 |
|
---|
| 1758 | xstring : tXSTRING_BEG tXSTRING
|
---|
| 1759 | {
|
---|
| 1760 | $$ = $2;
|
---|
| 1761 | }
|
---|
| 1762 | | tXSTRING_BEG string_rep tXSTRING
|
---|
| 1763 | {
|
---|
| 1764 | $$ = new_dxstr(push($2, $3));
|
---|
| 1765 | }
|
---|
| 1766 | ;
|
---|
| 1767 |
|
---|
| 1768 | regexp : tREGEXP_BEG tREGEXP
|
---|
| 1769 | {
|
---|
| 1770 | $$ = $2;
|
---|
| 1771 | }
|
---|
| 1772 | | tREGEXP_BEG string_rep tREGEXP
|
---|
| 1773 | {
|
---|
| 1774 | $$ = new_dregx($2, $3);
|
---|
| 1775 | }
|
---|
| 1776 | ;
|
---|
| 1777 |
|
---|
| 1778 | heredoc : tHEREDOC_BEG
|
---|
| 1779 | ;
|
---|
| 1780 |
|
---|
| 1781 | heredoc_bodies : heredoc_body
|
---|
| 1782 | | heredoc_bodies heredoc_body
|
---|
| 1783 | ;
|
---|
| 1784 |
|
---|
| 1785 | heredoc_body : tHEREDOC_END
|
---|
| 1786 | {
|
---|
| 1787 | parser_heredoc_info inf = parsing_heredoc_inf();
|
---|
| 1788 | inf.push_doc(new_str(new Uint8Array(0), 0));
|
---|
| 1789 | heredoc_end();
|
---|
| 1790 | }
|
---|
| 1791 | | heredoc_string_rep tHEREDOC_END
|
---|
| 1792 | {
|
---|
| 1793 | heredoc_end();
|
---|
| 1794 | }
|
---|
| 1795 | ;
|
---|
| 1796 |
|
---|
| 1797 | heredoc_string_rep : heredoc_string_interp
|
---|
| 1798 | | heredoc_string_rep heredoc_string_interp
|
---|
| 1799 | ;
|
---|
| 1800 |
|
---|
| 1801 | heredoc_string_interp : tHD_STRING_MID
|
---|
| 1802 | {
|
---|
| 1803 | parser_heredoc_info inf = parsing_heredoc_inf();
|
---|
| 1804 | inf.push_doc($1);
|
---|
| 1805 | heredoc_treat_nextline();
|
---|
| 1806 | }
|
---|
| 1807 | | tHD_STRING_PART
|
---|
| 1808 | {
|
---|
| 1809 | $$ = (node)this.lex_strterm;
|
---|
| 1810 | this.lex_strterm = null;
|
---|
| 1811 | }
|
---|
| 1812 | compstmt
|
---|
| 1813 | '}'
|
---|
| 1814 | {
|
---|
| 1815 | parser_heredoc_info inf = parsing_heredoc_inf();
|
---|
| 1816 | this.lex_strterm = $<node>2;
|
---|
| 1817 | inf.push_doc($1);
|
---|
| 1818 | inf.push_doc($3);
|
---|
| 1819 | }
|
---|
| 1820 | ;
|
---|
| 1821 |
|
---|
| 1822 | words : tWORDS_BEG tSTRING
|
---|
| 1823 | {
|
---|
| 1824 | $$ = new_words(list1($2));
|
---|
| 1825 | }
|
---|
| 1826 | | tWORDS_BEG string_rep tSTRING
|
---|
| 1827 | {
|
---|
| 1828 | $$ = new_words(push($2, $3));
|
---|
| 1829 | }
|
---|
| 1830 | ;
|
---|
| 1831 |
|
---|
| 1832 |
|
---|
| 1833 | symbol : basic_symbol
|
---|
| 1834 | {
|
---|
| 1835 | $$ = new_sym($1);
|
---|
| 1836 | }
|
---|
| 1837 | | tSYMBEG tSTRING_BEG string_rep tSTRING
|
---|
| 1838 | {
|
---|
| 1839 | this.lstate = mrb_lex_state_enum.EXPR_END;
|
---|
| 1840 | $$ = new_dsym(push($3, $4));
|
---|
| 1841 | }
|
---|
| 1842 | ;
|
---|
| 1843 |
|
---|
| 1844 | basic_symbol : tSYMBEG sym
|
---|
| 1845 | {
|
---|
| 1846 | this.lstate = mrb_lex_state_enum.EXPR_END;
|
---|
| 1847 | $$ = $2;
|
---|
| 1848 | }
|
---|
| 1849 | ;
|
---|
| 1850 |
|
---|
| 1851 | sym : fname
|
---|
| 1852 | | tIVAR
|
---|
| 1853 | | tGVAR
|
---|
| 1854 | | tCVAR
|
---|
| 1855 | | tSTRING
|
---|
| 1856 | {
|
---|
| 1857 | $$ = new_strsym($1);
|
---|
| 1858 | }
|
---|
| 1859 | | tSTRING_BEG tSTRING
|
---|
| 1860 | {
|
---|
| 1861 | $$ = new_strsym($2);
|
---|
| 1862 | }
|
---|
| 1863 | ;
|
---|
| 1864 |
|
---|
| 1865 | symbols : tSYMBOLS_BEG tSTRING
|
---|
| 1866 | {
|
---|
| 1867 | $$ = new_symbols(list1($2));
|
---|
| 1868 | }
|
---|
| 1869 | | tSYMBOLS_BEG string_rep tSTRING
|
---|
| 1870 | {
|
---|
| 1871 | $$ = new_symbols(push($2, $3));
|
---|
| 1872 | }
|
---|
| 1873 | ;
|
---|
| 1874 |
|
---|
| 1875 | numeric : tINTEGER
|
---|
| 1876 | | tFLOAT
|
---|
| 1877 | | tUMINUS_NUM tINTEGER %prec tLOWEST
|
---|
| 1878 | {
|
---|
| 1879 | $$ = negate_lit($2);
|
---|
| 1880 | }
|
---|
| 1881 | | tUMINUS_NUM tFLOAT %prec tLOWEST
|
---|
| 1882 | {
|
---|
| 1883 | $$ = negate_lit($2);
|
---|
| 1884 | }
|
---|
| 1885 | ;
|
---|
| 1886 |
|
---|
| 1887 | variable : tIDENTIFIER
|
---|
| 1888 | {
|
---|
| 1889 | $$ = new_lvar($1);
|
---|
| 1890 | }
|
---|
| 1891 | | tIVAR
|
---|
| 1892 | {
|
---|
| 1893 | $$ = new_ivar($1);
|
---|
| 1894 | }
|
---|
| 1895 | | tGVAR
|
---|
| 1896 | {
|
---|
| 1897 | $$ = new_gvar($1);
|
---|
| 1898 | }
|
---|
| 1899 | | tCVAR
|
---|
| 1900 | {
|
---|
| 1901 | $$ = new_cvar($1);
|
---|
| 1902 | }
|
---|
| 1903 | | tCONSTANT
|
---|
| 1904 | {
|
---|
| 1905 | $$ = new_const($1);
|
---|
| 1906 | }
|
---|
| 1907 | ;
|
---|
| 1908 |
|
---|
| 1909 | var_lhs : variable
|
---|
| 1910 | {
|
---|
| 1911 | assignable($1);
|
---|
| 1912 | }
|
---|
| 1913 | ;
|
---|
| 1914 |
|
---|
| 1915 | var_ref : variable
|
---|
| 1916 | {
|
---|
| 1917 | $$ = var_reference($1);
|
---|
| 1918 | }
|
---|
| 1919 | | keyword_nil
|
---|
| 1920 | {
|
---|
| 1921 | $$ = new_nil();
|
---|
| 1922 | }
|
---|
| 1923 | | keyword_self
|
---|
| 1924 | {
|
---|
| 1925 | $$ = new_self();
|
---|
| 1926 | }
|
---|
| 1927 | | keyword_true
|
---|
| 1928 | {
|
---|
| 1929 | $$ = new_true();
|
---|
| 1930 | }
|
---|
| 1931 | | keyword_false
|
---|
| 1932 | {
|
---|
| 1933 | $$ = new_false();
|
---|
| 1934 | }
|
---|
| 1935 | | keyword__FILE__
|
---|
| 1936 | {
|
---|
| 1937 | if (this.filename == null) {
|
---|
| 1938 | this.mrb_parser_set_filename("(null)");
|
---|
| 1939 | }
|
---|
| 1940 | $$ = new_filename(this.filename);
|
---|
| 1941 | }
|
---|
| 1942 | | keyword__LINE__
|
---|
| 1943 | {
|
---|
| 1944 | $$ = new_lineno(this.lineno);
|
---|
| 1945 | }
|
---|
| 1946 | ;
|
---|
| 1947 |
|
---|
| 1948 | backref : tNTH_REF
|
---|
| 1949 | | tBACK_REF
|
---|
| 1950 | ;
|
---|
| 1951 |
|
---|
| 1952 | superclass : /* term */
|
---|
| 1953 | {
|
---|
| 1954 | $$ = null;
|
---|
| 1955 | }
|
---|
| 1956 | | '<'
|
---|
| 1957 | {
|
---|
| 1958 | this.lstate = mrb_lex_state_enum.EXPR_BEG;
|
---|
| 1959 | this.cmd_start = true;
|
---|
| 1960 | }
|
---|
| 1961 | expr_value term
|
---|
| 1962 | {
|
---|
| 1963 | $$ = $3;
|
---|
| 1964 | } /*
|
---|
| 1965 | | error term
|
---|
| 1966 | {
|
---|
| 1967 | yyErrorFlag = 0;
|
---|
| 1968 | $$ = null;
|
---|
| 1969 | } */
|
---|
| 1970 | ;
|
---|
| 1971 |
|
---|
| 1972 | f_arglist : '(' f_args rparen
|
---|
| 1973 | {
|
---|
| 1974 | $$ = $2;
|
---|
| 1975 | this.lstate = mrb_lex_state_enum.EXPR_BEG;
|
---|
| 1976 | this.cmd_start = true;
|
---|
| 1977 | }
|
---|
| 1978 | | f_args term
|
---|
| 1979 | {
|
---|
| 1980 | $$ = $1;
|
---|
| 1981 | }
|
---|
| 1982 | ;
|
---|
| 1983 |
|
---|
| 1984 | f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
|
---|
| 1985 | {
|
---|
| 1986 | $$ = new_args($1, $3, $5, null, $6);
|
---|
| 1987 | }
|
---|
| 1988 | | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 1989 | {
|
---|
| 1990 | $$ = new_args($1, $3, $5, $7, $8);
|
---|
| 1991 | }
|
---|
| 1992 | | f_arg ',' f_optarg opt_f_block_arg
|
---|
| 1993 | {
|
---|
| 1994 | $$ = new_args($1, $3, 0, null, $4);
|
---|
| 1995 | }
|
---|
| 1996 | | f_arg ',' f_optarg ',' f_arg opt_f_block_arg
|
---|
| 1997 | {
|
---|
| 1998 | $$ = new_args($1, $3, 0, $5, $6);
|
---|
| 1999 | }
|
---|
| 2000 | | f_arg ',' f_rest_arg opt_f_block_arg
|
---|
| 2001 | {
|
---|
| 2002 | $$ = new_args($1, null, $3, null, $4);
|
---|
| 2003 | }
|
---|
| 2004 | | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 2005 | {
|
---|
| 2006 | $$ = new_args($1, null, $3, $5, $6);
|
---|
| 2007 | }
|
---|
| 2008 | | f_arg opt_f_block_arg
|
---|
| 2009 | {
|
---|
| 2010 | $$ = new_args($1, null, 0, null, $2);
|
---|
| 2011 | }
|
---|
| 2012 | | f_optarg ',' f_rest_arg opt_f_block_arg
|
---|
| 2013 | {
|
---|
| 2014 | $$ = new_args(null, $1, $3, null, $4);
|
---|
| 2015 | }
|
---|
| 2016 | | f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 2017 | {
|
---|
| 2018 | $$ = new_args(null, $1, $3, $5, $6);
|
---|
| 2019 | }
|
---|
| 2020 | | f_optarg opt_f_block_arg
|
---|
| 2021 | {
|
---|
| 2022 | $$ = new_args(null, $1, 0, null, $2);
|
---|
| 2023 | }
|
---|
| 2024 | | f_optarg ',' f_arg opt_f_block_arg
|
---|
| 2025 | {
|
---|
| 2026 | $$ = new_args(null, $1, 0, $3, $4);
|
---|
| 2027 | }
|
---|
| 2028 | | f_rest_arg opt_f_block_arg
|
---|
| 2029 | {
|
---|
| 2030 | $$ = new_args(null, null, $1, null, $2);
|
---|
| 2031 | }
|
---|
| 2032 | | f_rest_arg ',' f_arg opt_f_block_arg
|
---|
| 2033 | {
|
---|
| 2034 | $$ = new_args(null, null, $1, $3, $4);
|
---|
| 2035 | }
|
---|
| 2036 | | f_block_arg
|
---|
| 2037 | {
|
---|
| 2038 | $$ = new_args(null, null, 0, null, $1);
|
---|
| 2039 | }
|
---|
| 2040 | | /* none */
|
---|
| 2041 | {
|
---|
| 2042 | local_add_f(0);
|
---|
| 2043 | $$ = new_args(null, null, 0, null, 0);
|
---|
| 2044 | }
|
---|
| 2045 | ;
|
---|
| 2046 |
|
---|
| 2047 | f_bad_arg : tCONSTANT
|
---|
| 2048 | {
|
---|
| 2049 | yyError("formal argument cannot be a constant");
|
---|
| 2050 | $$ = null;
|
---|
| 2051 | }
|
---|
| 2052 | | tIVAR
|
---|
| 2053 | {
|
---|
| 2054 | yyError("formal argument cannot be an instance variable");
|
---|
| 2055 | $$ = null;
|
---|
| 2056 | }
|
---|
| 2057 | | tGVAR
|
---|
| 2058 | {
|
---|
| 2059 | yyError("formal argument cannot be a global variable");
|
---|
| 2060 | $$ = null;
|
---|
| 2061 | }
|
---|
| 2062 | | tCVAR
|
---|
| 2063 | {
|
---|
| 2064 | yyError("formal argument cannot be a class variable");
|
---|
| 2065 | $$ = null;
|
---|
| 2066 | }
|
---|
| 2067 | ;
|
---|
| 2068 |
|
---|
| 2069 | f_norm_arg : f_bad_arg
|
---|
| 2070 | {
|
---|
| 2071 | $$ = null;
|
---|
| 2072 | }
|
---|
| 2073 | | tIDENTIFIER
|
---|
| 2074 | {
|
---|
| 2075 | local_add_f($1);
|
---|
| 2076 | $$ = $1;
|
---|
| 2077 | }
|
---|
| 2078 | ;
|
---|
| 2079 |
|
---|
| 2080 | f_arg_item : f_norm_arg
|
---|
| 2081 | {
|
---|
| 2082 | $$ = new_arg($1);
|
---|
| 2083 | }
|
---|
| 2084 | | tLPAREN f_margs rparen
|
---|
| 2085 | {
|
---|
| 2086 | $$ = new_masgn($2, null);
|
---|
| 2087 | }
|
---|
| 2088 | ;
|
---|
| 2089 |
|
---|
| 2090 | f_arg : f_arg_item
|
---|
| 2091 | {
|
---|
| 2092 | $$ = list1($1);
|
---|
| 2093 | }
|
---|
| 2094 | | f_arg ',' f_arg_item
|
---|
| 2095 | {
|
---|
| 2096 | $$ = push($1, $3);
|
---|
| 2097 | }
|
---|
| 2098 | ;
|
---|
| 2099 |
|
---|
| 2100 | f_opt_asgn : tIDENTIFIER '='
|
---|
| 2101 | {
|
---|
| 2102 | local_add_f($1);
|
---|
| 2103 | $$ = $1;
|
---|
| 2104 | }
|
---|
| 2105 | ;
|
---|
| 2106 |
|
---|
| 2107 | f_opt : f_opt_asgn arg
|
---|
| 2108 | {
|
---|
| 2109 | $$ = cons($1, $2);
|
---|
| 2110 | }
|
---|
| 2111 | ;
|
---|
| 2112 |
|
---|
| 2113 | f_block_opt : f_opt_asgn primary_value
|
---|
| 2114 | {
|
---|
| 2115 | $$ = cons($1, $2);
|
---|
| 2116 | }
|
---|
| 2117 | ;
|
---|
| 2118 |
|
---|
| 2119 | f_block_optarg : f_block_opt
|
---|
| 2120 | {
|
---|
| 2121 | $$ = list1($1);
|
---|
| 2122 | }
|
---|
| 2123 | | f_block_optarg ',' f_block_opt
|
---|
| 2124 | {
|
---|
| 2125 | $$ = push($1, $3);
|
---|
| 2126 | }
|
---|
| 2127 | ;
|
---|
| 2128 |
|
---|
| 2129 | f_optarg : f_opt
|
---|
| 2130 | {
|
---|
| 2131 | $$ = list1($1);
|
---|
| 2132 | }
|
---|
| 2133 | | f_optarg ',' f_opt
|
---|
| 2134 | {
|
---|
| 2135 | $$ = push($1, $3);
|
---|
| 2136 | }
|
---|
| 2137 | ;
|
---|
| 2138 |
|
---|
| 2139 | restarg_mark : '*'
|
---|
| 2140 | | tSTAR
|
---|
| 2141 | ;
|
---|
| 2142 |
|
---|
| 2143 | f_rest_arg : restarg_mark tIDENTIFIER
|
---|
| 2144 | {
|
---|
| 2145 | local_add_f($2);
|
---|
| 2146 | $$ = $2;
|
---|
| 2147 | }
|
---|
| 2148 | | restarg_mark
|
---|
| 2149 | {
|
---|
| 2150 | local_add_f(0);
|
---|
| 2151 | $$ = -1;
|
---|
| 2152 | }
|
---|
| 2153 | ;
|
---|
| 2154 |
|
---|
| 2155 | blkarg_mark : '&'
|
---|
| 2156 | | tAMPER
|
---|
| 2157 | ;
|
---|
| 2158 |
|
---|
| 2159 | f_block_arg : blkarg_mark tIDENTIFIER
|
---|
| 2160 | {
|
---|
| 2161 | local_add_f($2);
|
---|
| 2162 | $$ = $2;
|
---|
| 2163 | }
|
---|
| 2164 | ;
|
---|
| 2165 |
|
---|
| 2166 | opt_f_block_arg : ',' f_block_arg
|
---|
| 2167 | {
|
---|
| 2168 | $$ = $2;
|
---|
| 2169 | }
|
---|
| 2170 | | none
|
---|
| 2171 | {
|
---|
| 2172 | local_add_f(0);
|
---|
| 2173 | $$ = 0;
|
---|
| 2174 | }
|
---|
| 2175 | ;
|
---|
| 2176 |
|
---|
| 2177 | singleton : var_ref
|
---|
| 2178 | {
|
---|
| 2179 | $$ = $1;
|
---|
| 2180 | if ($$ == null) $$ = new_nil();
|
---|
| 2181 | }
|
---|
| 2182 | | '(' {this.lstate = mrb_lex_state_enum.EXPR_BEG;} expr rparen
|
---|
| 2183 | {
|
---|
| 2184 | if ($<int>3 == 0) {
|
---|
| 2185 | yyError("can't define singleton method for ().");
|
---|
| 2186 | }
|
---|
| 2187 | else {
|
---|
| 2188 | switch ((node_type)($3.car)) {
|
---|
| 2189 | case node_type.NODE_STR:
|
---|
| 2190 | case node_type.NODE_DSTR:
|
---|
| 2191 | case node_type.NODE_XSTR:
|
---|
| 2192 | case node_type.NODE_DXSTR:
|
---|
| 2193 | case node_type.NODE_DREGX:
|
---|
| 2194 | case node_type.NODE_MATCH:
|
---|
| 2195 | case node_type.NODE_FLOAT:
|
---|
| 2196 | case node_type.NODE_ARRAY:
|
---|
| 2197 | case node_type.NODE_HEREDOC:
|
---|
| 2198 | yyError("can't define singleton method for literals");
|
---|
| 2199 | break;
|
---|
| 2200 | default:
|
---|
| 2201 | break;
|
---|
| 2202 | }
|
---|
| 2203 | }
|
---|
| 2204 | $$ = $3;
|
---|
| 2205 | }
|
---|
| 2206 | ;
|
---|
| 2207 |
|
---|
| 2208 | assoc_list : none
|
---|
| 2209 | | assocs trailer
|
---|
| 2210 | {
|
---|
| 2211 | $$ = $1;
|
---|
| 2212 | }
|
---|
| 2213 | ;
|
---|
| 2214 |
|
---|
| 2215 | assocs : assoc
|
---|
| 2216 | {
|
---|
| 2217 | $$ = list1($1);
|
---|
| 2218 | $<node>$.NODE_LINENO($1);
|
---|
| 2219 | }
|
---|
| 2220 | | assocs ',' assoc
|
---|
| 2221 | {
|
---|
| 2222 | $$ = push($1, $3);
|
---|
| 2223 | }
|
---|
| 2224 | ;
|
---|
| 2225 |
|
---|
| 2226 | assoc : arg tASSOC arg
|
---|
| 2227 | {
|
---|
| 2228 | $$ = cons($1, $3);
|
---|
| 2229 | }
|
---|
| 2230 | | tLABEL arg
|
---|
| 2231 | {
|
---|
| 2232 | $$ = cons(new_sym($1), $2);
|
---|
| 2233 | }
|
---|
| 2234 | | tLABEL_END arg
|
---|
| 2235 | {
|
---|
| 2236 | $$ = cons(new_sym(new_strsym($1)), $2);
|
---|
| 2237 | }
|
---|
| 2238 | | tSTRING_BEG tLABEL_END arg
|
---|
| 2239 | {
|
---|
| 2240 | $$ = cons(new_sym(new_strsym($2)), $3);
|
---|
| 2241 | }
|
---|
| 2242 | | tSTRING_BEG string_rep tLABEL_END arg
|
---|
| 2243 | {
|
---|
| 2244 | $$ = cons(new_dsym(push($2, $3)), $4);
|
---|
| 2245 | }
|
---|
| 2246 | ;
|
---|
| 2247 |
|
---|
| 2248 | operation : tIDENTIFIER
|
---|
| 2249 | | tCONSTANT
|
---|
| 2250 | | tFID
|
---|
| 2251 | ;
|
---|
| 2252 |
|
---|
| 2253 | operation2 : tIDENTIFIER
|
---|
| 2254 | | tCONSTANT
|
---|
| 2255 | | tFID
|
---|
| 2256 | | op
|
---|
| 2257 | ;
|
---|
| 2258 |
|
---|
| 2259 | operation3 : tIDENTIFIER
|
---|
| 2260 | | tFID
|
---|
| 2261 | | op
|
---|
| 2262 | ;
|
---|
| 2263 |
|
---|
| 2264 | dot_or_colon : '.'
|
---|
| 2265 | | tCOLON2
|
---|
| 2266 | ;
|
---|
| 2267 |
|
---|
| 2268 | call_op : '.'
|
---|
| 2269 | {
|
---|
| 2270 | $$ = (MrbTokens)'.';
|
---|
| 2271 | }
|
---|
| 2272 | | tANDDOT
|
---|
| 2273 | {
|
---|
| 2274 | $$ = (MrbTokens)0;
|
---|
| 2275 | }
|
---|
| 2276 | ;
|
---|
| 2277 |
|
---|
| 2278 | call_op2 : call_op
|
---|
| 2279 | | tCOLON2
|
---|
| 2280 | {
|
---|
| 2281 | $$ = MrbTokens.tCOLON2;
|
---|
| 2282 | }
|
---|
| 2283 | ;
|
---|
| 2284 |
|
---|
| 2285 | opt_terms : /* none */
|
---|
| 2286 | | terms
|
---|
| 2287 | ;
|
---|
| 2288 |
|
---|
| 2289 | opt_nl : /* none */
|
---|
| 2290 | | nl
|
---|
| 2291 | ;
|
---|
| 2292 |
|
---|
| 2293 | rparen : opt_nl ')'
|
---|
| 2294 | ;
|
---|
| 2295 |
|
---|
| 2296 | rbracket : opt_nl ']'
|
---|
| 2297 | ;
|
---|
| 2298 |
|
---|
| 2299 | trailer : /* none */
|
---|
| 2300 | | nl
|
---|
| 2301 | | comma
|
---|
| 2302 | ;
|
---|
| 2303 |
|
---|
| 2304 | term : ';' {yyErrorFlag = 0;}
|
---|
| 2305 | | nl
|
---|
| 2306 | | heredoc_body
|
---|
| 2307 | ;
|
---|
| 2308 |
|
---|
| 2309 | nl : '\n'
|
---|
| 2310 | {
|
---|
| 2311 | this.lineno++;
|
---|
| 2312 | this.column = 0;
|
---|
| 2313 | }
|
---|
| 2314 | ;
|
---|
| 2315 |
|
---|
| 2316 | terms : term
|
---|
| 2317 | | terms term
|
---|
| 2318 | ;
|
---|
| 2319 |
|
---|
| 2320 | none : /* none */
|
---|
| 2321 | {
|
---|
| 2322 | $$ = null;
|
---|
| 2323 | }
|
---|
| 2324 | ;
|
---|
| 2325 | %%
|
---|
| 2326 |
|
---|
| 2327 | } // must specify trailing } for parser class
|
---|
| 2328 | } // must specify trailing } for namespace, if any
|
---|