PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/ext/melbourne/grammar18.y

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

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