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

/lib/ext/melbourne/grammar.y

https://github.com/wycats/rubinius
Happy | 6013 lines | 5491 code | 522 blank | 0 comment | 0 complexity | a07b041dd808f5734d64cee7dc8fd238 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause, LGPL-2.1

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

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