PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ext/melbourne/grammar18.y

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

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