PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/vm/parser/grammar.y

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

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