PageRenderTime 70ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/ext/melbourne/grammar.y

https://github.com/vasco/rubinius
Happy | 5852 lines | 5342 code | 510 blank | 0 comment | 0 complexity | 1358a622624b5adbc84e5ec1d97c0e89 MD5 | raw file
Possible License(s): GPL-2.0, BSD-2-Clause, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /**********************************************************************
  2. parse.y -
  3. $Author: matz $
  4. $Date: 2004/11/29 06:13:51 $
  5. created at: Fri May 28 18:02:42 JST 1993
  6. Copyright (C) 1993-2003 Yukihiro Matsumoto
  7. **********************************************************************/
  8. %{
  9. #define YYDEBUG 1
  10. #define YYERROR_VERBOSE 1
  11. #include <stdio.h>
  12. #include <errno.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include <stdbool.h>
  16. #include <assert.h>
  17. #include "ruby.h"
  18. #include "internal.hpp"
  19. #include "visitor.hpp"
  20. #include "local_state.hpp"
  21. namespace melbourne {
  22. #ifndef isnumber
  23. #define isnumber isdigit
  24. #endif
  25. /* Defined at least in mach/boolean.h on OS X. */
  26. #ifdef TRUE
  27. #undef TRUE
  28. #endif
  29. #ifdef FALSE
  30. #undef FALSE
  31. #endif
  32. #define TRUE true
  33. #define FALSE false
  34. /*
  35. #define ISALPHA isalpha
  36. #define ISSPACE isspace
  37. #define ISALNUM(x) (isalpha(x) || isnumber(x))
  38. #define ISDIGIT isdigit
  39. #define ISXDIGIT isxdigit
  40. #define ISUPPER isupper
  41. */
  42. #define ismbchar(c) (0)
  43. #define mbclen(c) (1)
  44. #define string_new(ptr, len) blk2bstr(ptr, len)
  45. #define string_new2(ptr) cstr2bstr(ptr)
  46. long mel_sourceline;
  47. static char *mel_sourcefile;
  48. #define ruby_sourceline mel_sourceline
  49. #define ruby_sourcefile mel_sourcefile
  50. static int
  51. mel_yyerror(const char *, rb_parse_state*);
  52. #define yyparse mel_yyparse
  53. #define yylex mel_yylex
  54. #define yyerror(str) mel_yyerror(str, (rb_parse_state*)parse_state)
  55. #define yylval mel_yylval
  56. #define yychar mel_yychar
  57. #define yydebug mel_yydebug
  58. #define YYPARSE_PARAM parse_state
  59. #define YYLEX_PARAM parse_state
  60. #define ID_SCOPE_SHIFT 3
  61. #define ID_SCOPE_MASK 0x07
  62. #define ID_LOCAL 0x01
  63. #define ID_INSTANCE 0x02
  64. #define ID_GLOBAL 0x03
  65. #define ID_ATTRSET 0x04
  66. #define ID_CONST 0x05
  67. #define ID_CLASS 0x06
  68. #define ID_JUNK 0x07
  69. #define ID_INTERNAL ID_JUNK
  70. #define is_notop_id(id) ((id)>tLAST_TOKEN)
  71. #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
  72. #define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
  73. #define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
  74. #define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
  75. #define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
  76. #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
  77. #define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
  78. #define is_asgn_or_id(id) ((is_notop_id(id)) && \
  79. (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
  80. ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
  81. ((id)&ID_SCOPE_MASK) == ID_CLASS))
  82. /* FIXME these went into the ruby_state instead of parse_state
  83. because a ton of other crap depends on it
  84. char *ruby_sourcefile; current source file
  85. int ruby_sourceline; current line no.
  86. */
  87. static int yylex(void*, void *);
  88. #define BITSTACK_PUSH(stack, n) (stack = (stack<<1)|((n)&1))
  89. #define BITSTACK_POP(stack) (stack >>= 1)
  90. #define BITSTACK_LEXPOP(stack) (stack = (stack >> 1) | (stack & 1))
  91. #define BITSTACK_SET_P(stack) (stack&1)
  92. #define COND_PUSH(n) BITSTACK_PUSH(vps->cond_stack, n)
  93. #define COND_POP() BITSTACK_POP(vps->cond_stack)
  94. #define COND_LEXPOP() BITSTACK_LEXPOP(vps->cond_stack)
  95. #define COND_P() BITSTACK_SET_P(vps->cond_stack)
  96. #define CMDARG_PUSH(n) BITSTACK_PUSH(vps->cmdarg_stack, n)
  97. #define CMDARG_POP() BITSTACK_POP(vps->cmdarg_stack)
  98. #define CMDARG_LEXPOP() BITSTACK_LEXPOP(vps->cmdarg_stack)
  99. #define CMDARG_P() BITSTACK_SET_P(vps->cmdarg_stack)
  100. /*
  101. static int class_nest = 0;
  102. static int in_single = 0;
  103. static int in_def = 0;
  104. static int compile_for_eval = 0;
  105. static ID cur_mid = 0;
  106. */
  107. static NODE *cond(NODE*,rb_parse_state*);
  108. static NODE *logop(enum node_type,NODE*,NODE*,rb_parse_state*);
  109. static int cond_negative(NODE**);
  110. static NODE *newline_node(rb_parse_state*,NODE*);
  111. static void fixpos(NODE*,NODE*);
  112. static int value_expr0(NODE*,rb_parse_state*);
  113. static void void_expr0(NODE*,rb_parse_state*);
  114. static void void_stmts(NODE*,rb_parse_state*);
  115. static NODE *remove_begin(NODE*,rb_parse_state*);
  116. #define value_expr(node) value_expr0((node) = \
  117. remove_begin(node, (rb_parse_state*)parse_state), \
  118. (rb_parse_state*)parse_state)
  119. #define void_expr(node) void_expr0((node) = \
  120. remove_begin(node, (rb_parse_state*)parse_state), \
  121. (rb_parse_state*)parse_state)
  122. static NODE *block_append(rb_parse_state*,NODE*,NODE*);
  123. static NODE *list_append(rb_parse_state*,NODE*,NODE*);
  124. static NODE *list_concat(NODE*,NODE*);
  125. static NODE *arg_concat(rb_parse_state*,NODE*,NODE*);
  126. static NODE *arg_prepend(rb_parse_state*,NODE*,NODE*);
  127. static NODE *literal_concat(rb_parse_state*,NODE*,NODE*);
  128. static NODE *new_evstr(rb_parse_state*,NODE*);
  129. static NODE *evstr2dstr(rb_parse_state*,NODE*);
  130. static NODE *call_op(NODE*,QUID,int,NODE*,rb_parse_state*);
  131. /* static NODE *negate_lit(NODE*); */
  132. static NODE *ret_args(rb_parse_state*,NODE*);
  133. static NODE *arg_blk_pass(NODE*,NODE*);
  134. static NODE *new_call(rb_parse_state*,NODE*,QUID,NODE*);
  135. static NODE *new_fcall(rb_parse_state*,QUID,NODE*);
  136. static NODE *new_super(rb_parse_state*,NODE*);
  137. static NODE *new_yield(rb_parse_state*,NODE*);
  138. static NODE *mel_gettable(rb_parse_state*,QUID);
  139. #define gettable(i) mel_gettable((rb_parse_state*)parse_state, i)
  140. static NODE *assignable(QUID,NODE*,rb_parse_state*);
  141. static NODE *aryset(NODE*,NODE*,rb_parse_state*);
  142. static NODE *attrset(NODE*,QUID,rb_parse_state*);
  143. static void rb_backref_error(NODE*,rb_parse_state*);
  144. static NODE *node_assign(NODE*,NODE*,rb_parse_state*);
  145. static NODE *match_gen(NODE*,NODE*,rb_parse_state*);
  146. static void mel_local_push(rb_parse_state*, int cnt);
  147. #define local_push(cnt) mel_local_push(vps, cnt)
  148. static void mel_local_pop(rb_parse_state*);
  149. #define local_pop() mel_local_pop(vps)
  150. static intptr_t mel_local_cnt(rb_parse_state*,QUID);
  151. #define local_cnt(i) mel_local_cnt(vps, i)
  152. static int mel_local_id(rb_parse_state*,QUID);
  153. #define local_id(i) mel_local_id(vps, i)
  154. static QUID *mel_local_tbl(rb_parse_state *st);
  155. static QUID convert_op(QUID id);
  156. static void tokadd(char c, rb_parse_state *parse_state);
  157. static int tokadd_string(int, int, int, QUID*, rb_parse_state*);
  158. #define SHOW_PARSER_WARNS 0
  159. static int rb_compile_error(rb_parse_state *st, const char *fmt, ...) {
  160. va_list ar;
  161. char msg[256];
  162. int count;
  163. va_start(ar, fmt);
  164. count = vsnprintf(msg, 256, fmt, ar);
  165. va_end(ar);
  166. mel_yyerror(msg, st);
  167. return count;
  168. }
  169. static int _debug_print(const char *fmt, ...) {
  170. #if SHOW_PARSER_WARNS
  171. va_list ar;
  172. int i;
  173. va_start(ar, fmt);
  174. i = vprintf(fmt, ar);
  175. va_end(ar);
  176. return i;
  177. #else
  178. return 0;
  179. #endif
  180. }
  181. #define rb_warn _debug_print
  182. #define rb_warning _debug_print
  183. static QUID rb_intern(const char *name);
  184. static QUID rb_id_attrset(QUID);
  185. rb_parse_state *alloc_parse_state();
  186. static unsigned long scan_oct(const char *start, int len, int *retlen);
  187. static unsigned long scan_hex(const char *start, int len, int *retlen);
  188. static void reset_block(rb_parse_state *parse_state);
  189. static NODE *extract_block_vars(rb_parse_state *parse_state, NODE* node, var_table vars);
  190. #define RE_OPTION_ONCE 0x80
  191. #define RE_OPTION_IGNORECASE (1L)
  192. #define RE_OPTION_EXTENDED (RE_OPTION_IGNORECASE<<1)
  193. #define RE_OPTION_MULTILINE (RE_OPTION_EXTENDED<<1)
  194. #define RE_OPTION_SINGLELINE (RE_OPTION_MULTILINE<<1)
  195. #define RE_OPTION_LONGEST (RE_OPTION_SINGLELINE<<1)
  196. #define RE_MAY_IGNORECASE (RE_OPTION_LONGEST<<1)
  197. #define RE_OPTIMIZE_ANCHOR (RE_MAY_IGNORECASE<<1)
  198. #define RE_OPTIMIZE_EXACTN (RE_OPTIMIZE_ANCHOR<<1)
  199. #define RE_OPTIMIZE_NO_BM (RE_OPTIMIZE_EXACTN<<1)
  200. #define RE_OPTIMIZE_BMATCH (RE_OPTIMIZE_NO_BM<<1)
  201. #define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
  202. #define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */
  203. #define SIGN_EXTEND(x,n) (((1<<((n)-1))^((x)&~(~0<<(n))))-(1<<((n)-1)))
  204. #define nd_func u1.id
  205. #if SIZEOF_SHORT != 2
  206. #define nd_term(node) SIGN_EXTEND((node)->u2.id, (CHAR_BIT*2))
  207. #else
  208. #define nd_term(node) ((signed short)(node)->u2.id)
  209. #endif
  210. #define nd_paren(node) (char)((node)->u2.id >> (CHAR_BIT*2))
  211. #define nd_nest u3.id
  212. /* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150,
  213. for instance). This is too low for Ruby to parse some files, such as
  214. date/format.rb, therefore bump the value up to at least Bison's default. */
  215. #ifdef OLD_YACC
  216. #ifndef YYMAXDEPTH
  217. #define YYMAXDEPTH 10000
  218. #endif
  219. #endif
  220. #define vps ((rb_parse_state*)parse_state)
  221. %}
  222. %pure-parser
  223. %union {
  224. NODE *node;
  225. QUID id;
  226. int num;
  227. var_table vars;
  228. }
  229. %token kCLASS
  230. kMODULE
  231. kDEF
  232. kUNDEF
  233. kBEGIN
  234. kRESCUE
  235. kENSURE
  236. kEND
  237. kIF
  238. kUNLESS
  239. kTHEN
  240. kELSIF
  241. kELSE
  242. kCASE
  243. kWHEN
  244. kWHILE
  245. kUNTIL
  246. kFOR
  247. kBREAK
  248. kNEXT
  249. kREDO
  250. kRETRY
  251. kIN
  252. kDO
  253. kDO_COND
  254. kDO_BLOCK
  255. kRETURN
  256. kYIELD
  257. kSUPER
  258. kSELF
  259. kNIL
  260. kTRUE
  261. kFALSE
  262. kAND
  263. kOR
  264. kNOT
  265. kIF_MOD
  266. kUNLESS_MOD
  267. kWHILE_MOD
  268. kUNTIL_MOD
  269. kRESCUE_MOD
  270. kALIAS
  271. kDEFINED
  272. klBEGIN
  273. klEND
  274. k__LINE__
  275. k__FILE__
  276. %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tXSTRING_BEG
  277. %token <node> tINTEGER tFLOAT tSTRING_CONTENT
  278. %token <node> tNTH_REF tBACK_REF
  279. %token <num> tREGEXP_END
  280. %type <node> singleton strings string string1 xstring regexp
  281. %type <node> string_contents xstring_contents string_content
  282. %type <node> words qwords word_list qword_list word
  283. %type <node> literal numeric dsym cpath
  284. %type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
  285. %type <node> expr_value arg_value primary_value
  286. %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
  287. %type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args
  288. %type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
  289. %type <node> mrhs superclass block_call block_command
  290. %type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
  291. %type <node> assoc_list assocs assoc undef_list backref string_dvar
  292. %type <node> block_var opt_block_var brace_block cmd_brace_block do_block lhs none fitem
  293. %type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
  294. %type <id> fsym variable sym symbol operation operation2 operation3
  295. %type <id> cname fname op f_rest_arg
  296. %type <num> f_norm_arg f_arg
  297. %token tUPLUS /* unary+ */
  298. %token tUMINUS /* unary- */
  299. %token tUBS /* unary\ */
  300. %token tPOW /* ** */
  301. %token tCMP /* <=> */
  302. %token tEQ /* == */
  303. %token tEQQ /* === */
  304. %token tNEQ /* != */
  305. %token tGEQ /* >= */
  306. %token tLEQ /* <= */
  307. %token tANDOP tOROP /* && and || */
  308. %token tMATCH tNMATCH /* =~ and !~ */
  309. %token tDOT2 tDOT3 /* .. and ... */
  310. %token tAREF tASET /* [] and []= */
  311. %token tLSHFT tRSHFT /* << and >> */
  312. %token tCOLON2 /* :: */
  313. %token tCOLON3 /* :: at EXPR_BEG */
  314. %token <id> tOP_ASGN /* +=, -= etc. */
  315. %token tASSOC /* => */
  316. %token tLPAREN /* ( */
  317. %token tLPAREN_ARG /* ( */
  318. %token tRPAREN /* ) */
  319. %token tLBRACK /* [ */
  320. %token tLBRACE /* { */
  321. %token tLBRACE_ARG /* { */
  322. %token tSTAR /* * */
  323. %token tAMPER /* & */
  324. %token tSYMBEG tSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
  325. %token tSTRING_DBEG tSTRING_DVAR tSTRING_END
  326. /*
  327. * precedence table
  328. */
  329. %nonassoc tLOWEST
  330. %nonassoc tLBRACE_ARG
  331. %nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
  332. %left kOR kAND
  333. %right kNOT
  334. %nonassoc kDEFINED
  335. %right '=' tOP_ASGN
  336. %left kRESCUE_MOD
  337. %right '?' ':'
  338. %nonassoc tDOT2 tDOT3
  339. %left tOROP
  340. %left tANDOP
  341. %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
  342. %left '>' tGEQ '<' tLEQ
  343. %left '|' '^'
  344. %left '&'
  345. %left tLSHFT tRSHFT
  346. %left '+' '-'
  347. %left '*' '/' '%'
  348. %right tUMINUS_NUM tUMINUS
  349. %right tPOW
  350. %right '!' '~' tUPLUS
  351. %token tLAST_TOKEN
  352. %%
  353. program : {
  354. vps->lex_state = EXPR_BEG;
  355. vps->variables = new LocalState(0);
  356. class_nest = 0;
  357. }
  358. compstmt
  359. {
  360. if ($2 && !compile_for_eval) {
  361. /* last expression should not be void */
  362. if (nd_type($2) != NODE_BLOCK) void_expr($2);
  363. else {
  364. NODE *node = $2;
  365. while (node->nd_next) {
  366. node = node->nd_next;
  367. }
  368. void_expr(node->nd_head);
  369. }
  370. }
  371. vps->top = block_append(vps, vps->top, $2);
  372. class_nest = 0;
  373. }
  374. ;
  375. bodystmt : compstmt
  376. opt_rescue
  377. opt_else
  378. opt_ensure
  379. {
  380. $$ = $1;
  381. if ($2) {
  382. $$ = NEW_RESCUE($1, $2, $3);
  383. }
  384. else if ($3) {
  385. rb_warn("else without rescue is useless");
  386. $$ = block_append(vps, $$, $3);
  387. }
  388. if ($4) {
  389. $$ = NEW_ENSURE($$, $4);
  390. }
  391. fixpos($$, $1);
  392. }
  393. ;
  394. compstmt : stmts opt_terms
  395. {
  396. void_stmts($1, vps);
  397. $$ = $1;
  398. }
  399. ;
  400. stmts : none
  401. | stmt
  402. {
  403. $$ = newline_node(vps, $1);
  404. }
  405. | stmts terms stmt
  406. {
  407. $$ = block_append(vps, $1, newline_node(vps, $3));
  408. }
  409. | error stmt
  410. {
  411. $$ = remove_begin($2, vps);
  412. }
  413. ;
  414. stmt : kALIAS fitem {vps->lex_state = EXPR_FNAME;} fitem
  415. {
  416. $$ = NEW_ALIAS($2, $4);
  417. }
  418. | kALIAS tGVAR tGVAR
  419. {
  420. $$ = NEW_VALIAS($2, $3);
  421. }
  422. | kALIAS tGVAR tBACK_REF
  423. {
  424. char buf[3];
  425. snprintf(buf, sizeof(buf), "$%c", (char)$3->nd_nth);
  426. $$ = NEW_VALIAS($2, rb_intern(buf));
  427. }
  428. | kALIAS tGVAR tNTH_REF
  429. {
  430. yyerror("can't make alias for the number variables");
  431. $$ = 0;
  432. }
  433. | kUNDEF undef_list
  434. {
  435. $$ = $2;
  436. }
  437. | stmt kIF_MOD expr_value
  438. {
  439. $$ = NEW_IF(cond($3, vps), remove_begin($1, vps), 0);
  440. fixpos($$, $3);
  441. if (cond_negative(&$$->nd_cond)) {
  442. $$->nd_else = $$->nd_body;
  443. $$->nd_body = 0;
  444. }
  445. }
  446. | stmt kUNLESS_MOD expr_value
  447. {
  448. $$ = NEW_UNLESS(cond($3, vps), remove_begin($1, vps), 0);
  449. fixpos($$, $3);
  450. if (cond_negative(&$$->nd_cond)) {
  451. $$->nd_body = $$->nd_else;
  452. $$->nd_else = 0;
  453. }
  454. }
  455. | stmt kWHILE_MOD expr_value
  456. {
  457. if ($1 && nd_type($1) == NODE_BEGIN) {
  458. $$ = NEW_WHILE(cond($3, vps), $1->nd_body, 0);
  459. }
  460. else {
  461. $$ = NEW_WHILE(cond($3, vps), $1, 1);
  462. }
  463. if (cond_negative(&$$->nd_cond)) {
  464. nd_set_type($$, NODE_UNTIL);
  465. }
  466. }
  467. | stmt kUNTIL_MOD expr_value
  468. {
  469. if ($1 && nd_type($1) == NODE_BEGIN) {
  470. $$ = NEW_UNTIL(cond($3, vps), $1->nd_body, 0);
  471. }
  472. else {
  473. $$ = NEW_UNTIL(cond($3, vps), $1, 1);
  474. }
  475. if (cond_negative(&$$->nd_cond)) {
  476. nd_set_type($$, NODE_WHILE);
  477. }
  478. }
  479. | stmt kRESCUE_MOD stmt
  480. {
  481. NODE *resq = NEW_RESBODY(0, remove_begin($3, vps), 0);
  482. $$ = NEW_RESCUE(remove_begin($1, vps), resq, 0);
  483. }
  484. | klBEGIN
  485. {
  486. if (in_def || in_single) {
  487. yyerror("BEGIN in method");
  488. }
  489. local_push(0);
  490. }
  491. '{' compstmt '}'
  492. {
  493. /*
  494. ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
  495. NEW_PREEXE($4));
  496. */
  497. local_pop();
  498. $$ = 0;
  499. }
  500. | klEND '{' compstmt '}'
  501. {
  502. if (in_def || in_single) {
  503. rb_warn("END in method; use at_exit");
  504. }
  505. $$ = NEW_ITER(0, NEW_POSTEXE(), $3);
  506. }
  507. | lhs '=' command_call
  508. {
  509. $$ = node_assign($1, $3, vps);
  510. }
  511. | mlhs '=' command_call
  512. {
  513. value_expr($3);
  514. $1->nd_value = ($1->nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
  515. $$ = $1;
  516. }
  517. | var_lhs tOP_ASGN command_call
  518. {
  519. value_expr($3);
  520. if ($1) {
  521. QUID vid = $1->nd_vid;
  522. if ($2 == tOROP) {
  523. $1->nd_value = $3;
  524. $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
  525. if (is_asgn_or_id(vid)) {
  526. $$->nd_aid = vid;
  527. }
  528. }
  529. else if ($2 == tANDOP) {
  530. $1->nd_value = $3;
  531. $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
  532. }
  533. else {
  534. $$ = $1;
  535. $$->nd_value = call_op(gettable(vid),$2,1,$3, vps);
  536. }
  537. }
  538. else {
  539. $$ = 0;
  540. }
  541. }
  542. | primary_value '[' aref_args ']' tOP_ASGN command_call
  543. {
  544. NODE *args;
  545. value_expr($6);
  546. if (!$3) $3 = NEW_ZARRAY();
  547. args = arg_concat(vps, $6, $3);
  548. if ($5 == tOROP) {
  549. $5 = 0;
  550. }
  551. else if ($5 == tANDOP) {
  552. $5 = 1;
  553. }
  554. $$ = NEW_OP_ASGN1($1, $5, args);
  555. fixpos($$, $1);
  556. }
  557. | primary_value '.' tIDENTIFIER tOP_ASGN command_call
  558. {
  559. value_expr($5);
  560. if ($4 == tOROP) {
  561. $4 = 0;
  562. }
  563. else if ($4 == tANDOP) {
  564. $4 = 1;
  565. }
  566. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  567. fixpos($$, $1);
  568. }
  569. | primary_value '.' tCONSTANT tOP_ASGN command_call
  570. {
  571. value_expr($5);
  572. if ($4 == tOROP) {
  573. $4 = 0;
  574. }
  575. else if ($4 == tANDOP) {
  576. $4 = 1;
  577. }
  578. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  579. fixpos($$, $1);
  580. }
  581. | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
  582. {
  583. value_expr($5);
  584. if ($4 == tOROP) {
  585. $4 = 0;
  586. }
  587. else if ($4 == tANDOP) {
  588. $4 = 1;
  589. }
  590. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  591. fixpos($$, $1);
  592. }
  593. | backref tOP_ASGN command_call
  594. {
  595. rb_backref_error($1, vps);
  596. $$ = 0;
  597. }
  598. | lhs '=' mrhs
  599. {
  600. $$ = node_assign($1, NEW_SVALUE($3), vps);
  601. }
  602. | mlhs '=' arg_value
  603. {
  604. $1->nd_value = ($1->nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
  605. $$ = $1;
  606. }
  607. | mlhs '=' mrhs
  608. {
  609. $1->nd_value = $3;
  610. $$ = $1;
  611. }
  612. | expr
  613. ;
  614. expr : command_call
  615. | expr kAND expr
  616. {
  617. $$ = logop(NODE_AND, $1, $3, vps);
  618. }
  619. | expr kOR expr
  620. {
  621. $$ = logop(NODE_OR, $1, $3, vps);
  622. }
  623. | kNOT expr
  624. {
  625. $$ = NEW_NOT(cond($2, vps));
  626. }
  627. | '!' command_call
  628. {
  629. $$ = NEW_NOT(cond($2, vps));
  630. }
  631. | arg
  632. ;
  633. expr_value : expr
  634. {
  635. value_expr($$);
  636. $$ = $1;
  637. }
  638. ;
  639. command_call : command
  640. | block_command
  641. | kRETURN call_args
  642. {
  643. $$ = NEW_RETURN(ret_args(vps, $2));
  644. }
  645. | kBREAK call_args
  646. {
  647. $$ = NEW_BREAK(ret_args(vps, $2));
  648. }
  649. | kNEXT call_args
  650. {
  651. $$ = NEW_NEXT(ret_args(vps, $2));
  652. }
  653. ;
  654. block_command : block_call
  655. | block_call '.' operation2 command_args
  656. {
  657. $$ = new_call(vps, $1, $3, $4);
  658. }
  659. | block_call tCOLON2 operation2 command_args
  660. {
  661. $$ = new_call(vps, $1, $3, $4);
  662. }
  663. ;
  664. cmd_brace_block : tLBRACE_ARG
  665. {
  666. $<num>1 = ruby_sourceline;
  667. reset_block(vps);
  668. }
  669. opt_block_var { $<vars>$ = vps->variables->block_vars; }
  670. compstmt
  671. '}'
  672. {
  673. $$ = NEW_ITER($3, 0, extract_block_vars(vps, $5, $<vars>4));
  674. nd_set_line($$, $<num>1);
  675. }
  676. ;
  677. command : operation command_args %prec tLOWEST
  678. {
  679. $$ = new_fcall(vps, $1, $2);
  680. fixpos($$, $2);
  681. }
  682. | operation command_args cmd_brace_block
  683. {
  684. $$ = new_fcall(vps, $1, $2);
  685. if ($3) {
  686. if (nd_type($$) == NODE_BLOCK_PASS) {
  687. rb_compile_error(vps, "both block arg and actual block given");
  688. }
  689. $3->nd_iter = $$;
  690. $$ = $3;
  691. }
  692. fixpos($$, $2);
  693. }
  694. | primary_value '.' operation2 command_args %prec tLOWEST
  695. {
  696. $$ = new_call(vps, $1, $3, $4);
  697. fixpos($$, $1);
  698. }
  699. | primary_value '.' operation2 command_args cmd_brace_block
  700. {
  701. $$ = new_call(vps, $1, $3, $4);
  702. if ($5) {
  703. if (nd_type($$) == NODE_BLOCK_PASS) {
  704. rb_compile_error(vps, "both block arg and actual block given");
  705. }
  706. $5->nd_iter = $$;
  707. $$ = $5;
  708. }
  709. fixpos($$, $1);
  710. }
  711. | primary_value tCOLON2 operation2 command_args %prec tLOWEST
  712. {
  713. $$ = new_call(vps, $1, $3, $4);
  714. fixpos($$, $1);
  715. }
  716. | primary_value tCOLON2 operation2 command_args cmd_brace_block
  717. {
  718. $$ = new_call(vps, $1, $3, $4);
  719. if ($5) {
  720. if (nd_type($$) == NODE_BLOCK_PASS) {
  721. rb_compile_error(vps, "both block arg and actual block given");
  722. }
  723. $5->nd_iter = $$;
  724. $$ = $5;
  725. }
  726. fixpos($$, $1);
  727. }
  728. | kSUPER command_args
  729. {
  730. $$ = new_super(vps, $2);
  731. fixpos($$, $2);
  732. }
  733. | kYIELD command_args
  734. {
  735. $$ = new_yield(vps, $2);
  736. fixpos($$, $2);
  737. }
  738. ;
  739. mlhs : mlhs_basic
  740. | tLPAREN mlhs_entry ')'
  741. {
  742. $$ = $2;
  743. }
  744. ;
  745. mlhs_entry : mlhs_basic
  746. | tLPAREN mlhs_entry ')'
  747. {
  748. $$ = NEW_MASGN(NEW_LIST($2), 0);
  749. }
  750. ;
  751. mlhs_basic : mlhs_head
  752. {
  753. $$ = NEW_MASGN($1, 0);
  754. }
  755. | mlhs_head mlhs_item
  756. {
  757. $$ = NEW_MASGN(list_append(vps, $1,$2), 0);
  758. }
  759. | mlhs_head tSTAR mlhs_node
  760. {
  761. $$ = NEW_MASGN($1, $3);
  762. }
  763. | mlhs_head tSTAR
  764. {
  765. $$ = NEW_MASGN($1, -1);
  766. }
  767. | tSTAR mlhs_node
  768. {
  769. $$ = NEW_MASGN(0, $2);
  770. }
  771. | tSTAR
  772. {
  773. $$ = NEW_MASGN(0, -1);
  774. }
  775. ;
  776. mlhs_item : mlhs_node
  777. | tLPAREN mlhs_entry ')'
  778. {
  779. $$ = $2;
  780. }
  781. ;
  782. mlhs_head : mlhs_item ','
  783. {
  784. $$ = NEW_LIST($1);
  785. }
  786. | mlhs_head mlhs_item ','
  787. {
  788. $$ = list_append(vps, $1, $2);
  789. }
  790. ;
  791. mlhs_node : variable
  792. {
  793. $$ = assignable($1, 0, vps);
  794. }
  795. | primary_value '[' aref_args ']'
  796. {
  797. $$ = aryset($1, $3, vps);
  798. }
  799. | primary_value '.' tIDENTIFIER
  800. {
  801. $$ = attrset($1, $3, vps);
  802. }
  803. | primary_value tCOLON2 tIDENTIFIER
  804. {
  805. $$ = attrset($1, $3, vps);
  806. }
  807. | primary_value '.' tCONSTANT
  808. {
  809. $$ = attrset($1, $3, vps);
  810. }
  811. | primary_value tCOLON2 tCONSTANT
  812. {
  813. if (in_def || in_single)
  814. yyerror("dynamic constant assignment");
  815. $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
  816. }
  817. | tCOLON3 tCONSTANT
  818. {
  819. if (in_def || in_single)
  820. yyerror("dynamic constant assignment");
  821. $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
  822. }
  823. | backref
  824. {
  825. rb_backref_error($1, vps);
  826. $$ = 0;
  827. }
  828. ;
  829. lhs : variable
  830. {
  831. $$ = assignable($1, 0, vps);
  832. }
  833. | primary_value '[' aref_args ']'
  834. {
  835. $$ = aryset($1, $3, vps);
  836. }
  837. | primary_value '.' tIDENTIFIER
  838. {
  839. $$ = attrset($1, $3, vps);
  840. }
  841. | primary_value tCOLON2 tIDENTIFIER
  842. {
  843. $$ = attrset($1, $3, vps);
  844. }
  845. | primary_value '.' tCONSTANT
  846. {
  847. $$ = attrset($1, $3, vps);
  848. }
  849. | primary_value tCOLON2 tCONSTANT
  850. {
  851. if (in_def || in_single)
  852. yyerror("dynamic constant assignment");
  853. $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
  854. }
  855. | tCOLON3 tCONSTANT
  856. {
  857. if (in_def || in_single)
  858. yyerror("dynamic constant assignment");
  859. $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
  860. }
  861. | backref
  862. {
  863. rb_backref_error($1, vps);
  864. $$ = 0;
  865. }
  866. ;
  867. cname : tIDENTIFIER
  868. {
  869. yyerror("class/module name must be CONSTANT");
  870. }
  871. | tCONSTANT
  872. ;
  873. cpath : tCOLON3 cname
  874. {
  875. $$ = NEW_COLON3($2);
  876. }
  877. | cname
  878. {
  879. $$ = NEW_COLON2(0, $$);
  880. }
  881. | primary_value tCOLON2 cname
  882. {
  883. $$ = NEW_COLON2($1, $3);
  884. }
  885. ;
  886. fname : tIDENTIFIER
  887. | tCONSTANT
  888. | tFID
  889. | op
  890. {
  891. vps->lex_state = EXPR_END;
  892. $$ = convert_op($1);
  893. }
  894. | reswords
  895. {
  896. vps->lex_state = EXPR_END;
  897. $$ = $<id>1;
  898. }
  899. ;
  900. fsym : fname
  901. | symbol
  902. ;
  903. fitem : fsym
  904. {
  905. $$ = NEW_LIT(ID2SYM($1));
  906. }
  907. | dsym
  908. ;
  909. undef_list : fitem
  910. {
  911. $$ = NEW_UNDEF($1);
  912. }
  913. | undef_list ',' {vps->lex_state = EXPR_FNAME;} fitem
  914. {
  915. $$ = block_append(vps, $1, NEW_UNDEF($4));
  916. }
  917. ;
  918. op : '|' { $$ = '|'; }
  919. | '^' { $$ = '^'; }
  920. | '&' { $$ = '&'; }
  921. | tCMP { $$ = tCMP; }
  922. | tEQ { $$ = tEQ; }
  923. | tEQQ { $$ = tEQQ; }
  924. | tMATCH { $$ = tMATCH; }
  925. | '>' { $$ = '>'; }
  926. | tGEQ { $$ = tGEQ; }
  927. | '<' { $$ = '<'; }
  928. | tLEQ { $$ = tLEQ; }
  929. | tLSHFT { $$ = tLSHFT; }
  930. | tRSHFT { $$ = tRSHFT; }
  931. | '+' { $$ = '+'; }
  932. | '-' { $$ = '-'; }
  933. | '*' { $$ = '*'; }
  934. | tSTAR { $$ = '*'; }
  935. | '/' { $$ = '/'; }
  936. | '%' { $$ = '%'; }
  937. | tPOW { $$ = tPOW; }
  938. | '~' { $$ = '~'; }
  939. | tUPLUS { $$ = tUPLUS; }
  940. | tUMINUS { $$ = tUMINUS; }
  941. | tAREF { $$ = tAREF; }
  942. | tASET { $$ = tASET; }
  943. | '`' { $$ = '`'; }
  944. ;
  945. reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
  946. | kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF
  947. | kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
  948. | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
  949. | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER
  950. | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
  951. | kIF_MOD | kUNLESS_MOD | kWHILE_MOD | kUNTIL_MOD | kRESCUE_MOD
  952. ;
  953. arg : lhs '=' arg
  954. {
  955. $$ = node_assign($1, $3, vps);
  956. }
  957. | lhs '=' arg kRESCUE_MOD arg
  958. {
  959. $$ = node_assign($1, NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0), vps);
  960. }
  961. | var_lhs tOP_ASGN arg
  962. {
  963. value_expr($3);
  964. if ($1) {
  965. QUID vid = $1->nd_vid;
  966. if ($2 == tOROP) {
  967. $1->nd_value = $3;
  968. $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
  969. if (is_asgn_or_id(vid)) {
  970. $$->nd_aid = vid;
  971. }
  972. }
  973. else if ($2 == tANDOP) {
  974. $1->nd_value = $3;
  975. $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
  976. }
  977. else {
  978. $$ = $1;
  979. $$->nd_value = call_op(gettable(vid),$2,1,$3, vps);
  980. }
  981. }
  982. else {
  983. $$ = 0;
  984. }
  985. }
  986. | primary_value '[' aref_args ']' tOP_ASGN arg
  987. {
  988. NODE *args;
  989. value_expr($6);
  990. if (!$3) $3 = NEW_ZARRAY();
  991. args = arg_concat(vps, $6, $3);
  992. if ($5 == tOROP) {
  993. $5 = 0;
  994. }
  995. else if ($5 == tANDOP) {
  996. $5 = 1;
  997. }
  998. $$ = NEW_OP_ASGN1($1, $5, args);
  999. fixpos($$, $1);
  1000. }
  1001. | primary_value '.' tIDENTIFIER tOP_ASGN arg
  1002. {
  1003. value_expr($5);
  1004. if ($4 == tOROP) {
  1005. $4 = 0;
  1006. }
  1007. else if ($4 == tANDOP) {
  1008. $4 = 1;
  1009. }
  1010. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  1011. fixpos($$, $1);
  1012. }
  1013. | primary_value '.' tCONSTANT tOP_ASGN arg
  1014. {
  1015. value_expr($5);
  1016. if ($4 == tOROP) {
  1017. $4 = 0;
  1018. }
  1019. else if ($4 == tANDOP) {
  1020. $4 = 1;
  1021. }
  1022. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  1023. fixpos($$, $1);
  1024. }
  1025. | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
  1026. {
  1027. value_expr($5);
  1028. if ($4 == tOROP) {
  1029. $4 = 0;
  1030. }
  1031. else if ($4 == tANDOP) {
  1032. $4 = 1;
  1033. }
  1034. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  1035. fixpos($$, $1);
  1036. }
  1037. | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
  1038. {
  1039. yyerror("constant re-assignment");
  1040. $$ = 0;
  1041. }
  1042. | tCOLON3 tCONSTANT tOP_ASGN arg
  1043. {
  1044. yyerror("constant re-assignment");
  1045. $$ = 0;
  1046. }
  1047. | backref tOP_ASGN arg
  1048. {
  1049. rb_backref_error($1, vps);
  1050. $$ = 0;
  1051. }
  1052. | arg tDOT2 arg
  1053. {
  1054. value_expr($1);
  1055. value_expr($3);
  1056. $$ = NEW_DOT2($1, $3);
  1057. }
  1058. | arg tDOT3 arg
  1059. {
  1060. value_expr($1);
  1061. value_expr($3);
  1062. $$ = NEW_DOT3($1, $3);
  1063. }
  1064. | arg '+' arg
  1065. {
  1066. $$ = call_op($1, '+', 1, $3, vps);
  1067. }
  1068. | arg '-' arg
  1069. {
  1070. $$ = call_op($1, '-', 1, $3, vps);
  1071. }
  1072. | arg '*' arg
  1073. {
  1074. $$ = call_op($1, '*', 1, $3, vps);
  1075. }
  1076. | arg '/' arg
  1077. {
  1078. $$ = call_op($1, '/', 1, $3, vps);
  1079. }
  1080. | arg '%' arg
  1081. {
  1082. $$ = call_op($1, '%', 1, $3, vps);
  1083. }
  1084. | arg tPOW arg
  1085. {
  1086. $$ = call_op($1, tPOW, 1, $3, vps);
  1087. }
  1088. | tUMINUS_NUM tINTEGER tPOW arg
  1089. {
  1090. $$ = call_op(call_op($2, tPOW, 1, $4, vps), tUMINUS, 0, 0, vps);
  1091. }
  1092. | tUMINUS_NUM tFLOAT tPOW arg
  1093. {
  1094. $$ = call_op(call_op($2, tPOW, 1, $4, vps), tUMINUS, 0, 0, vps);
  1095. }
  1096. | tUPLUS arg
  1097. {
  1098. if ($2 && nd_type($2) == NODE_LIT) {
  1099. $$ = $2;
  1100. }
  1101. else {
  1102. $$ = call_op($2, tUPLUS, 0, 0, vps);
  1103. }
  1104. }
  1105. | tUMINUS arg
  1106. {
  1107. $$ = call_op($2, tUMINUS, 0, 0, vps);
  1108. }
  1109. | arg '|' arg
  1110. {
  1111. $$ = call_op($1, '|', 1, $3, vps);
  1112. }
  1113. | arg '^' arg
  1114. {
  1115. $$ = call_op($1, '^', 1, $3, vps);
  1116. }
  1117. | arg '&' arg
  1118. {
  1119. $$ = call_op($1, '&', 1, $3, vps);
  1120. }
  1121. | arg tCMP arg
  1122. {
  1123. $$ = call_op($1, tCMP, 1, $3, vps);
  1124. }
  1125. | arg '>' arg
  1126. {
  1127. $$ = call_op($1, '>', 1, $3, vps);
  1128. }
  1129. | arg tGEQ arg
  1130. {
  1131. $$ = call_op($1, tGEQ, 1, $3, vps);
  1132. }
  1133. | arg '<' arg
  1134. {
  1135. $$ = call_op($1, '<', 1, $3, vps);
  1136. }
  1137. | arg tLEQ arg
  1138. {
  1139. $$ = call_op($1, tLEQ, 1, $3, vps);
  1140. }
  1141. | arg tEQ arg
  1142. {
  1143. $$ = call_op($1, tEQ, 1, $3, vps);
  1144. }
  1145. | arg tEQQ arg
  1146. {
  1147. $$ = call_op($1, tEQQ, 1, $3, vps);
  1148. }
  1149. | arg tNEQ arg
  1150. {
  1151. $$ = NEW_NOT(call_op($1, tEQ, 1, $3, vps));
  1152. }
  1153. | arg tMATCH arg
  1154. {
  1155. $$ = match_gen($1, $3, vps);
  1156. }
  1157. | arg tNMATCH arg
  1158. {
  1159. $$ = NEW_NOT(match_gen($1, $3, vps));
  1160. }
  1161. | '!' arg
  1162. {
  1163. $$ = NEW_NOT(cond($2, vps));
  1164. }
  1165. | '~' arg
  1166. {
  1167. $$ = call_op($2, '~', 0, 0, vps);
  1168. }
  1169. | arg tLSHFT arg
  1170. {
  1171. $$ = call_op($1, tLSHFT, 1, $3, vps);
  1172. }
  1173. | arg tRSHFT arg
  1174. {
  1175. $$ = call_op($1, tRSHFT, 1, $3, vps);
  1176. }
  1177. | arg tANDOP arg
  1178. {
  1179. $$ = logop(NODE_AND, $1, $3, vps);
  1180. }
  1181. | arg tOROP arg
  1182. {
  1183. $$ = logop(NODE_OR, $1, $3, vps);
  1184. }
  1185. | kDEFINED opt_nl {vps->in_defined = 1;} arg
  1186. {
  1187. vps->in_defined = 0;
  1188. $$ = NEW_DEFINED($4);
  1189. }
  1190. | arg '?' {vps->ternary_colon++;} arg ':' arg
  1191. {
  1192. $$ = NEW_IF(cond($1, vps), $4, $6);
  1193. fixpos($$, $1);
  1194. vps->ternary_colon--;
  1195. }
  1196. | primary
  1197. {
  1198. $$ = $1;
  1199. }
  1200. ;
  1201. arg_value : arg
  1202. {
  1203. value_expr($1);
  1204. $$ = $1;
  1205. }
  1206. ;
  1207. aref_args : none
  1208. | command opt_nl
  1209. {
  1210. rb_warn("parenthesize argument(s) for future version");
  1211. $$ = NEW_LIST($1);
  1212. }
  1213. | args trailer
  1214. {
  1215. $$ = $1;
  1216. }
  1217. | args ',' tSTAR arg opt_nl
  1218. {
  1219. value_expr($4);
  1220. $$ = arg_concat(vps, $1, $4);
  1221. }
  1222. | assocs trailer
  1223. {
  1224. $$ = NEW_LIST(NEW_HASH($1));
  1225. }
  1226. | tSTAR arg opt_nl
  1227. {
  1228. value_expr($2);
  1229. $$ = NEW_NEWLINE(NEW_SPLAT($2));
  1230. }
  1231. ;
  1232. paren_args : '(' none ')'
  1233. {
  1234. $$ = $2;
  1235. }
  1236. | '(' call_args opt_nl ')'
  1237. {
  1238. $$ = $2;
  1239. }
  1240. | '(' block_call opt_nl ')'
  1241. {
  1242. rb_warn("parenthesize argument for future version");
  1243. $$ = NEW_LIST($2);
  1244. }
  1245. | '(' args ',' block_call opt_nl ')'
  1246. {
  1247. rb_warn("parenthesize argument for future version");
  1248. $$ = list_append(vps, $2, $4);
  1249. }
  1250. ;
  1251. opt_paren_args : none
  1252. | paren_args
  1253. ;
  1254. call_args : command
  1255. {
  1256. rb_warn("parenthesize argument(s) for future version");
  1257. $$ = NEW_LIST($1);
  1258. }
  1259. | args opt_block_arg
  1260. {
  1261. $$ = arg_blk_pass($1, $2);
  1262. }
  1263. | args ',' tSTAR arg_value opt_block_arg
  1264. {
  1265. $$ = arg_concat(vps, $1, $4);
  1266. $$ = arg_blk_pass($$, $5);
  1267. }
  1268. | assocs opt_block_arg
  1269. {
  1270. $$ = NEW_LIST(NEW_HASH($1));
  1271. $$ = arg_blk_pass($$, $2);
  1272. }
  1273. | assocs ',' tSTAR arg_value opt_block_arg
  1274. {
  1275. $$ = arg_concat(vps, NEW_LIST(NEW_HASH($1)), $4);
  1276. $$ = arg_blk_pass($$, $5);
  1277. }
  1278. | args ',' assocs opt_block_arg
  1279. {
  1280. $$ = list_append(vps, $1, NEW_HASH($3));
  1281. $$ = arg_blk_pass($$, $4);
  1282. }
  1283. | args ',' assocs ',' tSTAR arg opt_block_arg
  1284. {
  1285. value_expr($6);
  1286. $$ = arg_concat(vps, list_append(vps, $1, NEW_HASH($3)), $6);
  1287. $$ = arg_blk_pass($$, $7);
  1288. }
  1289. | tSTAR arg_value opt_block_arg
  1290. {
  1291. $$ = arg_blk_pass(NEW_SPLAT($2), $3);
  1292. }
  1293. | block_arg
  1294. ;
  1295. call_args2 : arg_value ',' args opt_block_arg
  1296. {
  1297. $$ = arg_blk_pass(list_concat(NEW_LIST($1),$3), $4);
  1298. }
  1299. | arg_value ',' block_arg
  1300. {
  1301. $$ = arg_blk_pass($1, $3);
  1302. }
  1303. | arg_value ',' tSTAR arg_value opt_block_arg
  1304. {
  1305. $$ = arg_concat(vps, NEW_LIST($1), $4);
  1306. $$ = arg_blk_pass($$, $5);
  1307. }
  1308. | arg_value ',' args ',' tSTAR arg_value opt_block_arg
  1309. {
  1310. $$ = arg_concat(vps, list_concat(NEW_LIST($1),$3), $6);
  1311. $$ = arg_blk_pass($$, $7);
  1312. }
  1313. | assocs opt_block_arg
  1314. {
  1315. $$ = NEW_LIST(NEW_HASH($1));
  1316. $$ = arg_blk_pass($$, $2);
  1317. }
  1318. | assocs ',' tSTAR arg_value opt_block_arg
  1319. {
  1320. $$ = arg_concat(vps, NEW_LIST(NEW_HASH($1)), $4);
  1321. $$ = arg_blk_pass($$, $5);
  1322. }
  1323. | arg_value ',' assocs opt_block_arg
  1324. {
  1325. $$ = list_append(vps, NEW_LIST($1), NEW_HASH($3));
  1326. $$ = arg_blk_pass($$, $4);
  1327. }
  1328. | arg_value ',' args ',' assocs opt_block_arg
  1329. {
  1330. $$ = list_append(vps, list_concat(NEW_LIST($1),$3), NEW_HASH($5));
  1331. $$ = arg_blk_pass($$, $6);
  1332. }
  1333. | arg_value ',' assocs ',' tSTAR arg_value opt_block_arg
  1334. {
  1335. $$ = arg_concat(vps, list_append(vps, NEW_LIST($1), NEW_HASH($3)), $6);
  1336. $$ = arg_blk_pass($$, $7);
  1337. }
  1338. | arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg
  1339. {
  1340. $$ = arg_concat(vps, list_append(vps,
  1341. list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8);
  1342. $$ = arg_blk_pass($$, $9);
  1343. }
  1344. | tSTAR arg_value opt_block_arg
  1345. {
  1346. $$ = arg_blk_pass(NEW_SPLAT($2), $3);
  1347. }
  1348. | block_arg
  1349. ;
  1350. command_args : {
  1351. $<num>$ = vps->cmdarg_stack;
  1352. CMDARG_PUSH(1);
  1353. }
  1354. open_args
  1355. {
  1356. /* CMDARG_POP() */
  1357. vps->cmdarg_stack = $<num

Large files files are truncated, but you can click here to view the full file