PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/ext/melbourne/grammar18.y

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

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