1/**********************************************************************
6 created at: Fri May 28 18:02:42 JST 1993
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10**********************************************************************/
15# error needs pure parser
18#define YYERROR_VERBOSE 1
19#define YYSTACK_USE_ALLOCA 0
23# include RUBY_EXTCONF_H
26#include "ruby/internal/config.h"
30#ifdef UNIVERSAL_PARSER
32#include "internal/ruby_parser.h"
33#include "parser_node.h"
34#include "universal_parser.c"
37#define STATIC_ID2SYM p->config->static_id2sym
38#define rb_str_coderange_scan_restartable p->config->str_coderange_scan_restartable
44#include "internal/compile.h"
45#include "internal/compilers.h"
46#include "internal/complex.h"
47#include "internal/encoding.h"
48#include "internal/error.h"
49#include "internal/hash.h"
50#include "internal/io.h"
51#include "internal/numeric.h"
52#include "internal/parse.h"
53#include "internal/rational.h"
54#include "internal/re.h"
55#include "internal/ruby_parser.h"
56#include "internal/symbol.h"
57#include "internal/thread.h"
58#include "internal/variable.h"
60#include "parser_node.h"
63#include "ruby/encoding.h"
64#include "ruby/regex.h"
68#include "ruby/ractor.h"
75 return rb_class_new_instance(0, 0, rb_eSyntaxError);
79static NODE *reg_named_capture_assign(struct parser_params* p, VALUE regexp, const YYLTYPE *loc, rb_parser_assignable_func assignable);
81#define compile_callback rb_suppress_tracing
82#endif /* !UNIVERSAL_PARSER */
84#define NODE_SPECIAL_EMPTY_ARGS ((NODE *)-1)
85#define NODE_EMPTY_ARGS_P(node) ((node) == NODE_SPECIAL_EMPTY_ARGS)
87static int rb_parser_string_hash_cmp(rb_parser_string_t *str1, rb_parser_string_t *str2);
90static rb_parser_string_t *rb_parser_string_deep_copy(struct parser_params *p, const rb_parser_string_t *original);
94node_integer_cmp(rb_node_integer_t *n1, rb_node_integer_t *n2)
96 return (n1->minus != n2->minus ||
97 n1->base != n2->base ||
98 strcmp(n1->val, n2->val));
102node_float_cmp(rb_node_float_t *n1, rb_node_float_t *n2)
104 return (n1->minus != n2->minus ||
105 strcmp(n1->val, n2->val));
109node_rational_cmp(rb_node_rational_t *n1, rb_node_rational_t *n2)
111 return (n1->minus != n2->minus ||
112 n1->base != n2->base ||
113 n1->seen_point != n2->seen_point ||
114 strcmp(n1->val, n2->val));
118node_imaginary_cmp(rb_node_imaginary_t *n1, rb_node_imaginary_t *n2)
120 return (n1->minus != n2->minus ||
121 n1->base != n2->base ||
122 n1->seen_point != n2->seen_point ||
123 n1->type != n2->type ||
124 strcmp(n1->val, n2->val));
128rb_parser_regx_hash_cmp(rb_node_regx_t *n1, rb_node_regx_t *n2)
130 return (n1->options != n2->options ||
131 rb_parser_string_hash_cmp(n1->string, n2->string));
134static st_index_t rb_parser_str_hash(rb_parser_string_t *str);
135static st_index_t rb_char_p_hash(const char *c);
138literal_cmp(st_data_t val, st_data_t lit)
140 if (val == lit) return 0;
142 NODE *node_val = RNODE(val);
143 NODE *node_lit = RNODE(lit);
144 enum node_type type_val = nd_type(node_val);
145 enum node_type type_lit = nd_type(node_lit);
147 if (type_val != type_lit) {
153 return node_integer_cmp(RNODE_INTEGER(node_val), RNODE_INTEGER(node_lit));
155 return node_float_cmp(RNODE_FLOAT(node_val), RNODE_FLOAT(node_lit));
157 return node_rational_cmp(RNODE_RATIONAL(node_val), RNODE_RATIONAL(node_lit));
159 return node_imaginary_cmp(RNODE_IMAGINARY(node_val), RNODE_IMAGINARY(node_lit));
161 return rb_parser_string_hash_cmp(RNODE_STR(node_val)->string, RNODE_STR(node_lit)->string);
163 return rb_parser_string_hash_cmp(RNODE_SYM(node_val)->string, RNODE_SYM(node_lit)->string);
165 return rb_parser_regx_hash_cmp(RNODE_REGX(node_val), RNODE_REGX(node_lit));
167 return node_val->nd_loc.beg_pos.lineno != node_lit->nd_loc.beg_pos.lineno;
169 return rb_parser_string_hash_cmp(RNODE_FILE(node_val)->path, RNODE_FILE(node_lit)->path);
171 return RNODE_ENCODING(node_val)->enc != RNODE_ENCODING(node_lit)->enc;
173#ifdef UNIVERSAL_PARSER
176 rb_bug("unexpected node: %s, %s", ruby_node_name(type_val), ruby_node_name(type_lit));
182literal_hash(st_data_t a)
184 NODE *node = (NODE *)a;
185 enum node_type type = nd_type(node);
189 return rb_char_p_hash(RNODE_INTEGER(node)->val);
191 return rb_char_p_hash(RNODE_FLOAT(node)->val);
193 return rb_char_p_hash(RNODE_RATIONAL(node)->val);
195 return rb_char_p_hash(RNODE_IMAGINARY(node)->val);
197 return rb_parser_str_hash(RNODE_STR(node)->string);
199 return rb_parser_str_hash(RNODE_SYM(node)->string);
201 return rb_parser_str_hash(RNODE_REGX(node)->string);
203 return (st_index_t)node->nd_loc.beg_pos.lineno;
205 return rb_parser_str_hash(RNODE_FILE(node)->path);
207 return (st_index_t)RNODE_ENCODING(node)->enc;
209#ifdef UNIVERSAL_PARSER
212 rb_bug("unexpected node: %s", ruby_node_name(type));
220 return '\0' <= c && c <= '\x7f';
224#define ISASCII parse_isascii
229 return c == ' ' || ('\t' <= c && c <= '\r');
233#define ISSPACE parse_isspace
238 return ('\0' <= c && c < ' ') || c == '\x7f';
242#define ISCNTRL(c) parse_iscntrl(c)
247 return 'A' <= c && c <= 'Z';
253 return 'a' <= c && c <= 'z';
259 return parse_isupper(c) || parse_islower(c);
263#define ISALPHA(c) parse_isalpha(c)
268 return '0' <= c && c <= '9';
272#define ISDIGIT(c) parse_isdigit(c)
277 return parse_isalpha(c) || parse_isdigit(c);
281#define ISALNUM(c) parse_isalnum(c)
286 return parse_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
290#define ISXDIGIT(c) parse_isxdigit(c)
292#include "parser_st.h"
295#define STRCASECMP rb_parser_st_locale_insensitive_strcasecmp
298#define STRNCASECMP rb_parser_st_locale_insensitive_strncasecmp
301#include "ripper_init.h"
312 unsigned int in_defined: 1;
313 unsigned int in_kwarg: 1;
314 unsigned int in_argdef: 1;
315 unsigned int in_def: 1;
316 unsigned int in_class: 1;
317 BITFIELD(enum rb_parser_shareability, shareable_constant_value, 2);
318 BITFIELD(enum rescue_context, in_rescue, 2);
319 unsigned int cant_return: 1;
322typedef struct RNode_DEF_TEMP rb_node_def_temp_t;
324#if defined(__GNUC__) && !defined(__clang__)
325// Suppress "parameter passing for argument of type 'struct
326// lex_context' changed" notes. `struct lex_context` is file scope,
327// and has no ABI compatibility issue.
329RBIMPL_WARNING_IGNORED(-Wpsabi)
331// Not sure why effective even after popped.
336#define NO_LEX_CTXT (struct lex_context){0}
338#ifndef WARN_PAST_SCOPE
339# define WARN_PAST_SCOPE 0
344#define yydebug (p->debug) /* disable the global variable definition */
346#define YYFPRINTF(out, ...) rb_parser_printf(p, __VA_ARGS__)
347#define YY_LOCATION_PRINT(File, loc, p) \
348 rb_parser_printf(p, "%d.%d-%d.%d", \
349 (loc).beg_pos.lineno, (loc).beg_pos.column,\
350 (loc).end_pos.lineno, (loc).end_pos.column)
351#define YYLLOC_DEFAULT(Current, Rhs, N) \
355 (Current).beg_pos = YYRHSLOC(Rhs, 1).beg_pos; \
356 (Current).end_pos = YYRHSLOC(Rhs, N).end_pos; \
360 (Current).beg_pos = YYRHSLOC(Rhs, 0).end_pos; \
361 (Current).end_pos = YYRHSLOC(Rhs, 0).end_pos; \
365 (((Msgid)[0] == 'm') && (strcmp((Msgid), "memory exhausted") == 0) ? \
366 "nesting too deep" : (Msgid))
368#define RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(Current) \
369 rb_parser_set_location_from_strterm_heredoc(p, &p->lex.strterm->u.heredoc, &(Current))
370#define RUBY_SET_YYLLOC_OF_DELAYED_TOKEN(Current) \
371 rb_parser_set_location_of_delayed_token(p, &(Current))
372#define RUBY_SET_YYLLOC_OF_HEREDOC_END(Current) \
373 rb_parser_set_location_of_heredoc_end(p, &(Current))
374#define RUBY_SET_YYLLOC_OF_DUMMY_END(Current) \
375 rb_parser_set_location_of_dummy_end(p, &(Current))
376#define RUBY_SET_YYLLOC_OF_NONE(Current) \
377 rb_parser_set_location_of_none(p, &(Current))
378#define RUBY_SET_YYLLOC(Current) \
379 rb_parser_set_location(p, &(Current))
380#define RUBY_INIT_YYLLOC() \
382 {p->ruby_sourceline, (int)(p->lex.ptok - p->lex.pbeg)}, \
383 {p->ruby_sourceline, (int)(p->lex.pcur - p->lex.pbeg)}, \
386#define IS_lex_state_for(x, ls) ((x) & (ls))
387#define IS_lex_state_all_for(x, ls) (((x) & (ls)) == (ls))
388#define IS_lex_state(ls) IS_lex_state_for(p->lex.state, (ls))
389#define IS_lex_state_all(ls) IS_lex_state_all_for(p->lex.state, (ls))
391# define SET_LEX_STATE(ls) \
392 parser_set_lex_state(p, ls, __LINE__)
393static inline enum lex_state_e parser_set_lex_state(struct parser_params *p, enum lex_state_e ls, int line);
395typedef VALUE stack_type;
397static const rb_code_location_t NULL_LOC = { {0, -1}, {0, -1} };
399# define SHOW_BITSTACK(stack, name) (p->debug ? rb_parser_show_bitstack(p, stack, name, __LINE__) : (void)0)
400# define BITSTACK_PUSH(stack, n) (((p->stack) = ((p->stack)<<1)|((n)&1)), SHOW_BITSTACK(p->stack, #stack"(push)"))
401# define BITSTACK_POP(stack) (((p->stack) = (p->stack) >> 1), SHOW_BITSTACK(p->stack, #stack"(pop)"))
402# define BITSTACK_SET_P(stack) (SHOW_BITSTACK(p->stack, #stack), (p->stack)&1)
403# define BITSTACK_SET(stack, n) ((p->stack)=(n), SHOW_BITSTACK(p->stack, #stack"(set)"))
405/* A flag to identify keyword_do_cond, "do" keyword after condition expression.
406 Examples: `while ... do`, `until ... do`, and `for ... in ... do` */
407#define COND_PUSH(n) BITSTACK_PUSH(cond_stack, (n))
408#define COND_POP() BITSTACK_POP(cond_stack)
409#define COND_P() BITSTACK_SET_P(cond_stack)
410#define COND_SET(n) BITSTACK_SET(cond_stack, (n))
412/* A flag to identify keyword_do_block; "do" keyword after command_call.
413 Example: `foo 1, 2 do`. */
414#define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, (n))
415#define CMDARG_POP() BITSTACK_POP(cmdarg_stack)
416#define CMDARG_P() BITSTACK_SET_P(cmdarg_stack)
417#define CMDARG_SET(n) BITSTACK_SET(cmdarg_stack, (n))
433 struct local_vars *prev;
435 NODE *outer, *inner, *current;
446#define DVARS_INHERIT ((void*)1)
447#define DVARS_TOPSCOPE NULL
448#define DVARS_TERMINAL_P(tbl) ((tbl) == DVARS_INHERIT || (tbl) == DVARS_TOPSCOPE)
450typedef struct token_info {
452 rb_code_position_t beg;
455 struct token_info *next;
458typedef struct end_expect_token_locations {
459 const rb_code_position_t *pos;
460 struct end_expect_token_locations *prev;
461} end_expect_token_locations_t;
463typedef struct parser_string_buffer_elem {
464 struct parser_string_buffer_elem *next;
465 long len; /* Total length of allocated buf */
466 long used; /* Current usage of buf */
467 rb_parser_string_t *buf[FLEX_ARY_LEN];
468} parser_string_buffer_elem_t;
470typedef struct parser_string_buffer {
471 parser_string_buffer_elem_t *head;
472 parser_string_buffer_elem_t *last;
473} parser_string_buffer_t;
475#define AFTER_HEREDOC_WITHOUT_TERMINTOR ((rb_parser_string_t *)1)
478 Structure of Lexer Buffer:
480 lex.pbeg lex.ptok lex.pcur lex.pend
482 |------------+------------+------------|
486struct parser_params {
491 rb_strterm_t *strterm;
492 rb_parser_lex_gets_func *gets;
493 rb_parser_input_data input;
494 parser_string_buffer_t string_buffer;
495 rb_parser_string_t *lastline;
496 rb_parser_string_t *nextline;
501 enum lex_state_e state;
502 /* track the nest level of any parens "()[]{}" */
504 /* keep p->lex.paren_nest at the beginning of lambda "->" to detect tLAMBEG and keyword_do_LAMBDA */
506 /* track the nest level of only braces "{}" */
509 stack_type cond_stack;
510 stack_type cmdarg_stack;
515 int heredoc_line_indent;
517 struct local_vars *lvtbl;
521 int ruby_sourceline; /* current line no. */
522 const char *ruby_sourcefile; /* current source file */
523 VALUE ruby_sourcefile_string;
525 token_info *token_info;
526 st_table *case_labels;
527 rb_node_exits_t *exits;
533 rb_parser_string_t *token;
543 st_table *warn_duplicate_keys_table;
548 struct lex_context ctxt;
550 NODE *eval_tree_begin;
552 const struct rb_iseq_struct *parent_iseq;
554#ifdef UNIVERSAL_PARSER
555 const rb_parser_config_t *config;
558 signed int frozen_string_literal:2; /* -1: not specified, 0: false, 1: true */
560 unsigned int command_start:1;
561 unsigned int eofp: 1;
562 unsigned int ruby__end__seen: 1;
563 unsigned int debug: 1;
564 unsigned int has_shebang: 1;
565 unsigned int token_seen: 1;
566 unsigned int token_info_enabled: 1;
568 unsigned int past_scope_enabled: 1;
570 unsigned int error_p: 1;
571 unsigned int cr_seen: 1;
576 unsigned int do_print: 1;
577 unsigned int do_loop: 1;
578 unsigned int do_chomp: 1;
579 unsigned int do_split: 1;
580 unsigned int error_tolerant: 1;
581 unsigned int keep_tokens: 1;
584 rb_parser_ary_t *debug_lines;
586 * Store specific keyword locations to generate dummy end token.
587 * Refer to the tail of list element.
589 end_expect_token_locations_t *end_expect_token_locations;
592 /* Array for term tokens */
593 rb_parser_ary_t *tokens;
599 VALUE parsing_thread;
600 VALUE s_value; /* Token VALUE */
601 VALUE s_lvalue; /* VALUE generated by rule action (reduce) */
606#define NUMPARAM_ID_P(id) numparam_id_p(p, id)
607#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - (tNUMPARAM_1 - 1))
608#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_1 - 1 + (idx)))
610numparam_id_p(struct parser_params *p, ID id)
612 if (!is_local_id(id) || id < (tNUMPARAM_1 << ID_SCOPE_SHIFT)) return 0;
613 unsigned int idx = NUMPARAM_ID_TO_IDX(id);
614 return idx > 0 && idx <= NUMPARAM_MAX;
616static void numparam_name(struct parser_params *p, ID id);
620after_shift(struct parser_params *p)
623 rb_parser_printf(p, "after-shift: %+"PRIsVALUE"\n", p->s_value);
625 rb_ary_push(p->s_value_stack, p->s_value);
630before_reduce(int len, struct parser_params *p)
632 // Initialize $$ with $1.
633 if (len) p->s_lvalue = rb_ary_entry(p->s_value_stack, -len);
637after_reduce(int len, struct parser_params *p)
639 for (int i = 0; i < len; i++) {
640 VALUE tos = rb_ary_pop(p->s_value_stack);
642 rb_parser_printf(p, "after-reduce pop: %+"PRIsVALUE"\n", tos);
646 rb_parser_printf(p, "after-reduce push: %+"PRIsVALUE"\n", p->s_lvalue);
648 rb_ary_push(p->s_value_stack, p->s_lvalue);
653after_shift_error_token(struct parser_params *p)
656 rb_parser_printf(p, "after-shift-error-token:\n");
658 rb_ary_push(p->s_value_stack, Qnil);
662after_pop_stack(int len, struct parser_params *p)
664 for (int i = 0; i < len; i++) {
665 VALUE tos = rb_ary_pop(p->s_value_stack);
667 rb_parser_printf(p, "after-pop-stack pop: %+"PRIsVALUE"\n", tos);
673after_shift(struct parser_params *p)
678before_reduce(int len, struct parser_params *p)
683after_reduce(int len, struct parser_params *p)
688after_shift_error_token(struct parser_params *p)
693after_pop_stack(int len, struct parser_params *p)
698#define intern_cstr(n,l,en) rb_intern3(n,l,en)
700#define STRING_NEW0() rb_parser_encoding_string_new(p,0,0,p->enc)
702#define STR_NEW(ptr,len) rb_enc_str_new((ptr),(len),p->enc)
703#define STR_NEW0() rb_enc_str_new(0,0,p->enc)
704#define STR_NEW2(ptr) rb_enc_str_new((ptr),strlen(ptr),p->enc)
705#define STR_NEW3(ptr,len,e,func) parser_str_new(p, (ptr),(len),(e),(func),p->enc)
706#define TOK_INTERN() intern_cstr(tok(p), toklen(p), p->enc)
707#define VALID_SYMNAME_P(s, l, enc, type) (rb_enc_symname_type(s, l, enc, (1U<<(type))) == (int)(type))
711char_at_end(struct parser_params *p, VALUE str, int when_empty)
713 long len = RSTRING_LEN(str);
714 return len > 0 ? (unsigned char)RSTRING_PTR(str)[len-1] : when_empty;
719pop_pvtbl(struct parser_params *p, st_table *tbl)
721 st_free_table(p->pvtbl);
726pop_pktbl(struct parser_params *p, st_table *tbl)
728 if (p->pktbl) st_free_table(p->pktbl);
732#define STRING_BUF_DEFAULT_LEN 16
735string_buffer_init(struct parser_params *p)
737 parser_string_buffer_t *buf = &p->lex.string_buffer;
738 const size_t size = offsetof(parser_string_buffer_elem_t, buf) + sizeof(rb_parser_string_t *) * STRING_BUF_DEFAULT_LEN;
740 buf->head = buf->last = xmalloc(size);
741 buf->head->len = STRING_BUF_DEFAULT_LEN;
743 buf->head->next = NULL;
747string_buffer_append(struct parser_params *p, rb_parser_string_t *str)
749 parser_string_buffer_t *buf = &p->lex.string_buffer;
751 if (buf->head->used >= buf->head->len) {
752 parser_string_buffer_elem_t *elem;
753 long n = buf->head->len * 2;
754 const size_t size = offsetof(parser_string_buffer_elem_t, buf) + sizeof(rb_parser_string_t *) * n;
756 elem = xmalloc(size);
760 buf->last->next = elem;
763 buf->last->buf[buf->last->used++] = str;
767string_buffer_free(struct parser_params *p)
769 parser_string_buffer_elem_t *elem = p->lex.string_buffer.head;
772 parser_string_buffer_elem_t *next_elem = elem->next;
774 for (long i = 0; i < elem->used; i++) {
775 rb_parser_string_free(p, elem->buf[i]);
784static void flush_debug_buffer(struct parser_params *p, VALUE out, VALUE str);
787debug_end_expect_token_locations(struct parser_params *p, const char *name)
790 VALUE mesg = rb_sprintf("%s: [", name);
792 for (end_expect_token_locations_t *loc = p->end_expect_token_locations; loc; loc = loc->prev) {
794 rb_str_cat_cstr(mesg, ", ");
795 rb_str_catf(mesg, "[%d, %d]", loc->pos->lineno, loc->pos->column);
798 rb_str_cat_cstr(mesg, "]\n");
799 flush_debug_buffer(p, p->debug_output, mesg);
804push_end_expect_token_locations(struct parser_params *p, const rb_code_position_t *pos)
806 if(!p->error_tolerant) return;
808 end_expect_token_locations_t *locations;
809 locations = ALLOC(end_expect_token_locations_t);
810 locations->pos = pos;
811 locations->prev = p->end_expect_token_locations;
812 p->end_expect_token_locations = locations;
814 debug_end_expect_token_locations(p, "push_end_expect_token_locations");
818pop_end_expect_token_locations(struct parser_params *p)
820 if(!p->end_expect_token_locations) return;
822 end_expect_token_locations_t *locations = p->end_expect_token_locations->prev;
823 ruby_sized_xfree(p->end_expect_token_locations, sizeof(end_expect_token_locations_t));
824 p->end_expect_token_locations = locations;
826 debug_end_expect_token_locations(p, "pop_end_expect_token_locations");
829static end_expect_token_locations_t *
830peek_end_expect_token_locations(struct parser_params *p)
832 return p->end_expect_token_locations;
836parser_token2char(struct parser_params *p, enum yytokentype tok)
839#define TOKEN2CHAR(tok) case tok: return (#tok);
840#define TOKEN2CHAR2(tok, name) case tok: return (name);
841 TOKEN2CHAR2(' ', "word_sep");
842 TOKEN2CHAR2('!', "!")
843 TOKEN2CHAR2('%', "%");
844 TOKEN2CHAR2('&', "&");
845 TOKEN2CHAR2('*', "*");
846 TOKEN2CHAR2('+', "+");
847 TOKEN2CHAR2('-', "-");
848 TOKEN2CHAR2('/', "/");
849 TOKEN2CHAR2('<', "<");
850 TOKEN2CHAR2('=', "=");
851 TOKEN2CHAR2('>', ">");
852 TOKEN2CHAR2('?', "?");
853 TOKEN2CHAR2('^', "^");
854 TOKEN2CHAR2('|', "|");
855 TOKEN2CHAR2('~', "~");
856 TOKEN2CHAR2(':', ":");
857 TOKEN2CHAR2(',', ",");
858 TOKEN2CHAR2('.', ".");
859 TOKEN2CHAR2(';', ";");
860 TOKEN2CHAR2('`', "`");
861 TOKEN2CHAR2('\n', "nl");
862 TOKEN2CHAR2('{', "\"{\"");
863 TOKEN2CHAR2('}', "\"}\"");
864 TOKEN2CHAR2('[', "\"[\"");
865 TOKEN2CHAR2(']', "\"]\"");
866 TOKEN2CHAR2('(', "\"(\"");
867 TOKEN2CHAR2(')', "\")\"");
868 TOKEN2CHAR2('\\', "backslash");
869 TOKEN2CHAR(keyword_class);
870 TOKEN2CHAR(keyword_module);
871 TOKEN2CHAR(keyword_def);
872 TOKEN2CHAR(keyword_undef);
873 TOKEN2CHAR(keyword_begin);
874 TOKEN2CHAR(keyword_rescue);
875 TOKEN2CHAR(keyword_ensure);
876 TOKEN2CHAR(keyword_end);
877 TOKEN2CHAR(keyword_if);
878 TOKEN2CHAR(keyword_unless);
879 TOKEN2CHAR(keyword_then);
880 TOKEN2CHAR(keyword_elsif);
881 TOKEN2CHAR(keyword_else);
882 TOKEN2CHAR(keyword_case);
883 TOKEN2CHAR(keyword_when);
884 TOKEN2CHAR(keyword_while);
885 TOKEN2CHAR(keyword_until);
886 TOKEN2CHAR(keyword_for);
887 TOKEN2CHAR(keyword_break);
888 TOKEN2CHAR(keyword_next);
889 TOKEN2CHAR(keyword_redo);
890 TOKEN2CHAR(keyword_retry);
891 TOKEN2CHAR(keyword_in);
892 TOKEN2CHAR(keyword_do);
893 TOKEN2CHAR(keyword_do_cond);
894 TOKEN2CHAR(keyword_do_block);
895 TOKEN2CHAR(keyword_do_LAMBDA);
896 TOKEN2CHAR(keyword_return);
897 TOKEN2CHAR(keyword_yield);
898 TOKEN2CHAR(keyword_super);
899 TOKEN2CHAR(keyword_self);
900 TOKEN2CHAR(keyword_nil);
901 TOKEN2CHAR(keyword_true);
902 TOKEN2CHAR(keyword_false);
903 TOKEN2CHAR(keyword_and);
904 TOKEN2CHAR(keyword_or);
905 TOKEN2CHAR(keyword_not);
906 TOKEN2CHAR(modifier_if);
907 TOKEN2CHAR(modifier_unless);
908 TOKEN2CHAR(modifier_while);
909 TOKEN2CHAR(modifier_until);
910 TOKEN2CHAR(modifier_rescue);
911 TOKEN2CHAR(keyword_alias);
912 TOKEN2CHAR(keyword_defined);
913 TOKEN2CHAR(keyword_BEGIN);
914 TOKEN2CHAR(keyword_END);
915 TOKEN2CHAR(keyword__LINE__);
916 TOKEN2CHAR(keyword__FILE__);
917 TOKEN2CHAR(keyword__ENCODING__);
918 TOKEN2CHAR(tIDENTIFIER);
922 TOKEN2CHAR(tCONSTANT);
925 TOKEN2CHAR(tINTEGER);
927 TOKEN2CHAR(tRATIONAL);
928 TOKEN2CHAR(tIMAGINARY);
930 TOKEN2CHAR(tNTH_REF);
931 TOKEN2CHAR(tBACK_REF);
932 TOKEN2CHAR(tSTRING_CONTENT);
933 TOKEN2CHAR(tREGEXP_END);
934 TOKEN2CHAR(tDUMNY_END);
960 TOKEN2CHAR(tOP_ASGN);
963 TOKEN2CHAR(tLPAREN_ARG);
967 TOKEN2CHAR(tLBRACE_ARG);
973 TOKEN2CHAR(tSTRING_BEG);
974 TOKEN2CHAR(tXSTRING_BEG);
975 TOKEN2CHAR(tREGEXP_BEG);
976 TOKEN2CHAR(tWORDS_BEG);
977 TOKEN2CHAR(tQWORDS_BEG);
978 TOKEN2CHAR(tSYMBOLS_BEG);
979 TOKEN2CHAR(tQSYMBOLS_BEG);
980 TOKEN2CHAR(tSTRING_END);
981 TOKEN2CHAR(tSTRING_DEND);
982 TOKEN2CHAR(tSTRING_DBEG);
983 TOKEN2CHAR(tSTRING_DVAR);
985 TOKEN2CHAR(tLABEL_END);
986 TOKEN2CHAR(tIGNORED_NL);
987 TOKEN2CHAR(tCOMMENT);
988 TOKEN2CHAR(tEMBDOC_BEG);
990 TOKEN2CHAR(tEMBDOC_END);
991 TOKEN2CHAR(tHEREDOC_BEG);
992 TOKEN2CHAR(tHEREDOC_END);
993 TOKEN2CHAR(k__END__);
995 TOKEN2CHAR(tUMINUS_NUM);
996 TOKEN2CHAR(tLAST_TOKEN);
1001 rb_bug("parser_token2id: unknown token %d", tok);
1003 UNREACHABLE_RETURN(0);
1007push_end_expect_token_locations(struct parser_params *p, const rb_code_position_t *pos)
1012pop_end_expect_token_locations(struct parser_params *p)
1017RBIMPL_ATTR_NONNULL((1, 2, 3))
1018static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const char*);
1019RBIMPL_ATTR_NONNULL((1, 2))
1020static int parser_yyerror0(struct parser_params*, const char*);
1021#define yyerror0(msg) parser_yyerror0(p, (msg))
1022#define yyerror1(loc, msg) parser_yyerror(p, (loc), (msg))
1023#define yyerror(yylloc, p, msg) parser_yyerror(p, yylloc, msg)
1024#define token_flush(ptr) ((ptr)->lex.ptok = (ptr)->lex.pcur)
1025#define lex_goto_eol(p) ((p)->lex.pcur = (p)->lex.pend)
1026#define lex_eol_p(p) lex_eol_n_p(p, 0)
1027#define lex_eol_n_p(p,n) lex_eol_ptr_n_p(p, (p)->lex.pcur, n)
1028#define lex_eol_ptr_p(p,ptr) lex_eol_ptr_n_p(p,ptr,0)
1029#define lex_eol_ptr_n_p(p,ptr,n) ((ptr)+(n) >= (p)->lex.pend)
1031static void token_info_setup(token_info *ptinfo, const char *ptr, const rb_code_location_t *loc);
1032static void token_info_push(struct parser_params*, const char *token, const rb_code_location_t *loc);
1033static void token_info_pop(struct parser_params*, const char *token, const rb_code_location_t *loc);
1034static void token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc);
1035static void token_info_drop(struct parser_params *p, const char *token, rb_code_position_t beg_pos);
1038#define compile_for_eval (0)
1040#define compile_for_eval (p->parent_iseq != 0)
1043#define token_column ((int)(p->lex.ptok - p->lex.pbeg))
1045#define CALL_Q_P(q) ((q) == tANDDOT)
1046#define NEW_QCALL(q,r,m,a,loc) (CALL_Q_P(q) ? NEW_QCALL0(r,m,a,loc) : NEW_CALL(r,m,a,loc))
1048#define lambda_beginning_p() (p->lex.lpar_beg == p->lex.paren_nest)
1050static enum yytokentype yylex(YYSTYPE*, YYLTYPE*, struct parser_params*);
1053rb_discard_node(struct parser_params *p, NODE *n)
1055 rb_ast_delete_node(p->ast, n);
1058static rb_node_scope_t *rb_node_scope_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc);
1059static rb_node_scope_t *rb_node_scope_new2(struct parser_params *p, rb_ast_id_table_t *nd_tbl, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc);
1060static rb_node_block_t *rb_node_block_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
1061static rb_node_if_t *rb_node_if_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, NODE *nd_else, const YYLTYPE *loc);
1062static rb_node_unless_t *rb_node_unless_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, NODE *nd_else, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc, const YYLTYPE *end_keyword_loc);
1063static rb_node_case_t *rb_node_case_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
1064static rb_node_case2_t *rb_node_case2_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
1065static rb_node_case3_t *rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
1066static rb_node_when_t *rb_node_when_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc);
1067static rb_node_in_t *rb_node_in_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc);
1068static rb_node_while_t *rb_node_while_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, long nd_state, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *closing_loc);
1069static rb_node_until_t *rb_node_until_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, long nd_state, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *closing_loc);
1070static rb_node_iter_t *rb_node_iter_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc);
1071static rb_node_for_t *rb_node_for_new(struct parser_params *p, NODE *nd_iter, NODE *nd_body, const YYLTYPE *loc);
1072static rb_node_for_masgn_t *rb_node_for_masgn_new(struct parser_params *p, NODE *nd_var, const YYLTYPE *loc);
1073static rb_node_retry_t *rb_node_retry_new(struct parser_params *p, const YYLTYPE *loc);
1074static rb_node_begin_t *rb_node_begin_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1075static rb_node_rescue_t *rb_node_rescue_new(struct parser_params *p, NODE *nd_head, NODE *nd_resq, NODE *nd_else, const YYLTYPE *loc);
1076static rb_node_resbody_t *rb_node_resbody_new(struct parser_params *p, NODE *nd_args, NODE *nd_exc_var, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc);
1077static rb_node_ensure_t *rb_node_ensure_new(struct parser_params *p, NODE *nd_head, NODE *nd_ensr, const YYLTYPE *loc);
1078static rb_node_and_t *rb_node_and_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *operator_loc);
1079static rb_node_or_t *rb_node_or_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *operator_loc);
1080static rb_node_masgn_t *rb_node_masgn_new(struct parser_params *p, NODE *nd_head, NODE *nd_args, const YYLTYPE *loc);
1081static rb_node_lasgn_t *rb_node_lasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
1082static rb_node_dasgn_t *rb_node_dasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
1083static rb_node_gasgn_t *rb_node_gasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
1084static rb_node_iasgn_t *rb_node_iasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
1085static rb_node_cdecl_t *rb_node_cdecl_new(struct parser_params *p, ID nd_vid, NODE *nd_value, NODE *nd_else, enum rb_parser_shareability shareability, const YYLTYPE *loc);
1086static rb_node_cvasgn_t *rb_node_cvasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc);
1087static rb_node_op_asgn1_t *rb_node_op_asgn1_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *index, NODE *rvalue, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc);
1088static rb_node_op_asgn2_t *rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc);
1089static rb_node_op_asgn_or_t *rb_node_op_asgn_or_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc);
1090static rb_node_op_asgn_and_t *rb_node_op_asgn_and_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc);
1091static rb_node_op_cdecl_t *rb_node_op_cdecl_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, ID nd_aid, enum rb_parser_shareability shareability, const YYLTYPE *loc);
1092static rb_node_call_t *rb_node_call_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
1093static rb_node_opcall_t *rb_node_opcall_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
1094static rb_node_fcall_t *rb_node_fcall_new(struct parser_params *p, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
1095static rb_node_vcall_t *rb_node_vcall_new(struct parser_params *p, ID nd_mid, const YYLTYPE *loc);
1096static rb_node_qcall_t *rb_node_qcall_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
1097static rb_node_super_t *rb_node_super_new(struct parser_params *p, NODE *nd_args, const YYLTYPE *loc);
1098static rb_node_zsuper_t * rb_node_zsuper_new(struct parser_params *p, const YYLTYPE *loc);
1099static rb_node_list_t *rb_node_list_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
1100static rb_node_list_t *rb_node_list_new2(struct parser_params *p, NODE *nd_head, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
1101static rb_node_zlist_t *rb_node_zlist_new(struct parser_params *p, const YYLTYPE *loc);
1102static rb_node_hash_t *rb_node_hash_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
1103static rb_node_return_t *rb_node_return_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1104static rb_node_yield_t *rb_node_yield_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
1105static rb_node_lvar_t *rb_node_lvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1106static rb_node_dvar_t *rb_node_dvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1107static rb_node_gvar_t *rb_node_gvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1108static rb_node_ivar_t *rb_node_ivar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1109static rb_node_const_t *rb_node_const_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1110static rb_node_cvar_t *rb_node_cvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc);
1111static rb_node_nth_ref_t *rb_node_nth_ref_new(struct parser_params *p, long nd_nth, const YYLTYPE *loc);
1112static rb_node_back_ref_t *rb_node_back_ref_new(struct parser_params *p, long nd_nth, const YYLTYPE *loc);
1113static rb_node_match2_t *rb_node_match2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, const YYLTYPE *loc);
1114static rb_node_match3_t *rb_node_match3_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, const YYLTYPE *loc);
1115static rb_node_integer_t * rb_node_integer_new(struct parser_params *p, char* val, int base, const YYLTYPE *loc);
1116static rb_node_float_t * rb_node_float_new(struct parser_params *p, char* val, const YYLTYPE *loc);
1117static rb_node_rational_t * rb_node_rational_new(struct parser_params *p, char* val, int base, int seen_point, const YYLTYPE *loc);
1118static rb_node_imaginary_t * rb_node_imaginary_new(struct parser_params *p, char* val, int base, int seen_point, enum rb_numeric_type, const YYLTYPE *loc);
1119static rb_node_str_t *rb_node_str_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc);
1120static rb_node_dstr_t *rb_node_dstr_new0(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
1121static rb_node_dstr_t *rb_node_dstr_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc);
1122static rb_node_xstr_t *rb_node_xstr_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc);
1123static rb_node_dxstr_t *rb_node_dxstr_new(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
1124static rb_node_evstr_t *rb_node_evstr_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1125static rb_node_regx_t *rb_node_regx_new(struct parser_params *p, rb_parser_string_t *string, int options, const YYLTYPE *loc);
1126static rb_node_once_t *rb_node_once_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1127static rb_node_args_t *rb_node_args_new(struct parser_params *p, const YYLTYPE *loc);
1128static rb_node_args_aux_t *rb_node_args_aux_new(struct parser_params *p, ID nd_pid, int nd_plen, const YYLTYPE *loc);
1129static rb_node_opt_arg_t *rb_node_opt_arg_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1130static rb_node_kw_arg_t *rb_node_kw_arg_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1131static rb_node_postarg_t *rb_node_postarg_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc);
1132static rb_node_argscat_t *rb_node_argscat_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc);
1133static rb_node_argspush_t *rb_node_argspush_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc);
1134static rb_node_splat_t *rb_node_splat_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc, const YYLTYPE *operator_loc);
1135static rb_node_block_pass_t *rb_node_block_pass_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *operator_loc);
1136static rb_node_defn_t *rb_node_defn_new(struct parser_params *p, ID nd_mid, NODE *nd_defn, const YYLTYPE *loc);
1137static rb_node_defs_t *rb_node_defs_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_defn, const YYLTYPE *loc);
1138static rb_node_alias_t *rb_node_alias_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1139static rb_node_valias_t *rb_node_valias_new(struct parser_params *p, ID nd_alias, ID nd_orig, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1140static rb_node_undef_t *rb_node_undef_new(struct parser_params *p, NODE *nd_undef, const YYLTYPE *loc);
1141static rb_node_class_t *rb_node_class_new(struct parser_params *p, NODE *nd_cpath, NODE *nd_body, NODE *nd_super, const YYLTYPE *loc);
1142static rb_node_module_t *rb_node_module_new(struct parser_params *p, NODE *nd_cpath, NODE *nd_body, const YYLTYPE *loc);
1143static rb_node_sclass_t *rb_node_sclass_new(struct parser_params *p, NODE *nd_recv, NODE *nd_body, const YYLTYPE *loc);
1144static rb_node_colon2_t *rb_node_colon2_new(struct parser_params *p, NODE *nd_head, ID nd_mid, const YYLTYPE *loc);
1145static rb_node_colon3_t *rb_node_colon3_new(struct parser_params *p, ID nd_mid, const YYLTYPE *loc);
1146static rb_node_dot2_t *rb_node_dot2_new(struct parser_params *p, NODE *nd_beg, NODE *nd_end, const YYLTYPE *loc);
1147static rb_node_dot3_t *rb_node_dot3_new(struct parser_params *p, NODE *nd_beg, NODE *nd_end, const YYLTYPE *loc);
1148static rb_node_self_t *rb_node_self_new(struct parser_params *p, const YYLTYPE *loc);
1149static rb_node_nil_t *rb_node_nil_new(struct parser_params *p, const YYLTYPE *loc);
1150static rb_node_true_t *rb_node_true_new(struct parser_params *p, const YYLTYPE *loc);
1151static rb_node_false_t *rb_node_false_new(struct parser_params *p, const YYLTYPE *loc);
1152static rb_node_errinfo_t *rb_node_errinfo_new(struct parser_params *p, const YYLTYPE *loc);
1153static rb_node_defined_t *rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc);
1154static rb_node_postexe_t *rb_node_postexe_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc);
1155static rb_node_sym_t *rb_node_sym_new(struct parser_params *p, VALUE str, const YYLTYPE *loc);
1156static rb_node_dsym_t *rb_node_dsym_new(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc);
1157static rb_node_attrasgn_t *rb_node_attrasgn_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc);
1158static rb_node_lambda_t *rb_node_lambda_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc);
1159static rb_node_aryptn_t *rb_node_aryptn_new(struct parser_params *p, NODE *pre_args, NODE *rest_arg, NODE *post_args, const YYLTYPE *loc);
1160static rb_node_hshptn_t *rb_node_hshptn_new(struct parser_params *p, NODE *nd_pconst, NODE *nd_pkwargs, NODE *nd_pkwrestarg, const YYLTYPE *loc);
1161static rb_node_fndptn_t *rb_node_fndptn_new(struct parser_params *p, NODE *pre_rest_arg, NODE *args, NODE *post_rest_arg, const YYLTYPE *loc);
1162static rb_node_line_t *rb_node_line_new(struct parser_params *p, const YYLTYPE *loc);
1163static rb_node_file_t *rb_node_file_new(struct parser_params *p, VALUE str, const YYLTYPE *loc);
1164static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE *loc);
1166#define NEW_SCOPE(a,b,loc) (NODE *)rb_node_scope_new(p,a,b,loc)
1167#define NEW_SCOPE2(t,a,b,loc) (NODE *)rb_node_scope_new2(p,t,a,b,loc)
1168#define NEW_BLOCK(a,loc) (NODE *)rb_node_block_new(p,a,loc)
1169#define NEW_IF(c,t,e,loc) (NODE *)rb_node_if_new(p,c,t,e,loc)
1170#define NEW_UNLESS(c,t,e,loc,k_loc,t_loc,e_loc) (NODE *)rb_node_unless_new(p,c,t,e,loc,k_loc,t_loc,e_loc)
1171#define NEW_CASE(h,b,loc,ck_loc,ek_loc) (NODE *)rb_node_case_new(p,h,b,loc,ck_loc,ek_loc)
1172#define NEW_CASE2(b,loc,ck_loc,ek_loc) (NODE *)rb_node_case2_new(p,b,loc,ck_loc,ek_loc)
1173#define NEW_CASE3(h,b,loc,ck_loc,ek_loc) (NODE *)rb_node_case3_new(p,h,b,loc,ck_loc,ek_loc)
1174#define NEW_WHEN(c,t,e,loc,k_loc,t_loc) (NODE *)rb_node_when_new(p,c,t,e,loc,k_loc,t_loc)
1175#define NEW_IN(c,t,e,loc) (NODE *)rb_node_in_new(p,c,t,e,loc)
1176#define NEW_WHILE(c,b,n,loc,k_loc,c_loc) (NODE *)rb_node_while_new(p,c,b,n,loc,k_loc,c_loc)
1177#define NEW_UNTIL(c,b,n,loc,k_loc,c_loc) (NODE *)rb_node_until_new(p,c,b,n,loc,k_loc,c_loc)
1178#define NEW_ITER(a,b,loc) (NODE *)rb_node_iter_new(p,a,b,loc)
1179#define NEW_FOR(i,b,loc) (NODE *)rb_node_for_new(p,i,b,loc)
1180#define NEW_FOR_MASGN(v,loc) (NODE *)rb_node_for_masgn_new(p,v,loc)
1181#define NEW_RETRY(loc) (NODE *)rb_node_retry_new(p,loc)
1182#define NEW_BEGIN(b,loc) (NODE *)rb_node_begin_new(p,b,loc)
1183#define NEW_RESCUE(b,res,e,loc) (NODE *)rb_node_rescue_new(p,b,res,e,loc)
1184#define NEW_RESBODY(a,v,ex,n,loc) (NODE *)rb_node_resbody_new(p,a,v,ex,n,loc)
1185#define NEW_ENSURE(b,en,loc) (NODE *)rb_node_ensure_new(p,b,en,loc)
1186#define NEW_AND(f,s,loc,op_loc) (NODE *)rb_node_and_new(p,f,s,loc,op_loc)
1187#define NEW_OR(f,s,loc,op_loc) (NODE *)rb_node_or_new(p,f,s,loc,op_loc)
1188#define NEW_MASGN(l,r,loc) rb_node_masgn_new(p,l,r,loc)
1189#define NEW_LASGN(v,val,loc) (NODE *)rb_node_lasgn_new(p,v,val,loc)
1190#define NEW_DASGN(v,val,loc) (NODE *)rb_node_dasgn_new(p,v,val,loc)
1191#define NEW_GASGN(v,val,loc) (NODE *)rb_node_gasgn_new(p,v,val,loc)
1192#define NEW_IASGN(v,val,loc) (NODE *)rb_node_iasgn_new(p,v,val,loc)
1193#define NEW_CDECL(v,val,path,share,loc) (NODE *)rb_node_cdecl_new(p,v,val,path,share,loc)
1194#define NEW_CVASGN(v,val,loc) (NODE *)rb_node_cvasgn_new(p,v,val,loc)
1195#define NEW_OP_ASGN1(r,id,idx,rval,loc,c_op_loc,o_loc,c_loc,b_op_loc) (NODE *)rb_node_op_asgn1_new(p,r,id,idx,rval,loc,c_op_loc,o_loc,c_loc,b_op_loc)
1196#define NEW_OP_ASGN2(r,t,i,o,val,loc,c_op_loc,m_loc,b_op_loc) (NODE *)rb_node_op_asgn2_new(p,r,val,i,o,t,loc,c_op_loc,m_loc,b_op_loc)
1197#define NEW_OP_ASGN_OR(i,val,loc) (NODE *)rb_node_op_asgn_or_new(p,i,val,loc)
1198#define NEW_OP_ASGN_AND(i,val,loc) (NODE *)rb_node_op_asgn_and_new(p,i,val,loc)
1199#define NEW_OP_CDECL(v,op,val,share,loc) (NODE *)rb_node_op_cdecl_new(p,v,val,op,share,loc)
1200#define NEW_CALL(r,m,a,loc) (NODE *)rb_node_call_new(p,r,m,a,loc)
1201#define NEW_OPCALL(r,m,a,loc) (NODE *)rb_node_opcall_new(p,r,m,a,loc)
1202#define NEW_FCALL(m,a,loc) rb_node_fcall_new(p,m,a,loc)
1203#define NEW_VCALL(m,loc) (NODE *)rb_node_vcall_new(p,m,loc)
1204#define NEW_QCALL0(r,m,a,loc) (NODE *)rb_node_qcall_new(p,r,m,a,loc)
1205#define NEW_SUPER(a,loc) (NODE *)rb_node_super_new(p,a,loc)
1206#define NEW_ZSUPER(loc) (NODE *)rb_node_zsuper_new(p,loc)
1207#define NEW_LIST(a,loc) (NODE *)rb_node_list_new(p,a,loc)
1208#define NEW_LIST2(h,l,n,loc) (NODE *)rb_node_list_new2(p,h,l,n,loc)
1209#define NEW_ZLIST(loc) (NODE *)rb_node_zlist_new(p,loc)
1210#define NEW_HASH(a,loc) (NODE *)rb_node_hash_new(p,a,loc)
1211#define NEW_RETURN(s,loc,k_loc) (NODE *)rb_node_return_new(p,s,loc,k_loc)
1212#define NEW_YIELD(a,loc) (NODE *)rb_node_yield_new(p,a,loc)
1213#define NEW_LVAR(v,loc) (NODE *)rb_node_lvar_new(p,v,loc)
1214#define NEW_DVAR(v,loc) (NODE *)rb_node_dvar_new(p,v,loc)
1215#define NEW_GVAR(v,loc) (NODE *)rb_node_gvar_new(p,v,loc)
1216#define NEW_IVAR(v,loc) (NODE *)rb_node_ivar_new(p,v,loc)
1217#define NEW_CONST(v,loc) (NODE *)rb_node_const_new(p,v,loc)
1218#define NEW_CVAR(v,loc) (NODE *)rb_node_cvar_new(p,v,loc)
1219#define NEW_NTH_REF(n,loc) (NODE *)rb_node_nth_ref_new(p,n,loc)
1220#define NEW_BACK_REF(n,loc) (NODE *)rb_node_back_ref_new(p,n,loc)
1221#define NEW_MATCH2(n1,n2,loc) (NODE *)rb_node_match2_new(p,n1,n2,loc)
1222#define NEW_MATCH3(r,n2,loc) (NODE *)rb_node_match3_new(p,r,n2,loc)
1223#define NEW_INTEGER(val, base,loc) (NODE *)rb_node_integer_new(p,val,base,loc)
1224#define NEW_FLOAT(val,loc) (NODE *)rb_node_float_new(p,val,loc)
1225#define NEW_RATIONAL(val,base,seen_point,loc) (NODE *)rb_node_rational_new(p,val,base,seen_point,loc)
1226#define NEW_IMAGINARY(val,base,seen_point,numeric_type,loc) (NODE *)rb_node_imaginary_new(p,val,base,seen_point,numeric_type,loc)
1227#define NEW_STR(s,loc) (NODE *)rb_node_str_new(p,s,loc)
1228#define NEW_DSTR0(s,l,n,loc) (NODE *)rb_node_dstr_new0(p,s,l,n,loc)
1229#define NEW_DSTR(s,loc) (NODE *)rb_node_dstr_new(p,s,loc)
1230#define NEW_XSTR(s,loc) (NODE *)rb_node_xstr_new(p,s,loc)
1231#define NEW_DXSTR(s,l,n,loc) (NODE *)rb_node_dxstr_new(p,s,l,n,loc)
1232#define NEW_EVSTR(n,loc) (NODE *)rb_node_evstr_new(p,n,loc)
1233#define NEW_REGX(str,opts,loc) (NODE *)rb_node_regx_new(p,str,opts,loc)
1234#define NEW_ONCE(b,loc) (NODE *)rb_node_once_new(p,b,loc)
1235#define NEW_ARGS(loc) rb_node_args_new(p,loc)
1236#define NEW_ARGS_AUX(r,b,loc) rb_node_args_aux_new(p,r,b,loc)
1237#define NEW_OPT_ARG(v,loc) rb_node_opt_arg_new(p,v,loc)
1238#define NEW_KW_ARG(v,loc) rb_node_kw_arg_new(p,v,loc)
1239#define NEW_POSTARG(i,v,loc) (NODE *)rb_node_postarg_new(p,i,v,loc)
1240#define NEW_ARGSCAT(a,b,loc) (NODE *)rb_node_argscat_new(p,a,b,loc)
1241#define NEW_ARGSPUSH(a,b,loc) (NODE *)rb_node_argspush_new(p,a,b,loc)
1242#define NEW_SPLAT(a,loc,op_loc) (NODE *)rb_node_splat_new(p,a,loc,op_loc)
1243#define NEW_BLOCK_PASS(b,loc,o_loc) rb_node_block_pass_new(p,b,loc,o_loc)
1244#define NEW_DEFN(i,s,loc) (NODE *)rb_node_defn_new(p,i,s,loc)
1245#define NEW_DEFS(r,i,s,loc) (NODE *)rb_node_defs_new(p,r,i,s,loc)
1246#define NEW_ALIAS(n,o,loc,k_loc) (NODE *)rb_node_alias_new(p,n,o,loc,k_loc)
1247#define NEW_VALIAS(n,o,loc,k_loc) (NODE *)rb_node_valias_new(p,n,o,loc,k_loc)
1248#define NEW_UNDEF(i,loc) (NODE *)rb_node_undef_new(p,i,loc)
1249#define NEW_CLASS(n,b,s,loc) (NODE *)rb_node_class_new(p,n,b,s,loc)
1250#define NEW_MODULE(n,b,loc) (NODE *)rb_node_module_new(p,n,b,loc)
1251#define NEW_SCLASS(r,b,loc) (NODE *)rb_node_sclass_new(p,r,b,loc)
1252#define NEW_COLON2(c,i,loc) (NODE *)rb_node_colon2_new(p,c,i,loc)
1253#define NEW_COLON3(i,loc) (NODE *)rb_node_colon3_new(p,i,loc)
1254#define NEW_DOT2(b,e,loc) (NODE *)rb_node_dot2_new(p,b,e,loc)
1255#define NEW_DOT3(b,e,loc) (NODE *)rb_node_dot3_new(p,b,e,loc)
1256#define NEW_SELF(loc) (NODE *)rb_node_self_new(p,loc)
1257#define NEW_NIL(loc) (NODE *)rb_node_nil_new(p,loc)
1258#define NEW_TRUE(loc) (NODE *)rb_node_true_new(p,loc)
1259#define NEW_FALSE(loc) (NODE *)rb_node_false_new(p,loc)
1260#define NEW_ERRINFO(loc) (NODE *)rb_node_errinfo_new(p,loc)
1261#define NEW_DEFINED(e,loc) (NODE *)rb_node_defined_new(p,e,loc)
1262#define NEW_POSTEXE(b,loc) (NODE *)rb_node_postexe_new(p,b,loc)
1263#define NEW_SYM(str,loc) (NODE *)rb_node_sym_new(p,str,loc)
1264#define NEW_DSYM(s,l,n,loc) (NODE *)rb_node_dsym_new(p,s,l,n,loc)
1265#define NEW_ATTRASGN(r,m,a,loc) (NODE *)rb_node_attrasgn_new(p,r,m,a,loc)
1266#define NEW_LAMBDA(a,b,loc) (NODE *)rb_node_lambda_new(p,a,b,loc)
1267#define NEW_ARYPTN(pre,r,post,loc) (NODE *)rb_node_aryptn_new(p,pre,r,post,loc)
1268#define NEW_HSHPTN(c,kw,kwrest,loc) (NODE *)rb_node_hshptn_new(p,c,kw,kwrest,loc)
1269#define NEW_FNDPTN(pre,a,post,loc) (NODE *)rb_node_fndptn_new(p,pre,a,post,loc)
1270#define NEW_LINE(loc) (NODE *)rb_node_line_new(p,loc)
1271#define NEW_FILE(str,loc) (NODE *)rb_node_file_new(p,str,loc)
1272#define NEW_ENCODING(loc) (NODE *)rb_node_encoding_new(p,loc)
1273#define NEW_ERROR(loc) (NODE *)rb_node_error_new(p,loc)
1275enum internal_node_type {
1276 NODE_INTERNAL_ONLY = NODE_LAST,
1283parser_node_name(int node)
1287 return "NODE_DEF_TEMP";
1289 return "NODE_EXITS";
1291 return ruby_node_name(node);
1295/* This node is parse.y internal */
1296struct RNode_DEF_TEMP {
1299 /* for NODE_DEFN/NODE_DEFS */
1301 struct RNode *nd_def;
1306 NODE *numparam_save;
1307 struct lex_context ctxt;
1311#define RNODE_DEF_TEMP(node) ((struct RNode_DEF_TEMP *)(node))
1313static rb_node_break_t *rb_node_break_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1314static rb_node_next_t *rb_node_next_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1315static rb_node_redo_t *rb_node_redo_new(struct parser_params *p, const YYLTYPE *loc, const YYLTYPE *keyword_loc);
1316static rb_node_def_temp_t *rb_node_def_temp_new(struct parser_params *p, const YYLTYPE *loc);
1317static rb_node_def_temp_t *def_head_save(struct parser_params *p, rb_node_def_temp_t *n);
1319#define NEW_BREAK(s,loc,k_loc) (NODE *)rb_node_break_new(p,s,loc,k_loc)
1320#define NEW_NEXT(s,loc,k_loc) (NODE *)rb_node_next_new(p,s,loc,k_loc)
1321#define NEW_REDO(loc,k_loc) (NODE *)rb_node_redo_new(p,loc,k_loc)
1322#define NEW_DEF_TEMP(loc) rb_node_def_temp_new(p,loc)
1324/* Make a new internal node, which should not be appeared in the
1325 * result AST and does not have node_id and location. */
1326static NODE* node_new_internal(struct parser_params *p, enum node_type type, size_t size, size_t alignment);
1327#define NODE_NEW_INTERNAL(ndtype, type) (type *)node_new_internal(p, (enum node_type)(ndtype), sizeof(type), RUBY_ALIGNOF(type))
1329static NODE *nd_set_loc(NODE *nd, const YYLTYPE *loc);
1332parser_get_node_id(struct parser_params *p)
1334 int node_id = p->node_id;
1340anddot_multiple_assignment_check(struct parser_params* p, const YYLTYPE *loc, ID id)
1342 if (id == tANDDOT) {
1343 yyerror1(loc, "&. inside multiple assignment destination");
1348set_line_body(NODE *body, int line)
1351 switch (nd_type(body)) {
1354 nd_set_line(body, line);
1359set_embraced_location(NODE *node, const rb_code_location_t *beg, const rb_code_location_t *end)
1361 RNODE_ITER(node)->nd_body->nd_loc = code_loc_gen(beg, end);
1362 nd_set_line(node, beg->end_pos.lineno);
1366last_expr_node(NODE *expr)
1369 if (nd_type_p(expr, NODE_BLOCK)) {
1370 expr = RNODE_BLOCK(RNODE_BLOCK(expr)->nd_end)->nd_head;
1372 else if (nd_type_p(expr, NODE_BEGIN) && RNODE_BEGIN(expr)->nd_body) {
1373 expr = RNODE_BEGIN(expr)->nd_body;
1383#define yyparse ruby_yyparse
1386static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
1387static NODE* method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
1388#define new_nil(loc) NEW_NIL(loc)
1389static NODE *new_nil_at(struct parser_params *p, const rb_code_position_t *pos);
1390static NODE *new_if(struct parser_params*,NODE*,NODE*,NODE*,const YYLTYPE*);
1391static NODE *new_unless(struct parser_params*,NODE*,NODE*,NODE*,const YYLTYPE*,const YYLTYPE*,const YYLTYPE*,const YYLTYPE*);
1392static NODE *logop(struct parser_params*,ID,NODE*,NODE*,const YYLTYPE*,const YYLTYPE*);
1394static NODE *newline_node(NODE*);
1395static void fixpos(NODE*,NODE*);
1397static int value_expr_gen(struct parser_params*,NODE*);
1398static void void_expr(struct parser_params*,NODE*);
1399static NODE *remove_begin(NODE*);
1400#define value_expr(node) value_expr_gen(p, (node))
1401static NODE *void_stmts(struct parser_params*,NODE*);
1402static void reduce_nodes(struct parser_params*,NODE**);
1403static void block_dup_check(struct parser_params*,NODE*,NODE*);
1405static NODE *block_append(struct parser_params*,NODE*,NODE*);
1406static NODE *list_append(struct parser_params*,NODE*,NODE*);
1407static NODE *list_concat(NODE*,NODE*);
1408static NODE *arg_append(struct parser_params*,NODE*,NODE*,const YYLTYPE*);
1409static NODE *last_arg_append(struct parser_params *p, NODE *args, NODE *last_arg, const YYLTYPE *loc);
1410static NODE *rest_arg_append(struct parser_params *p, NODE *args, NODE *rest_arg, const YYLTYPE *loc);
1411static NODE *literal_concat(struct parser_params*,NODE*,NODE*,const YYLTYPE*);
1412static NODE *new_evstr(struct parser_params*,NODE*,const YYLTYPE*);
1413static NODE *new_dstr(struct parser_params*,NODE*,const YYLTYPE*);
1414static NODE *str2dstr(struct parser_params*,NODE*);
1415static NODE *evstr2dstr(struct parser_params*,NODE*);
1416static NODE *splat_array(NODE*);
1417static void mark_lvar_used(struct parser_params *p, NODE *rhs);
1419static NODE *call_bin_op(struct parser_params*,NODE*,ID,NODE*,const YYLTYPE*,const YYLTYPE*);
1420static NODE *call_uni_op(struct parser_params*,NODE*,ID,const YYLTYPE*,const YYLTYPE*);
1421static NODE *new_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, const YYLTYPE *op_loc, const YYLTYPE *loc);
1422static NODE *new_command_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, NODE *block, const YYLTYPE *op_loc, const YYLTYPE *loc);
1423static NODE *method_add_block(struct parser_params*p, NODE *m, NODE *b, const YYLTYPE *loc) {RNODE_ITER(b)->nd_iter = m; b->nd_loc = *loc; return b;}
1425static bool args_info_empty_p(struct rb_args_info *args);
1426static rb_node_args_t *new_args(struct parser_params*,rb_node_args_aux_t*,rb_node_opt_arg_t*,ID,rb_node_args_aux_t*,rb_node_args_t*,const YYLTYPE*);
1427static rb_node_args_t *new_args_tail(struct parser_params*,rb_node_kw_arg_t*,ID,ID,const YYLTYPE*);
1428static NODE *new_array_pattern(struct parser_params *p, NODE *constant, NODE *pre_arg, NODE *aryptn, const YYLTYPE *loc);
1429static NODE *new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, NODE *rest_arg, NODE *post_args, const YYLTYPE *loc);
1430static NODE *new_find_pattern(struct parser_params *p, NODE *constant, NODE *fndptn, const YYLTYPE *loc);
1431static NODE *new_find_pattern_tail(struct parser_params *p, NODE *pre_rest_arg, NODE *args, NODE *post_rest_arg, const YYLTYPE *loc);
1432static NODE *new_hash_pattern(struct parser_params *p, NODE *constant, NODE *hshptn, const YYLTYPE *loc);
1433static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc);
1435static rb_node_kw_arg_t *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
1436static rb_node_args_t *args_with_numbered(struct parser_params*,rb_node_args_t*,int,ID);
1438static NODE* negate_lit(struct parser_params*, NODE*);
1439static NODE *ret_args(struct parser_params*,NODE*);
1440static NODE *arg_blk_pass(NODE*,rb_node_block_pass_t*);
1441static NODE *new_yield(struct parser_params*,NODE*,const YYLTYPE*);
1442static NODE *dsym_node(struct parser_params*,NODE*,const YYLTYPE*);
1444static NODE *gettable(struct parser_params*,ID,const YYLTYPE*);
1445static NODE *assignable(struct parser_params*,ID,NODE*,const YYLTYPE*);
1447static NODE *aryset(struct parser_params*,NODE*,NODE*,const YYLTYPE*);
1448static NODE *attrset(struct parser_params*,NODE*,ID,ID,const YYLTYPE*);
1450static VALUE rb_backref_error(struct parser_params*,NODE*);
1451static NODE *node_assign(struct parser_params*,NODE*,NODE*,struct lex_context,const YYLTYPE*);
1453static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, const YYLTYPE *loc);
1454static NODE *new_ary_op_assign(struct parser_params *p, NODE *ary, NODE *args, ID op, NODE *rhs, const YYLTYPE *args_loc, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc);
1455static NODE *new_attr_op_assign(struct parser_params *p, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc);
1456static NODE *new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, const YYLTYPE *loc);
1457static NODE *new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc);
1459static NODE *const_decl(struct parser_params *p, NODE* path, const YYLTYPE *loc);
1461static rb_node_opt_arg_t *opt_arg_append(rb_node_opt_arg_t*, rb_node_opt_arg_t*);
1462static rb_node_kw_arg_t *kwd_append(rb_node_kw_arg_t*, rb_node_kw_arg_t*);
1464static NODE *new_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc);
1465static NODE *new_unique_key_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc);
1467static NODE *new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc);
1469static NODE *new_regexp(struct parser_params *, NODE *, int, const YYLTYPE *);
1471#define make_list(list, loc) ((list) ? (nd_set_loc(list, loc), list) : NEW_ZLIST(loc))
1473static NODE *new_xstring(struct parser_params *, NODE *, const YYLTYPE *loc);
1475static NODE *symbol_append(struct parser_params *p, NODE *symbols, NODE *symbol);
1477static NODE *match_op(struct parser_params*,NODE*,NODE*,const YYLTYPE*,const YYLTYPE*);
1479static rb_ast_id_table_t *local_tbl(struct parser_params*);
1481static VALUE reg_compile(struct parser_params*, rb_parser_string_t*, int);
1482static void reg_fragment_setenc(struct parser_params*, rb_parser_string_t*, int);
1483int rb_parser_reg_fragment_check(struct parser_params*, rb_parser_string_t*, int, rb_parser_reg_fragment_error_func);
1484static void reg_fragment_error(struct parser_params *, VALUE);
1485#define reg_fragment_check(p, str, option) rb_parser_reg_fragment_check(p, str, option, reg_fragment_error)
1487static int literal_concat0(struct parser_params *p, rb_parser_string_t *head, rb_parser_string_t *tail);
1488static NODE *heredoc_dedent(struct parser_params*,NODE*);
1490static void check_literal_when(struct parser_params *p, NODE *args, const YYLTYPE *loc);
1493#define get_value(idx) (rb_ary_entry(p->s_value_stack, idx))
1494#define set_value(val) (p->s_lvalue = val)
1495static VALUE assign_error(struct parser_params *p, const char *mesg, VALUE a);
1496static int id_is_var(struct parser_params *p, ID id);
1499RUBY_SYMBOL_EXPORT_BEGIN
1500VALUE rb_parser_reg_compile(struct parser_params* p, VALUE str, int options);
1501int rb_reg_fragment_setenc(struct parser_params*, rb_parser_string_t *, int);
1502enum lex_state_e rb_parser_trace_lex_state(struct parser_params *, enum lex_state_e, enum lex_state_e, int);
1503VALUE rb_parser_lex_state_name(struct parser_params *p, enum lex_state_e state);
1504void rb_parser_show_bitstack(struct parser_params *, stack_type, const char *, int);
1505PRINTF_ARGS(void rb_parser_fatal(struct parser_params *p, const char *fmt, ...), 2, 3);
1506YYLTYPE *rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_heredoc_t *here, YYLTYPE *yylloc);
1507YYLTYPE *rb_parser_set_location_of_delayed_token(struct parser_params *p, YYLTYPE *yylloc);
1508YYLTYPE *rb_parser_set_location_of_heredoc_end(struct parser_params *p, YYLTYPE *yylloc);
1509YYLTYPE *rb_parser_set_location_of_dummy_end(struct parser_params *p, YYLTYPE *yylloc);
1510YYLTYPE *rb_parser_set_location_of_none(struct parser_params *p, YYLTYPE *yylloc);
1511YYLTYPE *rb_parser_set_location(struct parser_params *p, YYLTYPE *yylloc);
1512void ruby_show_error_line(struct parser_params *p, VALUE errbuf, const YYLTYPE *yylloc, int lineno, rb_parser_string_t *str);
1513RUBY_SYMBOL_EXPORT_END
1515static void flush_string_content(struct parser_params *p, rb_encoding *enc, size_t back);
1516static void error_duplicate_pattern_variable(struct parser_params *p, ID id, const YYLTYPE *loc);
1517static void error_duplicate_pattern_key(struct parser_params *p, ID id, const YYLTYPE *loc);
1518static VALUE formal_argument_error(struct parser_params*, ID);
1519static ID shadowing_lvar(struct parser_params*,ID);
1520static void new_bv(struct parser_params*,ID);
1522static void local_push(struct parser_params*,int);
1523static void local_pop(struct parser_params*);
1524static void local_var(struct parser_params*, ID);
1525static void arg_var(struct parser_params*, ID);
1526static int local_id(struct parser_params *p, ID id);
1527static int local_id_ref(struct parser_params*, ID, ID **);
1528#define internal_id rb_parser_internal_id
1529ID internal_id(struct parser_params*);
1530static NODE *new_args_forward_call(struct parser_params*, NODE*, const YYLTYPE*, const YYLTYPE*);
1531static int check_forwarding_args(struct parser_params*);
1532static void add_forwarding_args(struct parser_params *p);
1533static void forwarding_arg_check(struct parser_params *p, ID arg, ID all, const char *var);
1535static const struct vtable *dyna_push(struct parser_params *);
1536static void dyna_pop(struct parser_params*, const struct vtable *);
1537static int dyna_in_block(struct parser_params*);
1538#define dyna_var(p, id) local_var(p, id)
1539static int dvar_defined(struct parser_params*, ID);
1540#define dvar_defined_ref rb_parser_dvar_defined_ref
1541int dvar_defined_ref(struct parser_params*, ID, ID**);
1542static int dvar_curr(struct parser_params*,ID);
1544static int lvar_defined(struct parser_params*, ID);
1546static NODE *numparam_push(struct parser_params *p);
1547static void numparam_pop(struct parser_params *p, NODE *prev_inner);
1549#define METHOD_NOT '!'
1551#define idFWD_REST '*'
1552#define idFWD_KWREST idPow /* Use simple "**", as tDSTAR is "**arg" */
1553#define idFWD_BLOCK '&'
1554#define idFWD_ALL idDot3
1555#define arg_FWD_BLOCK idFWD_BLOCK
1557#define RE_ONIG_OPTION_IGNORECASE 1
1558#define RE_ONIG_OPTION_EXTEND (RE_ONIG_OPTION_IGNORECASE<<1)
1559#define RE_ONIG_OPTION_MULTILINE (RE_ONIG_OPTION_EXTEND<<1)
1560#define RE_OPTION_ONCE (1<<16)
1561#define RE_OPTION_ENCODING_SHIFT 8
1562#define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
1563#define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
1564#define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
1565#define RE_OPTION_MASK 0xff
1566#define RE_OPTION_ARG_ENCODING_NONE 32
1568#define CHECK_LITERAL_WHEN (st_table *)1
1569#define CASE_LABELS_ENABLED_P(case_labels) (case_labels && case_labels != CHECK_LITERAL_WHEN)
1571#define yytnamerr(yyres, yystr) (YYSIZE_T)rb_yytnamerr(p, yyres, yystr)
1572RUBY_FUNC_EXPORTED size_t rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr);
1574#define TOKEN2ID(tok) ( \
1575 tTOKEN_LOCAL_BEGIN<(tok)&&(tok)<tTOKEN_LOCAL_END ? TOKEN2LOCALID(tok) : \
1576 tTOKEN_INSTANCE_BEGIN<(tok)&&(tok)<tTOKEN_INSTANCE_END ? TOKEN2INSTANCEID(tok) : \
1577 tTOKEN_GLOBAL_BEGIN<(tok)&&(tok)<tTOKEN_GLOBAL_END ? TOKEN2GLOBALID(tok) : \
1578 tTOKEN_CONST_BEGIN<(tok)&&(tok)<tTOKEN_CONST_END ? TOKEN2CONSTID(tok) : \
1579 tTOKEN_CLASS_BEGIN<(tok)&&(tok)<tTOKEN_CLASS_END ? TOKEN2CLASSID(tok) : \
1580 tTOKEN_ATTRSET_BEGIN<(tok)&&(tok)<tTOKEN_ATTRSET_END ? TOKEN2ATTRSETID(tok) : \
1581 ((tok) / ((tok)<tPRESERVED_ID_END && ((tok)>=128 || rb_ispunct(tok)))))
1583/****** Ripper *******/
1587#include "eventids1.h"
1588#include "eventids2.h"
1590extern const struct ripper_parser_ids ripper_parser_ids;
1592static VALUE ripper_dispatch0(struct parser_params*,ID);
1593static VALUE ripper_dispatch1(struct parser_params*,ID,VALUE);
1594static VALUE ripper_dispatch2(struct parser_params*,ID,VALUE,VALUE);
1595static VALUE ripper_dispatch3(struct parser_params*,ID,VALUE,VALUE,VALUE);
1596static VALUE ripper_dispatch4(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE);
1597static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE);
1598static VALUE ripper_dispatch7(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE);
1599void ripper_error(struct parser_params *p);
1601#define dispatch0(n) ripper_dispatch0(p, RIPPER_ID(n))
1602#define dispatch1(n,a) ripper_dispatch1(p, RIPPER_ID(n), (a))
1603#define dispatch2(n,a,b) ripper_dispatch2(p, RIPPER_ID(n), (a), (b))
1604#define dispatch3(n,a,b,c) ripper_dispatch3(p, RIPPER_ID(n), (a), (b), (c))
1605#define dispatch4(n,a,b,c,d) ripper_dispatch4(p, RIPPER_ID(n), (a), (b), (c), (d))
1606#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(p, RIPPER_ID(n), (a), (b), (c), (d), (e))
1607#define dispatch7(n,a,b,c,d,e,f,g) ripper_dispatch7(p, RIPPER_ID(n), (a), (b), (c), (d), (e), (f), (g))
1609#define yyparse ripper_yyparse
1612aryptn_pre_args(struct parser_params *p, VALUE pre_arg, VALUE pre_args)
1614 if (!NIL_P(pre_arg)) {
1615 if (!NIL_P(pre_args)) {
1616 rb_ary_unshift(pre_args, pre_arg);
1619 pre_args = rb_ary_new_from_args(1, pre_arg);
1625#define ID2VAL(id) STATIC_ID2SYM(id)
1626#define TOKEN2VAL(t) ID2VAL(TOKEN2ID(t))
1629#define KWD2EID(t, v) keyword_##t
1632new_scope_body(struct parser_params *p, rb_node_args_t *args, NODE *body, const YYLTYPE *loc)
1634 body = remove_begin(body);
1635 reduce_nodes(p, &body);
1636 NODE *n = NEW_SCOPE(args, body, loc);
1637 nd_set_line(n, loc->end_pos.lineno);
1638 set_line_body(body, loc->beg_pos.lineno);
1643rescued_expr(struct parser_params *p, NODE *arg, NODE *rescue,
1644 const YYLTYPE *arg_loc, const YYLTYPE *mod_loc, const YYLTYPE *res_loc)
1646 YYLTYPE loc = code_loc_gen(mod_loc, res_loc);
1647 rescue = NEW_RESBODY(0, 0, remove_begin(rescue), 0, &loc);
1648 loc.beg_pos = arg_loc->beg_pos;
1649 return NEW_RESCUE(arg, rescue, 0, &loc);
1652static NODE *add_block_exit(struct parser_params *p, NODE *node);
1653static rb_node_exits_t *init_block_exit(struct parser_params *p);
1654static rb_node_exits_t *allow_block_exit(struct parser_params *p);
1655static void restore_block_exit(struct parser_params *p, rb_node_exits_t *exits);
1656static void clear_block_exit(struct parser_params *p, bool error);
1659next_rescue_context(struct lex_context *next, const struct lex_context *outer, enum rescue_context def)
1661 next->in_rescue = outer->in_rescue == after_rescue ? after_rescue : def;
1665restore_defun(struct parser_params *p, rb_node_def_temp_t *temp)
1667 /* See: def_name action */
1668 struct lex_context ctxt = temp->save.ctxt;
1669 p->ctxt.in_def = ctxt.in_def;
1670 p->ctxt.shareable_constant_value = ctxt.shareable_constant_value;
1671 p->ctxt.in_rescue = ctxt.in_rescue;
1672 p->max_numparam = temp->save.max_numparam;
1673 numparam_pop(p, temp->save.numparam_save);
1674 clear_block_exit(p, true);
1678endless_method_name(struct parser_params *p, ID mid, const YYLTYPE *loc)
1680 if (is_attrset_id(mid)) {
1681 yyerror1(loc, "setter method cannot be defined in an endless method definition");
1683 token_info_drop(p, "def", loc->beg_pos);
1686#define debug_token_line(p, name, line) do { \
1688 const char *const pcur = p->lex.pcur; \
1689 const char *const ptok = p->lex.ptok; \
1690 rb_parser_printf(p, name ":%d (%d: %"PRIdPTRDIFF"|%"PRIdPTRDIFF"|%"PRIdPTRDIFF")\n", \
1691 line, p->ruby_sourceline, \
1692 ptok - p->lex.pbeg, pcur - ptok, p->lex.pend - pcur); \
1696#define begin_definition(k, loc_beg, loc_end) \
1698 if (!(p->ctxt.in_class = (k)[0] != 0)) { \
1699 /* singleton class */ \
1700 p->ctxt.cant_return = !p->ctxt.in_def; \
1701 p->ctxt.in_def = 0; \
1703 else if (p->ctxt.in_def) { \
1704 YYLTYPE loc = code_loc_gen(loc_beg, loc_end); \
1705 yyerror1(&loc, k " definition in method body"); \
1708 p->ctxt.cant_return = 1; \
1714# define ifndef_ripper(x) (x)
1715# define ifdef_ripper(r,x) (x)
1717# define ifndef_ripper(x)
1718# define ifdef_ripper(r,x) (r)
1721# define rb_warn0(fmt) WARN_CALL(WARN_ARGS(fmt, 1))
1722# define rb_warn1(fmt,a) WARN_CALL(WARN_ARGS(fmt, 2), (a))
1723# define rb_warn2(fmt,a,b) WARN_CALL(WARN_ARGS(fmt, 3), (a), (b))
1724# define rb_warn3(fmt,a,b,c) WARN_CALL(WARN_ARGS(fmt, 4), (a), (b), (c))
1725# define rb_warn4(fmt,a,b,c,d) WARN_CALL(WARN_ARGS(fmt, 5), (a), (b), (c), (d))
1726# define rb_warning0(fmt) WARNING_CALL(WARNING_ARGS(fmt, 1))
1727# define rb_warning1(fmt,a) WARNING_CALL(WARNING_ARGS(fmt, 2), (a))
1728# define rb_warning2(fmt,a,b) WARNING_CALL(WARNING_ARGS(fmt, 3), (a), (b))
1729# define rb_warning3(fmt,a,b,c) WARNING_CALL(WARNING_ARGS(fmt, 4), (a), (b), (c))
1730# define rb_warning4(fmt,a,b,c,d) WARNING_CALL(WARNING_ARGS(fmt, 5), (a), (b), (c), (d))
1731# define rb_warn0L(l,fmt) WARN_CALL(WARN_ARGS_L(l, fmt, 1))
1732# define rb_warn1L(l,fmt,a) WARN_CALL(WARN_ARGS_L(l, fmt, 2), (a))
1733# define rb_warn2L(l,fmt,a,b) WARN_CALL(WARN_ARGS_L(l, fmt, 3), (a), (b))
1734# define rb_warn3L(l,fmt,a,b,c) WARN_CALL(WARN_ARGS_L(l, fmt, 4), (a), (b), (c))
1735# define rb_warn4L(l,fmt,a,b,c,d) WARN_CALL(WARN_ARGS_L(l, fmt, 5), (a), (b), (c), (d))
1736# define rb_warning0L(l,fmt) WARNING_CALL(WARNING_ARGS_L(l, fmt, 1))
1737# define rb_warning1L(l,fmt,a) WARNING_CALL(WARNING_ARGS_L(l, fmt, 2), (a))
1738# define rb_warning2L(l,fmt,a,b) WARNING_CALL(WARNING_ARGS_L(l, fmt, 3), (a), (b))
1739# define rb_warning3L(l,fmt,a,b,c) WARNING_CALL(WARNING_ARGS_L(l, fmt, 4), (a), (b), (c))
1740# define rb_warning4L(l,fmt,a,b,c,d) WARNING_CALL(WARNING_ARGS_L(l, fmt, 5), (a), (b), (c), (d))
1742extern const ID id_warn, id_warning, id_gets, id_assoc;
1743# define ERR_MESG() STR_NEW2(mesg) /* to bypass Ripper DSL */
1744# define WARN_S_L(s,l) STR_NEW(s,l)
1745# define WARN_S(s) STR_NEW2(s)
1746# define WARN_I(i) INT2NUM(i)
1747# define WARN_ID(i) rb_id2str(i)
1748# define PRIsWARN PRIsVALUE
1749# define WARN_ARGS(fmt,n) p->value, id_warn, n, rb_usascii_str_new_lit(fmt)
1750# define WARN_ARGS_L(l,fmt,n) WARN_ARGS(fmt,n)
1751# ifdef HAVE_VA_ARGS_MACRO
1752# define WARN_CALL(...) rb_funcall(__VA_ARGS__)
1754# define WARN_CALL rb_funcall
1756# define WARNING_ARGS(fmt,n) p->value, id_warning, n, rb_usascii_str_new_lit(fmt)
1757# define WARNING_ARGS_L(l, fmt,n) WARNING_ARGS(fmt,n)
1758# ifdef HAVE_VA_ARGS_MACRO
1759# define WARNING_CALL(...) rb_funcall(__VA_ARGS__)
1761# define WARNING_CALL rb_funcall
1763# define compile_error ripper_compile_error
1765# define WARN_S_L(s,l) s
1768# define WARN_ID(i) rb_id2name(i)
1769# define PRIsWARN PRIsVALUE
1770# define WARN_ARGS(fmt,n) WARN_ARGS_L(p->ruby_sourceline,fmt,n)
1771# define WARN_ARGS_L(l,fmt,n) p->ruby_sourcefile, (l), (fmt)
1772# define WARN_CALL rb_compile_warn
1773# define WARNING_ARGS(fmt,n) WARN_ARGS(fmt,n)
1774# define WARNING_ARGS_L(l,fmt,n) WARN_ARGS_L(l,fmt,n)
1775# define WARNING_CALL rb_compile_warning
1776PRINTF_ARGS(static void parser_compile_error(struct parser_params*, const rb_code_location_t *loc, const char *fmt, ...), 3, 4);
1777# define compile_error(p, ...) parser_compile_error(p, NULL, __VA_ARGS__)
1780#define RNODE_EXITS(node) ((rb_node_exits_t*)(node))
1783add_block_exit(struct parser_params *p, NODE *node)
1786 compile_error(p, "unexpected null node");
1789 switch (nd_type(node)) {
1790 case NODE_BREAK: case NODE_NEXT: case NODE_REDO: break;
1792 compile_error(p, "add_block_exit: unexpected node: %s", parser_node_name(nd_type(node)));
1795 if (!p->ctxt.in_defined) {
1796 rb_node_exits_t *exits = p->exits;
1798 RNODE_EXITS(exits->nd_stts)->nd_chain = node;
1799 exits->nd_stts = node;
1805static rb_node_exits_t *
1806init_block_exit(struct parser_params *p)
1808 rb_node_exits_t *old = p->exits;
1809 rb_node_exits_t *exits = NODE_NEW_INTERNAL(NODE_EXITS, rb_node_exits_t);
1810 exits->nd_chain = 0;
1811 exits->nd_stts = RNODE(exits);
1816static rb_node_exits_t *
1817allow_block_exit(struct parser_params *p)
1819 rb_node_exits_t *exits = p->exits;
1825restore_block_exit(struct parser_params *p, rb_node_exits_t *exits)
1831clear_block_exit(struct parser_params *p, bool error)
1833 rb_node_exits_t *exits = p->exits;
1836 for (NODE *e = RNODE(exits); (e = RNODE_EXITS(e)->nd_chain) != 0; ) {
1837 switch (nd_type(e)) {
1839 yyerror1(&e->nd_loc, "Invalid break");
1842 yyerror1(&e->nd_loc, "Invalid next");
1845 yyerror1(&e->nd_loc, "Invalid redo");
1848 yyerror1(&e->nd_loc, "unexpected node");
1849 goto end_checks; /* no nd_chain */
1854 exits->nd_stts = RNODE(exits);
1855 exits->nd_chain = 0;
1858#define WARN_EOL(tok) \
1859 (looking_at_eol_p(p) ? \
1860 (void)rb_warning0("'" tok "' at the end of line without an expression") : \
1862static int looking_at_eol_p(struct parser_params *p);
1865get_nd_value(struct parser_params *p, NODE *node)
1867 switch (nd_type(node)) {
1869 return RNODE_GASGN(node)->nd_value;
1871 return RNODE_IASGN(node)->nd_value;
1873 return RNODE_LASGN(node)->nd_value;
1875 return RNODE_DASGN(node)->nd_value;
1877 return RNODE_MASGN(node)->nd_value;
1879 return RNODE_CVASGN(node)->nd_value;
1881 return RNODE_CDECL(node)->nd_value;
1883 compile_error(p, "get_nd_value: unexpected node: %s", parser_node_name(nd_type(node)));
1889set_nd_value(struct parser_params *p, NODE *node, NODE *rhs)
1891 switch (nd_type(node)) {
1893 RNODE_CDECL(node)->nd_value = rhs;
1896 RNODE_GASGN(node)->nd_value = rhs;
1899 RNODE_IASGN(node)->nd_value = rhs;
1902 RNODE_LASGN(node)->nd_value = rhs;
1905 RNODE_DASGN(node)->nd_value = rhs;
1908 RNODE_MASGN(node)->nd_value = rhs;
1911 RNODE_CVASGN(node)->nd_value = rhs;
1914 compile_error(p, "set_nd_value: unexpected node: %s", parser_node_name(nd_type(node)));
1920get_nd_vid(struct parser_params *p, NODE *node)
1922 switch (nd_type(node)) {
1924 return RNODE_CDECL(node)->nd_vid;
1926 return RNODE_GASGN(node)->nd_vid;
1928 return RNODE_IASGN(node)->nd_vid;
1930 return RNODE_LASGN(node)->nd_vid;
1932 return RNODE_DASGN(node)->nd_vid;
1934 return RNODE_CVASGN(node)->nd_vid;
1936 compile_error(p, "get_nd_vid: unexpected node: %s", parser_node_name(nd_type(node)));
1942get_nd_args(struct parser_params *p, NODE *node)
1944 switch (nd_type(node)) {
1946 return RNODE_CALL(node)->nd_args;
1948 return RNODE_OPCALL(node)->nd_args;
1950 return RNODE_FCALL(node)->nd_args;
1952 return RNODE_QCALL(node)->nd_args;
1954 return RNODE_SUPER(node)->nd_args;
1963 compile_error(p, "get_nd_args: unexpected node: %s", parser_node_name(nd_type(node)));
1969djb2(const uint8_t *str, size_t len)
1971 st_index_t hash = 5381;
1973 for (size_t i = 0; i < len; i++) {
1974 hash = ((hash << 5) + hash) + str[i];
1981parser_memhash(const void *ptr, long len)
1983 return djb2(ptr, len);
1986#define PARSER_STRING_PTR(str) (str->ptr)
1987#define PARSER_STRING_LEN(str) (str->len)
1988#define PARSER_STRING_END(str) (&str->ptr[str->len])
1989#define STRING_SIZE(str) ((size_t)str->len + 1)
1990#define STRING_TERM_LEN(str) (1)
1991#define STRING_TERM_FILL(str) (str->ptr[str->len] = '\0')
1992#define PARSER_STRING_RESIZE_CAPA_TERM(p,str,capacity,termlen) do {\
1993 SIZED_REALLOC_N(str->ptr, char, (size_t)total + termlen, STRING_SIZE(str)); \
1996#define STRING_SET_LEN(str, n) do { \
1999#define PARSER_STRING_GETMEM(str, ptrvar, lenvar) \
2000 ((ptrvar) = str->ptr, \
2001 (lenvar) = str->len)
2004parser_string_char_at_end(struct parser_params *p, rb_parser_string_t *str, int when_empty)
2006 return PARSER_STRING_LEN(str) > 0 ? (unsigned char)PARSER_STRING_END(str)[-1] : when_empty;
2009static rb_parser_string_t *
2010rb_parser_string_new(rb_parser_t *p, const char *ptr, long len)
2012 rb_parser_string_t *str;
2015 rb_bug("negative string size (or size too big): %ld", len);
2018 str = xcalloc(1, sizeof(rb_parser_string_t));
2019 str->ptr = xcalloc(len + 1, sizeof(char));
2022 memcpy(PARSER_STRING_PTR(str), ptr, len);
2024 STRING_SET_LEN(str, len);
2025 STRING_TERM_FILL(str);
2029static rb_parser_string_t *
2030rb_parser_encoding_string_new(rb_parser_t *p, const char *ptr, long len, rb_encoding *enc)
2032 rb_parser_string_t *str = rb_parser_string_new(p, ptr, len);
2033 str->coderange = RB_PARSER_ENC_CODERANGE_UNKNOWN;
2040rb_str_to_parser_string(rb_parser_t *p, VALUE str)
2043 rb_parser_string_t *ret = rb_parser_encoding_string_new(p, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
2049rb_parser_string_free(rb_parser_t *p, rb_parser_string_t *str)
2052 xfree(PARSER_STRING_PTR(str));
2058rb_parser_str_hash(rb_parser_string_t *str)
2060 return parser_memhash((const void *)PARSER_STRING_PTR(str), PARSER_STRING_LEN(str));
2064rb_char_p_hash(const char *c)
2066 return parser_memhash((const void *)c, strlen(c));
2070rb_parser_str_capacity(rb_parser_string_t *str, const int termlen)
2072 return PARSER_STRING_LEN(str);
2077rb_parser_string_end(rb_parser_string_t *str)
2079 return &str->ptr[str->len];
2084rb_parser_string_set_encoding(rb_parser_string_t *str, rb_encoding *enc)
2090rb_parser_str_get_encoding(rb_parser_string_t *str)
2097PARSER_ENCODING_IS_ASCII8BIT(struct parser_params *p, rb_parser_string_t *str)
2099 return rb_parser_str_get_encoding(str) == rb_ascii8bit_encoding();
2104PARSER_ENC_CODERANGE(rb_parser_string_t *str)
2106 return str->coderange;
2110PARSER_ENC_CODERANGE_SET(rb_parser_string_t *str, int coderange)
2112 str->coderange = coderange;
2116PARSER_ENCODING_CODERANGE_SET(rb_parser_string_t *str, rb_encoding *enc, enum rb_parser_string_coderange_type cr)
2118 rb_parser_string_set_encoding(str, enc);
2119 PARSER_ENC_CODERANGE_SET(str, cr);
2123PARSER_ENC_CODERANGE_CLEAR(rb_parser_string_t *str)
2125 str->coderange = RB_PARSER_ENC_CODERANGE_UNKNOWN;
2129PARSER_ENC_CODERANGE_ASCIIONLY(rb_parser_string_t *str)
2131 return PARSER_ENC_CODERANGE(str) == RB_PARSER_ENC_CODERANGE_7BIT;
2135PARSER_ENC_CODERANGE_CLEAN_P(int cr)
2137 return cr == RB_PARSER_ENC_CODERANGE_7BIT || cr == RB_PARSER_ENC_CODERANGE_VALID;
2141rb_parser_search_nonascii(const char *p, const char *e)
2145 for (; s < e; s++) {
2146 if (*s & 0x80) return s;
2153rb_parser_coderange_scan(struct parser_params *p, const char *ptr, long len, rb_encoding *enc)
2155 const char *e = ptr + len;
2157 if (enc == rb_ascii8bit_encoding()) {
2158 /* enc is ASCII-8BIT. ASCII-8BIT string never be broken. */
2159 ptr = rb_parser_search_nonascii(ptr, e);
2160 return ptr ? RB_PARSER_ENC_CODERANGE_VALID : RB_PARSER_ENC_CODERANGE_7BIT;
2163 /* parser string encoding is always asciicompat */
2164 ptr = rb_parser_search_nonascii(ptr, e);
2165 if (!ptr) return RB_PARSER_ENC_CODERANGE_7BIT;
2167 int ret = rb_enc_precise_mbclen(ptr, e, enc);
2168 if (!MBCLEN_CHARFOUND_P(ret)) return RB_PARSER_ENC_CODERANGE_BROKEN;
2169 ptr += MBCLEN_CHARFOUND_LEN(ret);
2170 if (ptr == e) break;
2171 ptr = rb_parser_search_nonascii(ptr, e);
2175 return RB_PARSER_ENC_CODERANGE_VALID;
2179rb_parser_enc_coderange_scan(struct parser_params *p, rb_parser_string_t *str, rb_encoding *enc)
2181 return rb_parser_coderange_scan(p, PARSER_STRING_PTR(str), PARSER_STRING_LEN(str), enc);
2185rb_parser_enc_str_coderange(struct parser_params *p, rb_parser_string_t *str)
2187 int cr = PARSER_ENC_CODERANGE(str);
2189 if (cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2190 cr = rb_parser_enc_coderange_scan(p, str, rb_parser_str_get_encoding(str));
2191 PARSER_ENC_CODERANGE_SET(str, cr);
2197static rb_parser_string_t *
2198rb_parser_enc_associate(struct parser_params *p, rb_parser_string_t *str, rb_encoding *enc)
2200 if (rb_parser_str_get_encoding(str) == enc)
2202 if (!PARSER_ENC_CODERANGE_ASCIIONLY(str)) {
2203 PARSER_ENC_CODERANGE_CLEAR(str);
2205 rb_parser_string_set_encoding(str, enc);
2210rb_parser_is_ascii_string(struct parser_params *p, rb_parser_string_t *str)
2212 return rb_parser_enc_str_coderange(p, str) == RB_PARSER_ENC_CODERANGE_7BIT;
2216rb_parser_enc_compatible(struct parser_params *p, rb_parser_string_t *str1, rb_parser_string_t *str2)
2218 rb_encoding *enc1 = rb_parser_str_get_encoding(str1);
2219 rb_encoding *enc2 = rb_parser_str_get_encoding(str2);
2221 if (enc1 == NULL || enc2 == NULL)
2228 if (PARSER_STRING_LEN(str2) == 0)
2230 if (PARSER_STRING_LEN(str1) == 0)
2231 return rb_parser_is_ascii_string(p, str2) ? enc1 : enc2;
2235 cr1 = rb_parser_enc_str_coderange(p, str1);
2236 cr2 = rb_parser_enc_str_coderange(p, str2);
2239 if (cr1 == RB_PARSER_ENC_CODERANGE_7BIT) return enc2;
2240 if (cr2 == RB_PARSER_ENC_CODERANGE_7BIT) return enc1;
2243 if (cr2 == RB_PARSER_ENC_CODERANGE_7BIT) {
2247 if (cr1 == RB_PARSER_ENC_CODERANGE_7BIT) {
2255rb_parser_str_modify(rb_parser_string_t *str)
2257 PARSER_ENC_CODERANGE_CLEAR(str);
2261rb_parser_str_set_len(struct parser_params *p, rb_parser_string_t *str, long len)
2264 const int termlen = STRING_TERM_LEN(str);
2266 if (len > (capa = (long)(rb_parser_str_capacity(str, termlen))) || len < 0) {
2267 rb_bug("probable buffer overflow: %ld for %ld", len, capa);
2270 int cr = PARSER_ENC_CODERANGE(str);
2271 if (cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2272 /* Leave unknown. */
2274 else if (len > PARSER_STRING_LEN(str)) {
2275 PARSER_ENC_CODERANGE_SET(str, RB_PARSER_ENC_CODERANGE_UNKNOWN);
2277 else if (len < PARSER_STRING_LEN(str)) {
2278 if (cr != RB_PARSER_ENC_CODERANGE_7BIT) {
2279 /* ASCII-only string is keeping after truncated. Valid
2280 * and broken may be invalid or valid, leave unknown. */
2281 PARSER_ENC_CODERANGE_SET(str, RB_PARSER_ENC_CODERANGE_UNKNOWN);
2285 STRING_SET_LEN(str, len);
2286 STRING_TERM_FILL(str);
2289static rb_parser_string_t *
2290rb_parser_str_buf_cat(struct parser_params *p, rb_parser_string_t *str, const char *ptr, long len)
2292 rb_parser_str_modify(str);
2293 if (len == 0) return 0;
2295 long total, olen, off = -1;
2297 const int termlen = STRING_TERM_LEN(str);
2299 PARSER_STRING_GETMEM(str, sptr, olen);
2300 if (ptr >= sptr && ptr <= sptr + olen) {
2304 if (olen > LONG_MAX - len) {
2305 compile_error(p, "string sizes too big");
2309 PARSER_STRING_RESIZE_CAPA_TERM(p, str, total, termlen);
2310 sptr = PARSER_STRING_PTR(str);
2314 memcpy(sptr + olen, ptr, len);
2315 STRING_SET_LEN(str, total);
2316 STRING_TERM_FILL(str);
2321#define parser_str_cat(str, ptr, len) rb_parser_str_buf_cat(p, str, ptr, len)
2322#define parser_str_cat_cstr(str, lit) rb_parser_str_buf_cat(p, str, lit, strlen(lit))
2324static rb_parser_string_t *
2325rb_parser_enc_cr_str_buf_cat(struct parser_params *p, rb_parser_string_t *str, const char *ptr, long len,
2326 rb_encoding *ptr_enc, int ptr_cr, int *ptr_cr_ret)
2329 rb_encoding *str_enc, *res_enc;
2331 str_enc = rb_parser_str_get_encoding(str);
2332 str_cr = PARSER_STRING_LEN(str) ? PARSER_ENC_CODERANGE(str) : RB_PARSER_ENC_CODERANGE_7BIT;
2334 if (str_enc == ptr_enc) {
2335 if (str_cr != RB_PARSER_ENC_CODERANGE_UNKNOWN && ptr_cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2336 ptr_cr = rb_parser_coderange_scan(p, ptr, len, ptr_enc);
2340 /* parser string encoding is always asciicompat */
2341 if (ptr_cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2342 ptr_cr = rb_parser_coderange_scan(p, ptr, len, ptr_enc);
2344 if (str_cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2345 if (str_enc == rb_ascii8bit_encoding() || ptr_cr != RB_PARSER_ENC_CODERANGE_7BIT) {
2346 str_cr = rb_parser_enc_str_coderange(p, str);
2351 *ptr_cr_ret = ptr_cr;
2353 if (str_enc != ptr_enc &&
2354 str_cr != RB_PARSER_ENC_CODERANGE_7BIT &&
2355 ptr_cr != RB_PARSER_ENC_CODERANGE_7BIT) {
2359 if (str_cr == RB_PARSER_ENC_CODERANGE_UNKNOWN) {
2361 res_cr = RB_PARSER_ENC_CODERANGE_UNKNOWN;
2363 else if (str_cr == RB_PARSER_ENC_CODERANGE_7BIT) {
2364 if (ptr_cr == RB_PARSER_ENC_CODERANGE_7BIT) {
2366 res_cr = RB_PARSER_ENC_CODERANGE_7BIT;
2373 else if (str_cr == RB_PARSER_ENC_CODERANGE_VALID) {
2375 if (PARSER_ENC_CODERANGE_CLEAN_P(ptr_cr))
2380 else { /* str_cr == RB_PARSER_ENC_CODERANGE_BROKEN */
2383 if (0 < len) res_cr = RB_PARSER_ENC_CODERANGE_UNKNOWN;
2387 compile_error(p, "negative string size (or size too big)");
2389 parser_str_cat(str, ptr, len);
2390 PARSER_ENCODING_CODERANGE_SET(str, res_enc, res_cr);
2394 compile_error(p, "incompatible character encodings: %s and %s",
2395 rb_enc_name(str_enc), rb_enc_name(ptr_enc));
2396 UNREACHABLE_RETURN(0);
2400static rb_parser_string_t *
2401rb_parser_enc_str_buf_cat(struct parser_params *p, rb_parser_string_t *str, const char *ptr, long len,
2402 rb_encoding *ptr_enc)
2404 return rb_parser_enc_cr_str_buf_cat(p, str, ptr, len, ptr_enc, RB_PARSER_ENC_CODERANGE_UNKNOWN, NULL);
2407static rb_parser_string_t *
2408rb_parser_str_buf_append(struct parser_params *p, rb_parser_string_t *str, rb_parser_string_t *str2)
2410 int str2_cr = rb_parser_enc_str_coderange(p, str2);
2412 rb_parser_enc_cr_str_buf_cat(p, str, PARSER_STRING_PTR(str2), PARSER_STRING_LEN(str2),
2413 rb_parser_str_get_encoding(str2), str2_cr, &str2_cr);
2415 PARSER_ENC_CODERANGE_SET(str2, str2_cr);
2420static rb_parser_string_t *
2421rb_parser_str_resize(struct parser_params *p, rb_parser_string_t *str, long len)
2424 rb_bug("negative string size (or size too big)");
2427 long slen = PARSER_STRING_LEN(str);
2429 if (slen > len && PARSER_ENC_CODERANGE(str) != RB_PARSER_ENC_CODERANGE_7BIT) {
2430 PARSER_ENC_CODERANGE_CLEAR(str);
2435 const int termlen = STRING_TERM_LEN(str);
2437 if ((capa = slen) < len) {
2438 SIZED_REALLOC_N(str->ptr, char, (size_t)len + termlen, STRING_SIZE(str));
2440 else if (len == slen) return str;
2441 STRING_SET_LEN(str, len);
2442 STRING_TERM_FILL(str);
2447# define PARSER_ENC_STRING_GETMEM(str, ptrvar, lenvar, encvar) \
2448 ((ptrvar) = str->ptr, \
2449 (lenvar) = str->len, \
2450 (encvar) = str->enc)
2453rb_parser_string_hash_cmp(rb_parser_string_t *str1, rb_parser_string_t *str2)
2456 const char *ptr1, *ptr2;
2457 rb_encoding *enc1, *enc2;
2459 PARSER_ENC_STRING_GETMEM(str1, ptr1, len1, enc1);
2460 PARSER_ENC_STRING_GETMEM(str2, ptr2, len2, enc2);
2462 return (len1 != len2 ||
2464 memcmp(ptr1, ptr2, len1) != 0);
2468rb_parser_ary_extend(rb_parser_t *p, rb_parser_ary_t *ary, long len)
2471 if (ary->capa < len) {
2473 ary->data = (rb_parser_ary_data *)xrealloc(ary->data, sizeof(rb_parser_ary_data) * len);
2474 for (i = ary->len; i < len; i++) {
2481 * Do not call this directly.
2482 * Use rb_parser_ary_new_capa_for_XXX() instead.
2484static rb_parser_ary_t *
2485parser_ary_new_capa(rb_parser_t *p, long len)
2488 rb_bug("negative array size (or size too big): %ld", len);
2490 rb_parser_ary_t *ary = xcalloc(1, sizeof(rb_parser_ary_t));
2495 ary->data = (rb_parser_ary_data *)xcalloc(len, sizeof(rb_parser_ary_data));
2504static rb_parser_ary_t *
2505rb_parser_ary_new_capa_for_script_line(rb_parser_t *p, long len)
2507 rb_parser_ary_t *ary = parser_ary_new_capa(p, len);
2508 ary->data_type = PARSER_ARY_DATA_SCRIPT_LINE;
2512static rb_parser_ary_t *
2513rb_parser_ary_new_capa_for_ast_token(rb_parser_t *p, long len)
2515 rb_parser_ary_t *ary = parser_ary_new_capa(p, len);
2516 ary->data_type = PARSER_ARY_DATA_AST_TOKEN;
2521static rb_parser_ary_t *
2522rb_parser_ary_new_capa_for_node(rb_parser_t *p, long len)
2524 rb_parser_ary_t *ary = parser_ary_new_capa(p, len);
2525 ary->data_type = PARSER_ARY_DATA_NODE;
2530 * Do not call this directly.
2531 * Use rb_parser_ary_push_XXX() instead.
2533static rb_parser_ary_t *
2534parser_ary_push(rb_parser_t *p, rb_parser_ary_t *ary, rb_parser_ary_data val)
2536 if (ary->len == ary->capa) {
2537 rb_parser_ary_extend(p, ary, ary->len == 0 ? 1 : ary->len * 2);
2539 ary->data[ary->len++] = val;
2544static rb_parser_ary_t *
2545rb_parser_ary_push_ast_token(rb_parser_t *p, rb_parser_ary_t *ary, rb_parser_ast_token_t *val)
2547 if (ary->data_type != PARSER_ARY_DATA_AST_TOKEN) {
2548 rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
2550 return parser_ary_push(p, ary, val);
2553static rb_parser_ary_t *
2554rb_parser_ary_push_script_line(rb_parser_t *p, rb_parser_ary_t *ary, rb_parser_string_t *val)
2556 if (ary->data_type != PARSER_ARY_DATA_SCRIPT_LINE) {
2557 rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
2559 return parser_ary_push(p, ary, val);
2563static rb_parser_ary_t *
2564rb_parser_ary_push_node(rb_parser_t *p, rb_parser_ary_t *ary, NODE *val)
2566 if (ary->data_type != PARSER_ARY_DATA_NODE) {
2567 rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
2569 return parser_ary_push(p, ary, val);
2574rb_parser_ast_token_free(rb_parser_t *p, rb_parser_ast_token_t *token)
2577 rb_parser_string_free(p, token->str);
2582rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
2584# define foreach_ary(ptr) \
2585 for (rb_parser_ary_data *ptr = ary->data, *const end_ary_data = ptr + ary->len; \
2586 ptr < end_ary_data; ptr++)
2587 switch (ary->data_type) {
2588 case PARSER_ARY_DATA_AST_TOKEN:
2589 foreach_ary(data) {rb_parser_ast_token_free(p, *data);}
2591 case PARSER_ARY_DATA_SCRIPT_LINE:
2592 foreach_ary(data) {rb_parser_string_free(p, *data);}
2594 case PARSER_ARY_DATA_NODE:
2595 /* Do nothing because nodes are freed when rb_ast_t is freed */
2598 rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
2611%define parse.error verbose
2613 if ((NODE *)$$ == (NODE *)-1) {
2614 rb_parser_printf(p, "NODE_SPECIAL");
2617 rb_parser_printf(p, "%s", parser_node_name(nd_type(RNODE($$))));
2619} <node> <node_fcall> <node_args> <node_args_aux> <node_opt_arg>
2620 <node_kw_arg> <node_block_pass> <node_masgn> <node_def_temp> <node_exits>
2622 rb_parser_printf(p, "%"PRIsVALUE, rb_id2str($$));
2625 switch (nd_type(RNODE($$))) {
2627 rb_parser_printf(p, "%+"PRIsVALUE, rb_node_integer_literal_val($$));
2630 rb_parser_printf(p, "%+"PRIsVALUE, rb_node_float_literal_val($$));
2633 rb_parser_printf(p, "%+"PRIsVALUE, rb_node_rational_literal_val($$));
2635 case NODE_IMAGINARY:
2636 rb_parser_printf(p, "%+"PRIsVALUE, rb_node_imaginary_literal_val($$));
2641} tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR
2643 rb_parser_printf(p, "$%ld", RNODE_NTH_REF($$)->nd_nth);
2646 rb_parser_printf(p, "$%c", (int)RNODE_BACK_REF($$)->nd_nth);
2650 if (CASE_LABELS_ENABLED_P($$)) st_free_table($$);
2653%lex-param {struct parser_params *p}
2654%parse-param {struct parser_params *p}
2657 RUBY_SET_YYLLOC_OF_NONE(@$);
2659%after-shift after_shift
2660%before-reduce before_reduce
2661%after-reduce after_reduce
2662%after-shift-error-token after_shift_error_token
2663%after-pop-stack after_pop_stack
2667 rb_node_fcall_t *node_fcall;
2668 rb_node_args_t *node_args;
2669 rb_node_args_aux_t *node_args_aux;
2670 rb_node_opt_arg_t *node_opt_arg;
2671 rb_node_kw_arg_t *node_kw_arg;
2672 rb_node_block_pass_t *node_block_pass;
2673 rb_node_masgn_t *node_masgn;
2674 rb_node_def_temp_t *node_def_temp;
2675 rb_node_exits_t *node_exits;
2680 const struct vtable *vars;
2681 struct rb_strterm_struct *strterm;
2682 struct lex_context ctxt;
2683 enum lex_state_e state;
2687 keyword_class "'class'"
2688 keyword_module "'module'"
2690 keyword_undef "'undef'"
2691 keyword_begin "'begin'"
2692 keyword_rescue "'rescue'"
2693 keyword_ensure "'ensure'"
2696 keyword_unless "'unless'"
2697 keyword_then "'then'"
2698 keyword_elsif "'elsif'"
2699 keyword_else "'else'"
2700 keyword_case "'case'"
2701 keyword_when "'when'"
2702 keyword_while "'while'"
2703 keyword_until "'until'"
2705 keyword_break "'break'"
2706 keyword_next "'next'"
2707 keyword_redo "'redo'"
2708 keyword_retry "'retry'"
2711 keyword_do_cond "'do' for condition"
2712 keyword_do_block "'do' for block"
2713 keyword_do_LAMBDA "'do' for lambda"
2714 keyword_return "'return'"
2715 keyword_yield "'yield'"
2716 keyword_super "'super'"
2717 keyword_self "'self'"
2719 keyword_true "'true'"
2720 keyword_false "'false'"
2724 modifier_if "'if' modifier"
2725 modifier_unless "'unless' modifier"
2726 modifier_while "'while' modifier"
2727 modifier_until "'until' modifier"
2728 modifier_rescue "'rescue' modifier"
2729 keyword_alias "'alias'"
2730 keyword_defined "'defined?'"
2731 keyword_BEGIN "'BEGIN'"
2733 keyword__LINE__ "'__LINE__'"
2734 keyword__FILE__ "'__FILE__'"
2735 keyword__ENCODING__ "'__ENCODING__'"
2737%token <id> tIDENTIFIER "local variable or method"
2738%token <id> tFID "method"
2739%token <id> tGVAR "global variable"
2740%token <id> tIVAR "instance variable"
2741%token <id> tCONSTANT "constant"
2742%token <id> tCVAR "class variable"
2743%token <id> tLABEL "label"
2744%token <node> tINTEGER "integer literal"
2745%token <node> tFLOAT "float literal"
2746%token <node> tRATIONAL "rational literal"
2747%token <node> tIMAGINARY "imaginary literal"
2748%token <node> tCHAR "char literal"
2749%token <node> tNTH_REF "numbered reference"
2750%token <node> tBACK_REF "back reference"
2751%token <node> tSTRING_CONTENT "literal content"
2752%token <num> tREGEXP_END
2753%token <num> tDUMNY_END "dummy end"
2755%type <node> singleton strings string string1 xstring regexp
2756%type <node> string_contents xstring_contents regexp_contents string_content
2757%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
2758%type <node> literal numeric simple_numeric ssym dsym symbol cpath
2759%type <node_def_temp> defn_head defs_head k_def
2760%type <node_exits> block_open k_while k_until k_for allow_exits
2761%type <node> top_compstmt top_stmts top_stmt begin_block endless_arg endless_command
2762%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
2763%type <node> expr_value expr_value_do arg_value primary_value rel_expr
2764%type <node_fcall> fcall
2765%type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure
2766%type <node> args arg_splat call_args opt_call_args
2767%type <node> paren_args opt_paren_args
2768%type <node_args> args_tail block_args_tail
2769%type <node> command_args aref_args
2770%type <node_block_pass> opt_block_arg block_arg
2771%type <node> var_ref var_lhs
2772%type <node> command_rhs arg_rhs
2773%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
2774%type <node_args> f_arglist f_opt_paren_args f_paren_args f_args
2775%type <node_args_aux> f_arg f_arg_item
2776%type <node> f_marg f_marg_list f_rest_marg
2777%type <node_masgn> f_margs
2778%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
2779%type <node_args> block_param opt_block_param block_param_def
2780%type <node_kw_arg> f_kw f_block_kw
2781%type <id> bv_decls opt_bv_decl bvar
2782%type <node> lambda lambda_body brace_body do_body
2783%type <node_args> f_larglist
2784%type <node> brace_block cmd_brace_block do_block lhs none fitem
2785%type <node> mlhs_head mlhs_item mlhs_node mlhs_post
2786%type <node_masgn> mlhs mlhs_basic mlhs_inner
2787%type <node> p_case_body p_cases p_top_expr p_top_expr_body
2788%type <node> p_expr p_as p_alt p_expr_basic p_find
2789%type <node> p_args p_args_head p_args_tail p_args_post p_arg p_rest
2790%type <node> p_value p_primitive p_variable p_var_ref p_expr_ref p_const
2791%type <node> p_kwargs p_kwarg p_kw
2792%type <id> keyword_variable user_variable sym operation operation2 operation3
2793%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
2794%type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon
2795%type <id> p_kwrest p_kwnorest p_any_kwrest p_kw_label
2796%type <id> f_no_kwarg f_any_kwrest args_forward excessed_comma nonlocal_var def_name
2797%type <ctxt> lex_ctxt begin_defined k_class k_module k_END k_rescue k_ensure after_rescue
2798%type <ctxt> p_in_kwarg
2799%type <tbl> p_lparen p_lbracket p_pktbl p_pvtbl
2800%type <num> max_numparam
2801%type <node> numparam
2803%token END_OF_INPUT 0 "end-of-input"
2806/* escaped chars, should be ignored otherwise */
2807%token <id> '\\' "backslash"
2808%token tSP "escaped space"
2809%token <id> '\t' "escaped horizontal tab"
2810%token <id> '\f' "escaped form feed"
2811%token <id> '\r' "escaped carriage return"
2812%token <id> '\13' "escaped vertical tab"
2813%token tUPLUS RUBY_TOKEN(UPLUS) "unary+"
2814%token tUMINUS RUBY_TOKEN(UMINUS) "unary-"
2815%token tPOW RUBY_TOKEN(POW) "**"
2816%token tCMP RUBY_TOKEN(CMP) "<=>"
2817%token tEQ RUBY_TOKEN(EQ) "=="
2818%token tEQQ RUBY_TOKEN(EQQ) "==="
2819%token tNEQ RUBY_TOKEN(NEQ) "!="
2820%token tGEQ RUBY_TOKEN(GEQ) ">="
2821%token tLEQ RUBY_TOKEN(LEQ) "<="
2822%token tANDOP RUBY_TOKEN(ANDOP) "&&"
2823%token tOROP RUBY_TOKEN(OROP) "||"
2824%token tMATCH RUBY_TOKEN(MATCH) "=~"
2825%token tNMATCH RUBY_TOKEN(NMATCH) "!~"
2826%token tDOT2 RUBY_TOKEN(DOT2) ".."
2827%token tDOT3 RUBY_TOKEN(DOT3) "..."
2828%token tBDOT2 RUBY_TOKEN(BDOT2) "(.."
2829%token tBDOT3 RUBY_TOKEN(BDOT3) "(..."
2830%token tAREF RUBY_TOKEN(AREF) "[]"
2831%token tASET RUBY_TOKEN(ASET) "[]="
2832%token tLSHFT RUBY_TOKEN(LSHFT) "<<"
2833%token tRSHFT RUBY_TOKEN(RSHFT) ">>"
2834%token <id> tANDDOT RUBY_TOKEN(ANDDOT) "&."
2835%token <id> tCOLON2 RUBY_TOKEN(COLON2) "::"
2836%token tCOLON3 ":: at EXPR_BEG"
2837%token <id> tOP_ASGN "operator-assignment" /* +=, -= etc. */
2840%token tLPAREN_ARG "( arg"
2844%token tLBRACE_ARG "{ arg"
2846%token tDSTAR "**arg"
2848%token <num> tLAMBDA "->"
2849%token tSYMBEG "symbol literal"
2850%token tSTRING_BEG "string literal"
2851%token tXSTRING_BEG "backtick literal"
2852%token tREGEXP_BEG "regexp literal"
2853%token tWORDS_BEG "word list"
2854%token tQWORDS_BEG "verbatim word list"
2855%token tSYMBOLS_BEG "symbol list"
2856%token tQSYMBOLS_BEG "verbatim symbol list"
2857%token tSTRING_END "terminator"
2858%token tSTRING_DEND "'}'"
2859%token <state> tSTRING_DBEG "'#{'"
2860%token tSTRING_DVAR tLAMBEG tLABEL_END
2862%token tIGNORED_NL tCOMMENT tEMBDOC_BEG tEMBDOC tEMBDOC_END
2863%token tHEREDOC_BEG tHEREDOC_END k__END__
2870%nonassoc tLBRACE_ARG
2872%nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in
2873%left keyword_or keyword_and
2875%nonassoc keyword_defined
2877%left modifier_rescue
2879%nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
2882%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
2883%left '>' tGEQ '<' tLEQ
2889%right tUMINUS_NUM tUMINUS
2891%right '!' '~' tUPLUS
2898%rule %inline ident_or_const
2903%rule %inline user_or_keyword_variable
2909 * parameterizing rules
2911%rule f_opt(value) <node_opt_arg>
2912 : f_arg_asgn f_eq value
2914 p->ctxt.in_argdef = 1;
2915 $$ = NEW_OPT_ARG(assignable(p, $1, $3, &@$), &@$);
2916 /*% ripper: [$:$, $:3] %*/
2920%rule f_optarg(value) <node_opt_arg>
2924 /*% ripper: rb_ary_new3(1, $:1) %*/
2926 | f_optarg(value) ',' f_opt(value)
2928 $$ = opt_arg_append($1, $3);
2929 /*% ripper: rb_ary_push($:1, $:3) %*/
2933%rule f_kwarg(kw) <node_kw_arg>
2937 /*% ripper: rb_ary_new3(1, $:1) %*/
2939 | f_kwarg(kw) ',' kw
2941 $$ = kwd_append($1, $3);
2942 /*% ripper: rb_ary_push($:1, $:3) %*/
2946%rule opt_args_tail(tail) <node_args>
2954 $$ = new_args_tail(p, 0, 0, 0, &@0);
2955 /*% ripper: [Qnil, Qnil, Qnil] %*/
2959%rule words(begin, word_list)
2960 : begin ' '+ word_list tSTRING_END
2962 $$ = make_list($3, &@$);
2963 /*% ripper: array!($:3) %*/
2969 SET_LEX_STATE(EXPR_BEG);
2970 local_push(p, ifndef_ripper(1)+0);
2971 /* jumps are possible in the top-level loop. */
2972 if (!ifndef_ripper(p->do_loop) + 0) init_block_exit(p);
2976 if ($2 && !compile_for_eval) {
2978 /* last expression should not be void */
2979 if (nd_type_p(node, NODE_BLOCK)) {
2980 while (RNODE_BLOCK(node)->nd_next) {
2981 node = RNODE_BLOCK(node)->nd_next;
2983 node = RNODE_BLOCK(node)->nd_head;
2985 node = remove_begin(node);
2988 p->eval_tree = NEW_SCOPE(0, block_append(p, p->eval_tree, $2), &@$);
2989 /*% ripper[final]: program!($:2) %*/
2994top_compstmt : top_stmts terms?
2996 void_stmts(p, $$ = $1);
3002 $$ = NEW_BEGIN(0, &@$);
3003 /*% ripper: stmts_add!(stmts_new!, void_stmt!) %*/
3007 $$ = newline_node($1);
3008 /*% ripper: stmts_add!(stmts_new!, $:1) %*/
3010 | top_stmts terms top_stmt
3012 $$ = block_append(p, $1, newline_node($3));
3013 /*% ripper: stmts_add!($:1, $:3) %*/
3019 clear_block_exit(p, true);
3022 | keyword_BEGIN begin_block
3029block_open : '{' {$$ = init_block_exit(p);};
3031begin_block : block_open top_compstmt '}'
3033 restore_block_exit(p, $block_open);
3034 p->eval_tree_begin = block_append(p, p->eval_tree_begin,
3035 NEW_BEGIN($2, &@$));
3036 $$ = NEW_BEGIN(0, &@$);
3037 /*% ripper: BEGIN!($:2) %*/
3041bodystmt : compstmt[body]
3046 if (!$opt_rescue) yyerror1(&@k_else, "else without rescue is useless");
3047 next_rescue_context(&p->ctxt, &$ctxt, after_else);
3051 next_rescue_context(&p->ctxt, &$ctxt, after_ensure);
3055 $$ = new_bodystmt(p, $body, $opt_rescue, $elsebody, $opt_ensure, &@$);
3056 /*% ripper: bodystmt!($:body, $:opt_rescue, $:elsebody, $:opt_ensure) %*/
3062 next_rescue_context(&p->ctxt, &$ctxt, after_ensure);
3066 $$ = new_bodystmt(p, $body, $opt_rescue, 0, $opt_ensure, &@$);
3067 /*% ripper: bodystmt!($:body, $:opt_rescue, Qnil, $:opt_ensure) %*/
3071compstmt : stmts terms?
3073 void_stmts(p, $$ = $1);
3079 $$ = NEW_BEGIN(0, &@$);
3080 /*% ripper: stmts_add!(stmts_new!, void_stmt!) %*/
3084 $$ = newline_node($1);
3085 /*% ripper: stmts_add!(stmts_new!, $:1) %*/
3087 | stmts terms stmt_or_begin
3089 $$ = block_append(p, $1, newline_node($3));
3090 /*% ripper: stmts_add!($:1, $:3) %*/
3100 yyerror1(&@1, "BEGIN is permitted only at toplevel");
3108allow_exits : {$$ = allow_block_exit(p);};
3110k_END : keyword_END lex_ctxt
3113 p->ctxt.in_rescue = before_rescue;
3117stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
3119 $$ = NEW_ALIAS($2, $4, &@$, &@1);
3120 /*% ripper: alias!($:2, $:4) %*/
3122 | keyword_alias tGVAR tGVAR
3124 $$ = NEW_VALIAS($2, $3, &@$, &@1);
3125 /*% ripper: var_alias!($:2, $:3) %*/
3127 | keyword_alias tGVAR tBACK_REF
3131 buf[1] = (char)RNODE_BACK_REF($3)->nd_nth;
3132 $$ = NEW_VALIAS($2, rb_intern2(buf, 2), &@$, &@1);
3133 /*% ripper: var_alias!($:2, $:3) %*/
3135 | keyword_alias tGVAR tNTH_REF
3137 static const char mesg[] = "can't make alias for the number variables";
3139 yyerror1(&@3, mesg);
3141 $$ = NEW_ERROR(&@$);
3142 /*% ripper[error]: alias_error!(ERR_MESG(), $:3) %*/
3144 | keyword_undef undef_list
3146 nd_set_first_loc($2, @1.beg_pos);
3147 RNODE_UNDEF($2)->keyword_loc = @1;
3149 /*% ripper: undef!($:2) %*/
3151 | stmt modifier_if expr_value
3153 $$ = new_if(p, $3, remove_begin($1), 0, &@$);
3155 /*% ripper: if_mod!($:3, $:1) %*/
3157 | stmt modifier_unless expr_value
3159 $$ = new_unless(p, $3, remove_begin($1), 0, &@$, &@2, &NULL_LOC, &NULL_LOC);
3161 /*% ripper: unless_mod!($:3, $:1) %*/
3163 | stmt modifier_while expr_value
3165 clear_block_exit(p, false);
3166 if ($1 && nd_type_p($1, NODE_BEGIN)) {
3167 $$ = NEW_WHILE(cond(p, $3, &@3), RNODE_BEGIN($1)->nd_body, 0, &@$, &@2, &NULL_LOC);
3170 $$ = NEW_WHILE(cond(p, $3, &@3), $1, 1, &@$, &@2, &NULL_LOC);
3172 /*% ripper: while_mod!($:3, $:1) %*/
3174 | stmt modifier_until expr_value
3176 clear_block_exit(p, false);
3177 if ($1 && nd_type_p($1, NODE_BEGIN)) {
3178 $$ = NEW_UNTIL(cond(p, $3, &@3), RNODE_BEGIN($1)->nd_body, 0, &@$, &@2, &NULL_LOC);
3181 $$ = NEW_UNTIL(cond(p, $3, &@3), $1, 1, &@$, &@2, &NULL_LOC);
3183 /*% ripper: until_mod!($:3, $:1) %*/
3185 | stmt modifier_rescue after_rescue stmt
3187 p->ctxt.in_rescue = $3.in_rescue;
3189 YYLTYPE loc = code_loc_gen(&@2, &@4);
3190 resq = NEW_RESBODY(0, 0, remove_begin($4), 0, &loc);
3191 $$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$);
3192 /*% ripper: rescue_mod!($:1, $:4) %*/
3194 | k_END allow_exits '{' compstmt '}'
3196 if (p->ctxt.in_def) {
3197 rb_warn0("END in method; use at_exit");
3199 restore_block_exit(p, $allow_exits);
3202 NODE *scope = NEW_SCOPE2(0 /* tbl */, 0 /* args */, $compstmt /* body */, &@$);
3203 $$ = NEW_POSTEXE(scope, &@$);
3205 /*% ripper: END!($:compstmt) %*/
3208 | mlhs '=' lex_ctxt command_call
3211 $$ = node_assign(p, (NODE *)$1, $4, $3, &@$);
3212 /*% ripper: massign!($:1, $:4) %*/
3214 | lhs '=' lex_ctxt mrhs
3216 $$ = node_assign(p, $1, $4, $3, &@$);
3217 /*% ripper: assign!($:1, $:4) %*/
3219 | mlhs '=' lex_ctxt mrhs_arg modifier_rescue
3220 after_rescue stmt[resbody]
3222 p->ctxt.in_rescue = $3.in_rescue;
3223 YYLTYPE loc = code_loc_gen(&@modifier_rescue, &@resbody);
3224 $resbody = NEW_RESBODY(0, 0, remove_begin($resbody), 0, &loc);
3225 loc.beg_pos = @mrhs_arg.beg_pos;
3226 $mrhs_arg = NEW_RESCUE($mrhs_arg, $resbody, 0, &loc);
3227 $$ = node_assign(p, (NODE *)$mlhs, $mrhs_arg, $lex_ctxt, &@$);
3228 /*% ripper: massign!($:1, rescue_mod!($:4, $:7)) %*/
3230 | mlhs '=' lex_ctxt mrhs_arg
3232 $$ = node_assign(p, (NODE *)$1, $4, $3, &@$);
3233 /*% ripper: massign!($:1, $:4) %*/
3239 $$ = NEW_ERROR(&@$);
3243command_asgn : lhs '=' lex_ctxt command_rhs
3245 $$ = node_assign(p, $1, $4, $3, &@$);
3246 /*% ripper: assign!($:1, $:4) %*/
3248 | var_lhs tOP_ASGN lex_ctxt command_rhs
3250 $$ = new_op_assign(p, $1, $2, $4, $3, &@$);
3251 /*% ripper: opassign!($:1, $:2, $:4) %*/
3253 | primary_value '[' opt_call_args rbracket tOP_ASGN lex_ctxt command_rhs
3255 $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$, &NULL_LOC, &@2, &@4, &@5);
3256 /*% ripper: opassign!(aref_field!($:1, $:3), $:5, $:7) %*/
3259 | primary_value call_op ident_or_const tOP_ASGN lex_ctxt command_rhs
3261 $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
3262 /*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
3264 | primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt command_rhs
3266 YYLTYPE loc = code_loc_gen(&@1, &@3);
3267 $$ = new_const_op_assign(p, NEW_COLON2($1, $3, &loc), $4, $6, $5, &@$);
3268 /*% ripper: opassign!(const_path_field!($:1, $:3), $:4, $:6) %*/
3270 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt command_rhs
3272 $$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$, &@2, &@3, &@4);
3273 /*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
3275 | defn_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
3277 endless_method_name(p, $head->nd_mid, &@head);
3278 restore_defun(p, $head);
3279 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
3280 ($$ = $head->nd_def)->nd_loc = @$;
3281 RNODE_DEFN($$)->nd_defn = $bodystmt;
3282 /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
3283 /*% ripper: def!($:head, $:args, $:$) %*/
3286 | defs_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
3288 endless_method_name(p, $head->nd_mid, &@head);
3289 restore_defun(p, $head);
3290 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
3291 ($$ = $head->nd_def)->nd_loc = @$;
3292 RNODE_DEFS($$)->nd_defn = $bodystmt;
3293 /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
3294 /*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
3297 | backref tOP_ASGN lex_ctxt command_rhs
3299 VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
3300 $$ = NEW_ERROR(&@$);
3301 /*% ripper[error]: assign_error!(?e, opassign!(var_field!($:1), $:2, $:4)) %*/
3305endless_command : command
3306 | endless_command modifier_rescue after_rescue arg
3308 p->ctxt.in_rescue = $3.in_rescue;
3309 $$ = rescued_expr(p, $1, $4, &@1, &@2, &@4);
3310 /*% ripper: rescue_mod!($:1, $:4) %*/
3312 | keyword_not '\n'? endless_command
3314 $$ = call_uni_op(p, method_cond(p, $3, &@3), METHOD_NOT, &@1, &@$);
3315 /*% ripper: unary!(ID2VAL(idNOT), $:3) %*/
3319command_rhs : command_call %prec tOP_ASGN
3324 | command_call modifier_rescue after_rescue stmt
3326 p->ctxt.in_rescue = $3.in_rescue;
3327 YYLTYPE loc = code_loc_gen(&@2, &@4);
3329 $$ = NEW_RESCUE($1, NEW_RESBODY(0, 0, remove_begin($4), 0, &loc), 0, &@$);
3330 /*% ripper: rescue_mod!($:1, $:4) %*/
3336 | expr keyword_and expr
3338 $$ = logop(p, idAND, $1, $3, &@2, &@$);
3339 /*% ripper: binary!($:1, ID2VAL(idAND), $:3) %*/
3341 | expr keyword_or expr
3343 $$ = logop(p, idOR, $1, $3, &@2, &@$);
3344 /*% ripper: binary!($:1, ID2VAL(idOR), $:3) %*/
3346 | keyword_not '\n'? expr
3348 $$ = call_uni_op(p, method_cond(p, $3, &@3), METHOD_NOT, &@1, &@$);
3349 /*% ripper: unary!(ID2VAL(idNOT), $:3) %*/
3353 $$ = call_uni_op(p, method_cond(p, $2, &@2), '!', &@1, &@$);
3354 /*% ripper: unary!(ID2VAL('\'!\''), $:2) %*/
3360 p_in_kwarg[ctxt] p_pvtbl p_pktbl
3361 p_top_expr_body[body]
3363 pop_pktbl(p, $p_pktbl);
3364 pop_pvtbl(p, $p_pvtbl);
3365 p->ctxt.in_kwarg = $ctxt.in_kwarg;
3366 $$ = NEW_CASE3($arg, NEW_IN($body, 0, 0, &@body), &@$, &NULL_LOC, &NULL_LOC);
3367 /*% ripper: case!($:arg, in!($:body, Qnil, Qnil)) %*/
3373 p_in_kwarg[ctxt] p_pvtbl p_pktbl
3374 p_top_expr_body[body]
3376 pop_pktbl(p, $p_pktbl);
3377 pop_pvtbl(p, $p_pvtbl);
3378 p->ctxt.in_kwarg = $ctxt.in_kwarg;
3379 $$ = NEW_CASE3($arg, NEW_IN($body, NEW_TRUE(&@body), NEW_FALSE(&@body), &@body), &@$, &NULL_LOC, &NULL_LOC);
3380 /*% ripper: case!($:arg, in!($:body, Qnil, Qnil)) %*/
3382 | arg %prec tLBRACE_ARG
3388 numparam_name(p, fname);
3391 p->ctxt.in_rescue = before_rescue;
3392 p->ctxt.cant_return = 0;
3397defn_head : k_def def_name
3399 $$ = def_head_save(p, $k_def);
3400 $$->nd_mid = $def_name;
3401 $$->nd_def = NEW_DEFN($def_name, 0, &@$);
3402 /*% ripper: $:def_name %*/
3406defs_head : k_def singleton dot_or_colon
3408 SET_LEX_STATE(EXPR_FNAME);
3412 SET_LEX_STATE(EXPR_ENDFN|EXPR_LABEL); /* force for args */
3413 $$ = def_head_save(p, $k_def);
3414 $$->nd_mid = $def_name;
3415 $$->nd_def = NEW_DEFS($singleton, $def_name, 0, &@$);
3416 /*% ripper: [$:singleton, $:dot_or_colon, $:def_name] %*/
3427 $$ = NEW_ERROR(&@$);
3431expr_value_do : {COND_PUSH(1);} expr_value do {COND_POP();}
3438command_call : command
3442block_command : block_call
3443 | block_call call_op2 operation2 command_args
3445 $$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
3446 /*% ripper: method_add_arg!(call!($:1, $:2, $:3), $:4) %*/
3450cmd_brace_block : tLBRACE_ARG brace_body '}'
3453 set_embraced_location($$, &@1, &@3);
3460 $$ = NEW_FCALL($1, 0, &@$);
3465command : fcall command_args %prec tLOWEST
3468 nd_set_last_loc($1, @2.end_pos);
3470 /*% ripper: command!($:1, $:2) %*/
3472 | fcall command_args cmd_brace_block
3474 block_dup_check(p, $2, $3);
3476 $$ = method_add_block(p, (NODE *)$1, $3, &@$);
3477 fixpos($$, RNODE($1));
3478 nd_set_last_loc($1, @2.end_pos);
3479 /*% ripper: method_add_block!(command!($:1, $:2), $:3) %*/
3481 | primary_value call_op operation2 command_args %prec tLOWEST
3483 $$ = new_command_qcall(p, $2, $1, $3, $4, 0, &@3, &@$);
3484 /*% ripper: command_call!($:1, $:2, $:3, $:4) %*/
3486 | primary_value call_op operation2 command_args cmd_brace_block
3488 $$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
3489 /*% ripper: method_add_block!(command_call!($:1, $:2, $:3, $:4), $:5) %*/
3491 | primary_value tCOLON2 operation2 command_args %prec tLOWEST
3493 $$ = new_command_qcall(p, idCOLON2, $1, $3, $4, 0, &@3, &@$);
3494 /*% ripper: command_call!($:1, $:2, $:3, $:4) %*/
3496 | primary_value tCOLON2 operation2 command_args cmd_brace_block
3498 $$ = new_command_qcall(p, idCOLON2, $1, $3, $4, $5, &@3, &@$);
3499 /*% ripper: method_add_block!(command_call!($:1, $:2, $:3, $:4), $:5) %*/
3501 | primary_value tCOLON2 tCONSTANT '{' brace_body '}'
3503 set_embraced_location($5, &@4, &@6);
3504 $$ = new_command_qcall(p, idCOLON2, $1, $3, 0, $5, &@3, &@$);
3505 /*% ripper: method_add_block!(command_call!($:1, $:2, $:3, Qnil), $:5) %*/
3507 | keyword_super command_args
3509 $$ = NEW_SUPER($2, &@$);
3511 /*% ripper: super!($:2) %*/
3513 | k_yield command_args
3515 $$ = new_yield(p, $2, &@$);
3517 /*% ripper: yield!($:2) %*/
3519 | k_return call_args
3521 $$ = NEW_RETURN(ret_args(p, $2), &@$, &@1);
3522 /*% ripper: return!($:2) %*/
3524 | keyword_break call_args
3527 args = ret_args(p, $2);
3528 $$ = add_block_exit(p, NEW_BREAK(args, &@$, &@1));
3529 /*% ripper: break!($:2) %*/
3531 | keyword_next call_args
3534 args = ret_args(p, $2);
3535 $$ = add_block_exit(p, NEW_NEXT(args, &@$, &@1));
3536 /*% ripper: next!($:2) %*/
3541 | tLPAREN mlhs_inner rparen
3544 /*% ripper: mlhs_paren!($:2) %*/
3548mlhs_inner : mlhs_basic
3549 | tLPAREN mlhs_inner rparen
3551 $$ = NEW_MASGN(NEW_LIST((NODE *)$2, &@$), 0, &@$);
3552 /*% ripper: mlhs_paren!($:2) %*/
3556mlhs_basic : mlhs_head
3558 $$ = NEW_MASGN($1, 0, &@$);
3561 | mlhs_head mlhs_item
3563 $$ = NEW_MASGN(list_append(p, $1, $2), 0, &@$);
3564 /*% ripper: mlhs_add!($:1, $:2) %*/
3566 | mlhs_head tSTAR mlhs_node
3568 $$ = NEW_MASGN($1, $3, &@$);
3569 /*% ripper: mlhs_add_star!($:1, $:3) %*/
3571 | mlhs_head tSTAR mlhs_node ',' mlhs_post
3573 $$ = NEW_MASGN($1, NEW_POSTARG($3,$5,&@$), &@$);
3574 /*% ripper: mlhs_add_post!(mlhs_add_star!($:1, $:3), $:5) %*/
3578 $$ = NEW_MASGN($1, NODE_SPECIAL_NO_NAME_REST, &@$);
3579 /*% ripper: mlhs_add_star!($:1, Qnil) %*/
3581 | mlhs_head tSTAR ',' mlhs_post
3583 $$ = NEW_MASGN($1, NEW_POSTARG(NODE_SPECIAL_NO_NAME_REST, $4, &@$), &@$);
3584 /*% ripper: mlhs_add_post!(mlhs_add_star!($:1, Qnil), $:4) %*/
3588 $$ = NEW_MASGN(0, $2, &@$);
3589 /*% ripper: mlhs_add_star!(mlhs_new!, $:2) %*/
3591 | tSTAR mlhs_node ',' mlhs_post
3593 $$ = NEW_MASGN(0, NEW_POSTARG($2,$4,&@$), &@$);
3594 /*% ripper: mlhs_add_post!(mlhs_add_star!(mlhs_new!, $:2), $:4) %*/
3598 $$ = NEW_MASGN(0, NODE_SPECIAL_NO_NAME_REST, &@$);
3599 /*% ripper: mlhs_add_star!(mlhs_new!, Qnil) %*/
3601 | tSTAR ',' mlhs_post
3603 $$ = NEW_MASGN(0, NEW_POSTARG(NODE_SPECIAL_NO_NAME_REST, $3, &@$), &@$);
3604 /*% ripper: mlhs_add_post!(mlhs_add_star!(mlhs_new!, Qnil), $:3) %*/
3608mlhs_item : mlhs_node
3609 | tLPAREN mlhs_inner rparen
3612 /*% ripper: mlhs_paren!($:2) %*/
3616mlhs_head : mlhs_item ','
3618 $$ = NEW_LIST($1, &@1);
3619 /*% ripper: mlhs_add!(mlhs_new!, $:1) %*/
3621 | mlhs_head mlhs_item ','
3623 $$ = list_append(p, $1, $2);
3624 /*% ripper: mlhs_add!($:1, $:2) %*/
3628mlhs_post : mlhs_item
3630 $$ = NEW_LIST($1, &@$);
3631 /*% ripper: mlhs_add!(mlhs_new!, $:1) %*/
3633 | mlhs_post ',' mlhs_item
3635 $$ = list_append(p, $1, $3);
3636 /*% ripper: mlhs_add!($:1, $:3) %*/
3640mlhs_node : user_or_keyword_variable
3642 /*% ripper: var_field!($:1) %*/
3643 $$ = assignable(p, $1, 0, &@$);
3645 | primary_value '[' opt_call_args rbracket
3647 $$ = aryset(p, $1, $3, &@$);
3648 /*% ripper: aref_field!($:1, $:3) %*/
3650 | primary_value call_op tIDENTIFIER
3652 anddot_multiple_assignment_check(p, &@2, $2);
3653 $$ = attrset(p, $1, $2, $3, &@$);
3654 /*% ripper: field!($:1, $:2, $:3) %*/
3656 | primary_value tCOLON2 tIDENTIFIER
3658 $$ = attrset(p, $1, idCOLON2, $3, &@$);
3659 /*% ripper: const_path_field!($:1, $:3) %*/
3661 | primary_value call_op tCONSTANT
3663 anddot_multiple_assignment_check(p, &@2, $2);
3664 $$ = attrset(p, $1, $2, $3, &@$);
3665 /*% ripper: field!($:1, $:2, $:3) %*/
3667 | primary_value tCOLON2 tCONSTANT
3669 /*% ripper: const_path_field!($:1, $:3) %*/
3670 $$ = const_decl(p, NEW_COLON2($1, $3, &@$), &@$);
3674 /*% ripper: top_const_field!($:2) %*/
3675 $$ = const_decl(p, NEW_COLON3($2, &@$), &@$);
3679 VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
3680 $$ = NEW_ERROR(&@$);
3681 /*% ripper[error]: assign_error!(?e, var_field!($:1)) %*/
3685lhs : user_or_keyword_variable
3687 /*% ripper: var_field!($:1) %*/
3688 $$ = assignable(p, $1, 0, &@$);
3690 | primary_value '[' opt_call_args rbracket
3692 $$ = aryset(p, $1, $3, &@$);
3693 /*% ripper: aref_field!($:1, $:3) %*/
3695 | primary_value call_op tIDENTIFIER
3697 $$ = attrset(p, $1, $2, $3, &@$);
3698 /*% ripper: field!($:1, $:2, $:3) %*/
3700 | primary_value tCOLON2 tIDENTIFIER
3702 $$ = attrset(p, $1, idCOLON2, $3, &@$);
3703 /*% ripper: field!($:1, $:2, $:3) %*/
3705 | primary_value call_op tCONSTANT
3707 $$ = attrset(p, $1, $2, $3, &@$);
3708 /*% ripper: field!($:1, $:2, $:3) %*/
3710 | primary_value tCOLON2 tCONSTANT
3712 /*% ripper: const_path_field!($:1, $:3) %*/
3713 $$ = const_decl(p, NEW_COLON2($1, $3, &@$), &@$);
3717 /*% ripper: top_const_field!($:2) %*/
3718 $$ = const_decl(p, NEW_COLON3($2, &@$), &@$);
3722 VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
3723 $$ = NEW_ERROR(&@$);
3724 /*% ripper[error]: assign_error!(?e, var_field!($:1)) %*/
3730 static const char mesg[] = "class/module name must be CONSTANT";
3732 yyerror1(&@1, mesg);
3734 /*% ripper[error]: class_name_error!(ERR_MESG(), $:1) %*/
3739cpath : tCOLON3 cname
3741 $$ = NEW_COLON3($2, &@$);
3742 /*% ripper: top_const_ref!($:2) %*/
3746 $$ = NEW_COLON2(0, $1, &@$);
3747 /*% ripper: const_ref!($:1) %*/
3749 | primary_value tCOLON2 cname
3751 $$ = NEW_COLON2($1, $3, &@$);
3752 /*% ripper: const_path_ref!($:1, $:3) %*/
3756fname : ident_or_const
3760 SET_LEX_STATE(EXPR_ENDFN);
3768 $$ = NEW_SYM(rb_id2str($1), &@$);
3769 /*% ripper: symbol_literal!($:1) %*/
3776 $$ = NEW_UNDEF($1, &@$);
3777 /*% ripper: rb_ary_new3(1, $:1) %*/
3779 | undef_list ',' {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
3781 nd_set_last_loc($1, @4.end_pos);
3782 rb_parser_ary_push_node(p, RNODE_UNDEF($1)->nd_undefs, $4);
3783 /*% ripper: rb_ary_push($:1, $:4) %*/
3787op : '|' { $$ = '|'; }
3790 | tCMP { $$ = tCMP; }
3792 | tEQQ { $$ = tEQQ; }
3793 | tMATCH { $$ = tMATCH; }
3794 | tNMATCH { $$ = tNMATCH; }
3796 | tGEQ { $$ = tGEQ; }
3798 | tLEQ { $$ = tLEQ; }
3799 | tNEQ { $$ = tNEQ; }
3800 | tLSHFT { $$ = tLSHFT; }
3801 | tRSHFT { $$ = tRSHFT; }
3805 | tSTAR { $$ = '*'; }
3808 | tPOW { $$ = tPOW; }
3809 | tDSTAR { $$ = tDSTAR; }
3812 | tUPLUS { $$ = tUPLUS; }
3813 | tUMINUS { $$ = tUMINUS; }
3814 | tAREF { $$ = tAREF; }
3815 | tASET { $$ = tASET; }
3819reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
3820 | keyword_BEGIN | keyword_END
3821 | keyword_alias | keyword_and | keyword_begin
3822 | keyword_break | keyword_case | keyword_class | keyword_def
3823 | keyword_defined | keyword_do | keyword_else | keyword_elsif
3824 | keyword_end | keyword_ensure | keyword_false
3825 | keyword_for | keyword_in | keyword_module | keyword_next
3826 | keyword_nil | keyword_not | keyword_or | keyword_redo
3827 | keyword_rescue | keyword_retry | keyword_return | keyword_self
3828 | keyword_super | keyword_then | keyword_true | keyword_undef
3829 | keyword_when | keyword_yield | keyword_if | keyword_unless
3830 | keyword_while | keyword_until
3833arg : lhs '=' lex_ctxt arg_rhs
3835 $$ = node_assign(p, $1, $4, $3, &@$);
3836 /*% ripper: assign!($:1, $:4) %*/
3838 | var_lhs tOP_ASGN lex_ctxt arg_rhs
3840 $$ = new_op_assign(p, $1, $2, $4, $3, &@$);
3841 /*% ripper: opassign!($:1, $:2, $:4) %*/
3843 | primary_value '[' opt_call_args rbracket tOP_ASGN lex_ctxt arg_rhs
3845 $$ = new_ary_op_assign(p, $1, $3, $5, $7, &@3, &@$, &NULL_LOC, &@2, &@4, &@5);
3846 /*% ripper: opassign!(aref_field!($:1, $:3), $:5, $:7) %*/
3848 | primary_value call_op tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs
3850 $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
3851 /*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
3853 | primary_value call_op tCONSTANT tOP_ASGN lex_ctxt arg_rhs
3855 $$ = new_attr_op_assign(p, $1, $2, $3, $4, $6, &@$, &@2, &@3, &@4);
3856 /*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
3858 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN lex_ctxt arg_rhs
3860 $$ = new_attr_op_assign(p, $1, idCOLON2, $3, $4, $6, &@$, &@2, &@3, &@4);
3861 /*% ripper: opassign!(field!($:1, $:2, $:3), $:4, $:6) %*/
3863 | primary_value tCOLON2 tCONSTANT tOP_ASGN lex_ctxt arg_rhs
3865 YYLTYPE loc = code_loc_gen(&@1, &@3);
3866 $$ = new_const_op_assign(p, NEW_COLON2($1, $3, &loc), $4, $6, $5, &@$);
3867 /*% ripper: opassign!(const_path_field!($:1, $:3), $:4, $:6) %*/
3869 | tCOLON3 tCONSTANT tOP_ASGN lex_ctxt arg_rhs
3871 YYLTYPE loc = code_loc_gen(&@1, &@2);
3872 $$ = new_const_op_assign(p, NEW_COLON3($2, &loc), $3, $5, $4, &@$);
3873 /*% ripper: opassign!(top_const_field!($:2), $:3, $:5) %*/
3875 | backref tOP_ASGN lex_ctxt arg_rhs
3877 VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
3878 $$ = NEW_ERROR(&@$);
3879 /*% ripper[error]: assign_error!(?e, opassign!(var_field!($:1), $:2, $:4)) %*/
3885 $$ = NEW_DOT2($1, $3, &@$);
3886 /*% ripper: dot2!($:1, $:3) %*/
3892 $$ = NEW_DOT3($1, $3, &@$);
3893 /*% ripper: dot3!($:1, $:3) %*/
3898 $$ = NEW_DOT2($1, new_nil_at(p, &@2.end_pos), &@$);
3899 /*% ripper: dot2!($:1, Qnil) %*/
3904 $$ = NEW_DOT3($1, new_nil_at(p, &@2.end_pos), &@$);
3905 /*% ripper: dot3!($:1, Qnil) %*/
3910 $$ = NEW_DOT2(new_nil_at(p, &@1.beg_pos), $2, &@$);
3911 /*% ripper: dot2!(Qnil, $:2) %*/
3916 $$ = NEW_DOT3(new_nil_at(p, &@1.beg_pos), $2, &@$);
3917 /*% ripper: dot3!(Qnil, $:2) %*/
3921 $$ = call_bin_op(p, $1, '+', $3, &@2, &@$);
3922 /*% ripper: binary!($:1, ID2VAL('\'+\''), $:3) %*/
3926 $$ = call_bin_op(p, $1, '-', $3, &@2, &@$);
3927 /*% ripper: binary!($:1, ID2VAL('\'-\''), $:3) %*/
3931 $$ = call_bin_op(p, $1, '*', $3, &@2, &@$);
3932 /*% ripper: binary!($:1, ID2VAL('\'*\''), $:3) %*/
3936 $$ = call_bin_op(p, $1, '/', $3, &@2, &@$);
3937 /*% ripper: binary!($:1, ID2VAL('\'/\''), $:3) %*/
3941 $$ = call_bin_op(p, $1, '%', $3, &@2, &@$);
3942 /*% ripper: binary!($:1, ID2VAL('\'%\''), $:3) %*/
3946 $$ = call_bin_op(p, $1, idPow, $3, &@2, &@$);
3947 /*% ripper: binary!($:1, ID2VAL(idPow), $:3) %*/
3949 | tUMINUS_NUM simple_numeric tPOW arg
3951 $$ = call_uni_op(p, call_bin_op(p, $2, idPow, $4, &@2, &@$), idUMinus, &@1, &@$);
3952 /*% ripper: unary!(ID2VAL(idUMinus), binary!($:2, ID2VAL(idPow), $:4)) %*/
3956 $$ = call_uni_op(p, $2, idUPlus, &@1, &@$);
3957 /*% ripper: unary!(ID2VAL(idUPlus), $:2) %*/
3961 $$ = call_uni_op(p, $2, idUMinus, &@1, &@$);
3962 /*% ripper: unary!(ID2VAL(idUMinus), $:2) %*/
3966 $$ = call_bin_op(p, $1, '|', $3, &@2, &@$);
3967 /*% ripper: binary!($:1, ID2VAL('\'|\''), $:3) %*/
3971 $$ = call_bin_op(p, $1, '^', $3, &@2, &@$);
3972 /*% ripper: binary!($:1, ID2VAL('\'^\''), $:3) %*/
3976 $$ = call_bin_op(p, $1, '&', $3, &@2, &@$);
3977 /*% ripper: binary!($:1, ID2VAL('\'&\''), $:3) %*/
3981 $$ = call_bin_op(p, $1, idCmp, $3, &@2, &@$);
3982 /*% ripper: binary!($:1, ID2VAL(idCmp), $:3) %*/
3984 | rel_expr %prec tCMP
3987 $$ = call_bin_op(p, $1, idEq, $3, &@2, &@$);
3988 /*% ripper: binary!($:1, ID2VAL(idEq), $:3) %*/
3992 $$ = call_bin_op(p, $1, idEqq, $3, &@2, &@$);
3993 /*% ripper: binary!($:1, ID2VAL(idEqq), $:3) %*/
3997 $$ = call_bin_op(p, $1, idNeq, $3, &@2, &@$);
3998 /*% ripper: binary!($:1, ID2VAL(idNeq), $:3) %*/
4002 $$ = match_op(p, $1, $3, &@2, &@$);
4003 /*% ripper: binary!($:1, ID2VAL(idEqTilde), $:3) %*/
4007 $$ = call_bin_op(p, $1, idNeqTilde, $3, &@2, &@$);
4008 /*% ripper: binary!($:1, ID2VAL(idNeqTilde), $:3) %*/
4012 $$ = call_uni_op(p, method_cond(p, $2, &@2), '!', &@1, &@$);
4013 /*% ripper: unary!(ID2VAL('\'!\''), $:2) %*/
4017 $$ = call_uni_op(p, $2, '~', &@1, &@$);
4018 /*% ripper: unary!(ID2VAL('\'~\''), $:2) %*/
4022 $$ = call_bin_op(p, $1, idLTLT, $3, &@2, &@$);
4023 /*% ripper: binary!($:1, ID2VAL(idLTLT), $:3) %*/
4027 $$ = call_bin_op(p, $1, idGTGT, $3, &@2, &@$);
4028 /*% ripper: binary!($:1, ID2VAL(idGTGT), $:3) %*/
4032 $$ = logop(p, idANDOP, $1, $3, &@2, &@$);
4033 /*% ripper: binary!($:1, ID2VAL(idANDOP), $:3) %*/
4037 $$ = logop(p, idOROP, $1, $3, &@2, &@$);
4038 /*% ripper: binary!($:1, ID2VAL(idOROP), $:3) %*/
4040 | keyword_defined '\n'? begin_defined arg
4042 p->ctxt.in_defined = $3.in_defined;
4043 $$ = new_defined(p, $4, &@$);
4044 /*% ripper: defined!($:4) %*/
4046 | arg '?' arg '\n'? ':' arg
4049 $$ = new_if(p, $1, $3, $6, &@$);
4051 /*% ripper: ifop!($:1, $:3, $:6) %*/
4053 | defn_head[head] f_opt_paren_args[args] '=' endless_arg[bodystmt]
4055 endless_method_name(p, $head->nd_mid, &@head);
4056 restore_defun(p, $head);
4057 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
4058 ($$ = $head->nd_def)->nd_loc = @$;
4059 RNODE_DEFN($$)->nd_defn = $bodystmt;
4060 /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
4061 /*% ripper: def!($:head, $:args, $:$) %*/
4064 | defs_head[head] f_opt_paren_args[args] '=' endless_arg[bodystmt]
4066 endless_method_name(p, $head->nd_mid, &@head);
4067 restore_defun(p, $head);
4068 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
4069 ($$ = $head->nd_def)->nd_loc = @$;
4070 RNODE_DEFS($$)->nd_defn = $bodystmt;
4071 /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
4072 /*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
4081endless_arg : arg %prec modifier_rescue
4082 | endless_arg modifier_rescue after_rescue arg
4084 p->ctxt.in_rescue = $3.in_rescue;
4085 $$ = rescued_expr(p, $1, $4, &@1, &@2, &@4);
4086 /*% ripper: rescue_mod!($:1, $:4) %*/
4088 | keyword_not '\n'? endless_arg
4090 $$ = call_uni_op(p, method_cond(p, $3, &@3), METHOD_NOT, &@1, &@$);
4091 /*% ripper: unary!(ID2VAL(idNOT), $:3) %*/
4095relop : '>' {$$ = '>';}
4101rel_expr : arg relop arg %prec '>'
4103 $$ = call_bin_op(p, $1, $2, $3, &@2, &@$);
4104 /*% ripper: binary!($:1, ID2VAL($2), $:3) %*/
4106 | rel_expr relop arg %prec '>'
4108 rb_warning1("comparison '%s' after comparison", WARN_ID($2));
4109 $$ = call_bin_op(p, $1, $2, $3, &@2, &@$);
4110 /*% ripper: binary!($:1, ID2VAL($2), $:3) %*/
4120begin_defined : lex_ctxt
4122 p->ctxt.in_defined = 1;
4127after_rescue : lex_ctxt
4129 p->ctxt.in_rescue = after_rescue;
4146 | args ',' assocs trailer
4148 $$ = $3 ? arg_append(p, $1, new_hash(p, $3, &@3), &@$) : $1;
4149 /*% ripper: args_add!($:1, bare_assoc_hash!($:3)) %*/
4153 $$ = $1 ? NEW_LIST(new_hash(p, $1, &@1), &@$) : 0;
4154 /*% ripper: args_add!(args_new!, bare_assoc_hash!($:1)) %*/
4158arg_rhs : arg %prec tOP_ASGN
4163 | arg modifier_rescue after_rescue arg
4165 p->ctxt.in_rescue = $3.in_rescue;
4167 $$ = rescued_expr(p, $1, $4, &@1, &@2, &@4);
4168 /*% ripper: rescue_mod!($:1, $:4) %*/
4172paren_args : '(' opt_call_args rparen
4175 /*% ripper: arg_paren!($:2) %*/
4177 | '(' args ',' args_forward rparen
4179 if (!check_forwarding_args(p)) {
4183 $$ = new_args_forward_call(p, $2, &@4, &@$);
4184 /*% ripper: arg_paren!(args_add!($:2, $:4)) %*/
4187 | '(' args_forward rparen
4189 if (!check_forwarding_args(p)) {
4193 $$ = new_args_forward_call(p, 0, &@2, &@$);
4194 /*% ripper: arg_paren!($:2) %*/
4199opt_paren_args : none
4202 $$ = $1 ? $1 : NODE_SPECIAL_EMPTY_ARGS;
4212 | args ',' assocs ','
4214 $$ = $3 ? arg_append(p, $1, new_hash(p, $3, &@3), &@$) : $1;
4215 /*% ripper: args_add!($:1, bare_assoc_hash!($:3)) %*/
4219 $$ = $1 ? NEW_LIST(new_hash(p, $1, &@1), &@1) : 0;
4220 /*% ripper: args_add!(args_new!, bare_assoc_hash!($:1)) %*/
4227 $$ = NEW_LIST($1, &@$);
4228 /*% ripper: args_add!(args_new!, $:1) %*/
4230 | args opt_block_arg
4232 $$ = arg_blk_pass($1, $2);
4233 /*% ripper: args_add_block!($:1, $:2) %*/
4235 | assocs opt_block_arg
4237 $$ = $1 ? NEW_LIST(new_hash(p, $1, &@1), &@1) : 0;
4238 $$ = arg_blk_pass($$, $2);
4239 /*% ripper: args_add_block!(args_add!(args_new!, bare_assoc_hash!($:1)), $:2) %*/
4241 | args ',' assocs opt_block_arg
4243 $$ = $3 ? arg_append(p, $1, new_hash(p, $3, &@3), &@$) : $1;
4244 $$ = arg_blk_pass($$, $4);
4245 /*% ripper: args_add_block!(args_add!($:1, bare_assoc_hash!($:3)), $:4) %*/
4248 /*% ripper: args_add_block!(args_new!, $:1) %*/
4252 /* If call_args starts with a open paren '(' or '[',
4253 * look-ahead reading of the letters calls CMDARG_PUSH(0),
4254 * but the push must be done after CMDARG_PUSH(1).
4255 * So this code makes them consistent by first cancelling
4256 * the premature CMDARG_PUSH(0), doing CMDARG_PUSH(1),
4257 * and finally redoing CMDARG_PUSH(0).
4261 case '(': case tLPAREN: case tLPAREN_ARG: case '[': case tLBRACK:
4264 if (lookahead) CMDARG_POP();
4266 if (lookahead) CMDARG_PUSH(0);
4270 /* call_args can be followed by tLBRACE_ARG (that does CMDARG_PUSH(0) in the lexer)
4271 * but the push must be done after CMDARG_POP() in the parser.
4272 * So this code does CMDARG_POP() to pop 0 pushed by tLBRACE_ARG,
4273 * CMDARG_POP() to pop 1 pushed by command_args,
4274 * and CMDARG_PUSH(0) to restore back the flag set by tLBRACE_ARG.
4281 if (lookahead) CMDARG_POP();
4283 if (lookahead) CMDARG_PUSH(0);
4289block_arg : tAMPER arg_value
4291 $$ = NEW_BLOCK_PASS($2, &@$, &@1);
4296 forwarding_arg_check(p, idFWD_BLOCK, idFWD_ALL, "block");
4297 $$ = NEW_BLOCK_PASS(NEW_LVAR(idFWD_BLOCK, &@1), &@$, &@1);
4298 /*% ripper: Qnil %*/
4302opt_block_arg : ',' block_arg
4310 /*% ripper: Qfalse %*/
4317 $$ = NEW_LIST($arg_value, &@$);
4318 /*% ripper: args_add!(args_new!, $:arg_value) %*/
4323 /*% ripper: args_add_star!(args_new!, $:arg_splat) %*/
4325 | args[non_last_args] ',' arg_value
4327 $$ = last_arg_append(p, $non_last_args, $arg_value, &@$);
4328 /*% ripper: args_add!($:non_last_args, $:arg_value) %*/
4330 | args[non_last_args] ',' arg_splat
4332 $$ = rest_arg_append(p, $non_last_args, RNODE_SPLAT($arg_splat)->nd_head, &@$);
4333 /*% ripper: args_add_star!($:non_last_args, $:arg_splat) %*/
4338arg_splat : tSTAR arg_value
4340 $$ = NEW_SPLAT($arg_value, &@$, &@tSTAR);
4341 /*% ripper: $:arg_value %*/
4345 forwarding_arg_check(p, idFWD_REST, idFWD_ALL, "rest");
4346 $$ = NEW_SPLAT(NEW_LVAR(idFWD_REST, &@tSTAR), &@$, &@tSTAR);
4347 /*% ripper: Qnil %*/
4357mrhs : args ',' arg_value
4359 $$ = last_arg_append(p, $args, $arg_value, &@$);
4360 /*% ripper: mrhs_add!(mrhs_new_from_args!($:args), $:arg_value) %*/
4362 | args ',' tSTAR arg_value
4364 $$ = rest_arg_append(p, $args, $arg_value, &@$);
4365 /*% ripper: mrhs_add_star!(mrhs_new_from_args!($:args), $:arg_value) %*/
4369 $$ = NEW_SPLAT($arg_value, &@$, &@tSTAR);
4370 /*% ripper: mrhs_add_star!(mrhs_new!, $:arg_value) %*/
4374%rule %inline inline_primary
4385primary : inline_primary
4390 $$ = (NODE *)NEW_FCALL($1, 0, &@$);
4391 /*% ripper: method_add_arg!(fcall!($:1), args_new!) %*/
4401 set_line_body($3, @1.end_pos.lineno);
4402 $$ = NEW_BEGIN($3, &@$);
4403 nd_set_line($$, @1.end_pos.lineno);
4404 /*% ripper: begin!($:3) %*/
4406 | tLPAREN_ARG compstmt {SET_LEX_STATE(EXPR_ENDARG);} ')'
4408 if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
4410 /*% ripper: paren!($:2) %*/
4412 | tLPAREN compstmt ')'
4414 if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
4415 $$ = NEW_BLOCK($2, &@$);
4416 /*% ripper: paren!($:2) %*/
4418 | primary_value tCOLON2 tCONSTANT
4420 $$ = NEW_COLON2($1, $3, &@$);
4421 /*% ripper: const_path_ref!($:1, $:3) %*/
4425 $$ = NEW_COLON3($2, &@$);
4426 /*% ripper: top_const_ref!($:2) %*/
4428 | tLBRACK aref_args ']'
4430 $$ = make_list($2, &@$);
4431 /*% ripper: array!($:2) %*/
4433 | tLBRACE assoc_list '}'
4435 $$ = new_hash(p, $2, &@$);
4436 RNODE_HASH($$)->nd_brace = TRUE;
4437 /*% ripper: hash!($:2) %*/
4441 $$ = NEW_RETURN(0, &@$, &@1);
4442 /*% ripper: return0! %*/
4444 | k_yield '(' call_args rparen
4446 $$ = new_yield(p, $3, &@$);
4447 /*% ripper: yield!(paren!($:3)) %*/
4449 | k_yield '(' rparen
4451 $$ = NEW_YIELD(0, &@$);
4452 /*% ripper: yield!(paren!(args_new!)) %*/
4456 $$ = NEW_YIELD(0, &@$);
4457 /*% ripper: yield0! %*/
4459 | keyword_defined '\n'? '(' begin_defined expr rparen
4461 p->ctxt.in_defined = $4.in_defined;
4462 $$ = new_defined(p, $5, &@$);
4463 /*% ripper: defined!($:5) %*/
4465 | keyword_not '(' expr rparen
4467 $$ = call_uni_op(p, method_cond(p, $3, &@3), METHOD_NOT, &@1, &@$);
4468 /*% ripper: unary!(ID2VAL(idNOT), $:3) %*/
4470 | keyword_not '(' rparen
4472 $$ = call_uni_op(p, method_cond(p, new_nil(&@2), &@2), METHOD_NOT, &@1, &@$);
4473 /*% ripper: unary!(ID2VAL(idNOT), Qnil) %*/
4477 $$ = method_add_block(p, (NODE *)$1, $2, &@$);
4478 /*% ripper: method_add_block!(method_add_arg!(fcall!($:1), args_new!), $:2) %*/
4481 | method_call brace_block
4483 block_dup_check(p, get_nd_args(p, $1), $2);
4484 $$ = method_add_block(p, $1, $2, &@$);
4485 /*% ripper: method_add_block!($:1, $:2) %*/
4488 | k_if expr_value then
4493 $$ = new_if(p, $2, $4, $5, &@$);
4495 /*% ripper: if!($:2, $:4, $:5) %*/
4497 | k_unless expr_value then
4502 $$ = new_unless(p, $2, $4, $5, &@$, &@1, &@3, &@6);
4504 /*% ripper: unless!($:2, $:4, $:5) %*/
4506 | k_while expr_value_do
4510 restore_block_exit(p, $1);
4511 $$ = NEW_WHILE(cond(p, $2, &@2), $3, 1, &@$, &@1, &@4);
4513 /*% ripper: while!($:2, $:3) %*/
4515 | k_until expr_value_do
4519 restore_block_exit(p, $1);
4520 $$ = NEW_UNTIL(cond(p, $2, &@2), $3, 1, &@$, &@1, &@4);
4522 /*% ripper: until!($:2, $:3) %*/
4524 | k_case expr_value terms?
4526 $$ = p->case_labels;
4527 p->case_labels = CHECK_LITERAL_WHEN;
4532 if (CASE_LABELS_ENABLED_P(p->case_labels)) st_free_table(p->case_labels);
4533 p->case_labels = $4;
4534 $$ = NEW_CASE($2, $5, &@$, &@1, &@6);
4536 /*% ripper: case!($:2, $:5) %*/
4540 $$ = p->case_labels;
4546 if (p->case_labels) st_free_table(p->case_labels);
4547 p->case_labels = $3;
4548 $$ = NEW_CASE2($4, &@$, &@1, &@5);
4549 /*% ripper: case!(Qnil, $:4) %*/
4551 | k_case expr_value terms?
4555 $$ = NEW_CASE3($2, $4, &@$, &@1, &@5);
4556 /*% ripper: case!($:2, $:4) %*/
4558 | k_for for_var keyword_in expr_value_do
4562 restore_block_exit(p, $1);
4566 * e.each{|*x| a, b, c = x}
4570 * e.each{|x| a, = x}
4572 ID id = internal_id(p);
4573 rb_node_args_aux_t *m = NEW_ARGS_AUX(0, 0, &NULL_LOC);
4574 rb_node_args_t *args;
4575 NODE *scope, *internal_var = NEW_DVAR(id, &@2);
4576 rb_ast_id_table_t *tbl = rb_ast_new_local_table(p->ast, 1);
4577 tbl->ids[0] = id; /* internal id */
4579 switch (nd_type($2)) {
4581 case NODE_DASGN: /* e.each {|internal_var| a = internal_var; ... } */
4582 set_nd_value(p, $2, internal_var);
4587 case NODE_MASGN: /* e.each {|*internal_var| a, b, c = (internal_var.length == 1 && Array === (tmp = internal_var[0]) ? tmp : internal_var); ... } */
4588 m->nd_next = node_assign(p, $2, NEW_FOR_MASGN(internal_var, &@2), NO_LEX_CTXT, &@2);
4590 default: /* e.each {|*internal_var| @a, B, c[1], d.attr = internal_val; ... } */
4591 m->nd_next = node_assign(p, (NODE *)NEW_MASGN(NEW_LIST($2, &@2), 0, &@2), internal_var, NO_LEX_CTXT, &@2);
4593 /* {|*internal_id| <m> = internal_id; ... } */
4594 args = new_args(p, m, 0, id, 0, new_args_tail(p, 0, 0, 0, &@2), &@2);
4595 scope = NEW_SCOPE2(tbl, args, $5, &@$);
4596 $$ = NEW_FOR($4, scope, &@$);
4598 /*% ripper: for!($:2, $:4, $:5) %*/
4600 | k_class cpath superclass
4602 begin_definition("class", &@k_class, &@cpath);
4607 $$ = NEW_CLASS($cpath, $bodystmt, $superclass, &@$);
4608 nd_set_line(RNODE_CLASS($$)->nd_body, @k_end.end_pos.lineno);
4609 set_line_body($bodystmt, @superclass.end_pos.lineno);
4610 nd_set_line($$, @superclass.end_pos.lineno);
4611 /*% ripper: class!($:cpath, $:superclass, $:bodystmt) %*/
4613 p->ctxt.in_class = $k_class.in_class;
4614 p->ctxt.cant_return = $k_class.cant_return;
4615 p->ctxt.shareable_constant_value = $k_class.shareable_constant_value;
4617 | k_class tLSHFT expr_value
4619 begin_definition("", &@k_class, &@tLSHFT);
4625 $$ = NEW_SCLASS($expr_value, $bodystmt, &@$);
4626 nd_set_line(RNODE_SCLASS($$)->nd_body, @k_end.end_pos.lineno);
4627 set_line_body($bodystmt, nd_line($expr_value));
4628 fixpos($$, $expr_value);
4629 /*% ripper: sclass!($:expr_value, $:bodystmt) %*/
4631 p->ctxt.in_def = $k_class.in_def;
4632 p->ctxt.in_class = $k_class.in_class;
4633 p->ctxt.cant_return = $k_class.cant_return;
4634 p->ctxt.shareable_constant_value = $k_class.shareable_constant_value;
4638 begin_definition("module", &@k_module, &@cpath);
4643 $$ = NEW_MODULE($cpath, $bodystmt, &@$);
4644 nd_set_line(RNODE_MODULE($$)->nd_body, @k_end.end_pos.lineno);
4645 set_line_body($bodystmt, @cpath.end_pos.lineno);
4646 nd_set_line($$, @cpath.end_pos.lineno);
4647 /*% ripper: module!($:cpath, $:bodystmt) %*/
4649 p->ctxt.in_class = $k_module.in_class;
4650 p->ctxt.cant_return = $k_module.cant_return;
4651 p->ctxt.shareable_constant_value = $k_module.shareable_constant_value;
4656 push_end_expect_token_locations(p, &@head.beg_pos);
4661 restore_defun(p, $head);
4662 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
4663 ($$ = $head->nd_def)->nd_loc = @$;
4664 RNODE_DEFN($$)->nd_defn = $bodystmt;
4665 /*% ripper: def!($:head, $:args, $:bodystmt) %*/
4671 push_end_expect_token_locations(p, &@head.beg_pos);
4676 restore_defun(p, $head);
4677 $bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
4678 ($$ = $head->nd_def)->nd_loc = @$;
4679 RNODE_DEFS($$)->nd_defn = $bodystmt;
4680 /*% ripper: defs!(*$:head[0..2], $:args, $:bodystmt) %*/
4685 $$ = add_block_exit(p, NEW_BREAK(0, &@$, &@1));
4686 /*% ripper: break!(args_new!) %*/
4690 $$ = add_block_exit(p, NEW_NEXT(0, &@$, &@1));
4691 /*% ripper: next!(args_new!) %*/
4695 $$ = add_block_exit(p, NEW_REDO(&@$, &@1));
4696 /*% ripper: redo! %*/
4700 if (!p->ctxt.in_defined) {
4701 switch (p->ctxt.in_rescue) {
4702 case before_rescue: yyerror1(&@1, "Invalid retry without rescue"); break;
4703 case after_rescue: /* ok */ break;
4704 case after_else: yyerror1(&@1, "Invalid retry after else"); break;
4705 case after_ensure: yyerror1(&@1, "Invalid retry after ensure"); break;
4708 $$ = NEW_RETRY(&@$);
4709 /*% ripper: retry! %*/
4713primary_value : primary
4720k_begin : keyword_begin
4722 token_info_push(p, "begin", &@$);
4723 push_end_expect_token_locations(p, &@1.beg_pos);
4730 token_info_push(p, "if", &@$);
4731 if (p->token_info && p->token_info->nonspc &&
4732 p->token_info->next && !strcmp(p->token_info->next->token, "else")) {
4733 const char *tok = p->lex.ptok - rb_strlen_lit("if");
4734 const char *beg = p->lex.pbeg + p->token_info->next->beg.column;
4735 beg += rb_strlen_lit("else");
4736 while (beg < tok && ISSPACE(*beg)) beg++;
4738 p->token_info->nonspc = 0;
4741 push_end_expect_token_locations(p, &@1.beg_pos);
4745k_unless : keyword_unless
4747 token_info_push(p, "unless", &@$);
4748 push_end_expect_token_locations(p, &@1.beg_pos);
4752k_while : keyword_while allow_exits
4755 token_info_push(p, "while", &@$);
4756 push_end_expect_token_locations(p, &@1.beg_pos);
4760k_until : keyword_until allow_exits
4763 token_info_push(p, "until", &@$);
4764 push_end_expect_token_locations(p, &@1.beg_pos);
4768k_case : keyword_case
4770 token_info_push(p, "case", &@$);
4771 push_end_expect_token_locations(p, &@1.beg_pos);
4775k_for : keyword_for allow_exits
4778 token_info_push(p, "for", &@$);
4779 push_end_expect_token_locations(p, &@1.beg_pos);
4783k_class : keyword_class
4785 token_info_push(p, "class", &@$);
4787 p->ctxt.in_rescue = before_rescue;
4788 push_end_expect_token_locations(p, &@1.beg_pos);
4792k_module : keyword_module
4794 token_info_push(p, "module", &@$);
4796 p->ctxt.in_rescue = before_rescue;
4797 push_end_expect_token_locations(p, &@1.beg_pos);
4803 token_info_push(p, "def", &@$);
4804 $$ = NEW_DEF_TEMP(&@$);
4805 p->ctxt.in_argdef = 1;
4811 token_info_push(p, "do", &@$);
4812 push_end_expect_token_locations(p, &@1.beg_pos);
4816k_do_block : keyword_do_block
4818 token_info_push(p, "do", &@$);
4819 push_end_expect_token_locations(p, &@1.beg_pos);
4823k_rescue : keyword_rescue
4825 token_info_warn(p, "rescue", p->token_info, 1, &@$);
4827 p->ctxt.in_rescue = after_rescue;
4831k_ensure : keyword_ensure
4833 token_info_warn(p, "ensure", p->token_info, 1, &@$);
4838k_when : keyword_when
4840 token_info_warn(p, "when", p->token_info, 0, &@$);
4844k_else : keyword_else
4846 token_info *ptinfo_beg = p->token_info;
4847 int same = ptinfo_beg && strcmp(ptinfo_beg->token, "case") != 0;
4848 token_info_warn(p, "else", p->token_info, same, &@$);
4851 e.next = ptinfo_beg->next;
4853 token_info_setup(&e, p->lex.pbeg, &@$);
4854 if (!e.nonspc) *ptinfo_beg = e;
4859k_elsif : keyword_elsif
4862 token_info_warn(p, "elsif", p->token_info, 1, &@$);
4868 token_info_pop(p, "end", &@$);
4869 pop_end_expect_token_locations(p);
4873 compile_error(p, "syntax error, unexpected end-of-input");
4877k_return : keyword_return
4879 if (p->ctxt.cant_return && !dyna_in_block(p))
4880 yyerror1(&@1, "Invalid return in class/module body");
4884k_yield : keyword_yield
4886 if (!p->ctxt.in_defined && !p->ctxt.in_def && !compile_for_eval)
4887 yyerror1(&@1, "Invalid yield");
4901 | k_elsif expr_value then
4905 $$ = new_if(p, $2, $4, $5, &@$);
4907 /*% ripper: elsif!($:2, $:4, $:5) %*/
4915 /*% ripper: else!($:2) %*/
4925 $$ = assignable(p, $1, 0, &@$);
4926 mark_lvar_used(p, $$);
4928 | tLPAREN f_margs rparen
4931 /*% ripper: mlhs_paren!($:2) %*/
4937 $$ = NEW_LIST($1, &@$);
4938 /*% ripper: mlhs_add!(mlhs_new!, $:1) %*/
4940 | f_marg_list ',' f_marg
4942 $$ = list_append(p, $1, $3);
4943 /*% ripper: mlhs_add!($:1, $:3) %*/
4947f_margs : f_marg_list
4949 $$ = NEW_MASGN($1, 0, &@$);
4952 | f_marg_list ',' f_rest_marg
4954 $$ = NEW_MASGN($1, $3, &@$);
4955 /*% ripper: mlhs_add_star!($:1, $:3) %*/
4957 | f_marg_list ',' f_rest_marg ',' f_marg_list
4959 $$ = NEW_MASGN($1, NEW_POSTARG($3, $5, &@$), &@$);
4960 /*% ripper: mlhs_add_post!(mlhs_add_star!($:1, $:3), $:5) %*/
4964 $$ = NEW_MASGN(0, $1, &@$);
4965 /*% ripper: mlhs_add_star!(mlhs_new!, $:1) %*/
4967 | f_rest_marg ',' f_marg_list
4969 $$ = NEW_MASGN(0, NEW_POSTARG($1, $3, &@$), &@$);
4970 /*% ripper: mlhs_add_post!(mlhs_add_star!(mlhs_new!, $:1), $:3) %*/
4974f_rest_marg : tSTAR f_norm_arg
4977 $$ = assignable(p, $2, 0, &@$);
4978 mark_lvar_used(p, $$);
4982 $$ = NODE_SPECIAL_NO_NAME_REST;
4983 /*% ripper: Qnil %*/
4987f_any_kwrest : f_kwrest
4991 /*% ripper: ID2VAL(idNil) %*/
4995f_eq : {p->ctxt.in_argdef = 0;} '=';
4997block_args_tail : f_kwarg(f_block_kw) ',' f_kwrest opt_f_block_arg
4999 $$ = new_args_tail(p, $1, $3, $4, &@3);
5000 /*% ripper: [$:1, $:3, $:4] %*/
5002 | f_kwarg(f_block_kw) opt_f_block_arg
5004 $$ = new_args_tail(p, $1, 0, $2, &@1);
5005 /*% ripper: [$:1, Qnil, $:2] %*/
5007 | f_any_kwrest opt_f_block_arg
5009 $$ = new_args_tail(p, 0, $1, $2, &@1);
5010 /*% ripper: [Qnil, $:1, $:2] %*/
5014 $$ = new_args_tail(p, 0, 0, $1, &@1);
5015 /*% ripper: [Qnil, Qnil, $:1] %*/
5021 /* magic number for rest_id in iseq_set_arguments() */
5022 $$ = NODE_SPECIAL_EXCESSIVE_COMMA;
5023 /*% ripper: excessed_comma! %*/
5027block_param : f_arg ',' f_optarg(primary_value) ',' f_rest_arg opt_args_tail(block_args_tail)
5029 $$ = new_args(p, $1, $3, $5, 0, $6, &@$);
5030 /*% ripper: params!($:1, $:3, $:5, Qnil, *$:6[0..2]) %*/
5032 | f_arg ',' f_optarg(primary_value) ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
5034 $$ = new_args(p, $1, $3, $5, $7, $8, &@$);
5035 /*% ripper: params!($:1, $:3, $:5, $:7, *$:8[0..2]) %*/
5037 | f_arg ',' f_optarg(primary_value) opt_args_tail(block_args_tail)
5039 $$ = new_args(p, $1, $3, 0, 0, $4, &@$);
5040 /*% ripper: params!($:1, $:3, Qnil, Qnil, *$:4[0..2]) %*/
5042 | f_arg ',' f_optarg(primary_value) ',' f_arg opt_args_tail(block_args_tail)
5044 $$ = new_args(p, $1, $3, 0, $5, $6, &@$);
5045 /*% ripper: params!($:1, $:3, Qnil, $:5, *$:6[0..2]) %*/
5047 | f_arg ',' f_rest_arg opt_args_tail(block_args_tail)
5049 $$ = new_args(p, $1, 0, $3, 0, $4, &@$);
5050 /*% ripper: params!($:1, Qnil, $:3, Qnil, *$:4[0..2]) %*/
5052 | f_arg excessed_comma
5054 $$ = new_args_tail(p, 0, 0, 0, &@2);
5055 $$ = new_args(p, $1, 0, $2, 0, $$, &@$);
5056 /*% ripper: params!($:1, Qnil, $:2, Qnil, Qnil, Qnil, Qnil) %*/
5058 | f_arg ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
5060 $$ = new_args(p, $1, 0, $3, $5, $6, &@$);
5061 /*% ripper: params!($:1, Qnil, $:3, $:5, *$:6[0..2]) %*/
5063 | f_arg opt_args_tail(block_args_tail)
5065 $$ = new_args(p, $1, 0, 0, 0, $2, &@$);
5066 /*% ripper: params!($:1, Qnil, Qnil, Qnil, *$:2[0..2]) %*/
5068 | f_optarg(primary_value) ',' f_rest_arg opt_args_tail(block_args_tail)
5070 $$ = new_args(p, 0, $1, $3, 0, $4, &@$);
5071 /*% ripper: params!(Qnil, $:1, $:3, Qnil, *$:4[0..2]) %*/
5073 | f_optarg(primary_value) ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
5075 $$ = new_args(p, 0, $1, $3, $5, $6, &@$);
5076 /*% ripper: params!(Qnil, $:1, $:3, $:5, *$:6[0..2]) %*/
5078 | f_optarg(primary_value) opt_args_tail(block_args_tail)
5080 $$ = new_args(p, 0, $1, 0, 0, $2, &@$);
5081 /*% ripper: params!(Qnil, $:1, Qnil, Qnil, *$:2[0..2]) %*/
5083 | f_optarg(primary_value) ',' f_arg opt_args_tail(block_args_tail)
5085 $$ = new_args(p, 0, $1, 0, $3, $4, &@$);
5086 /*% ripper: params!(Qnil, $:1, Qnil, $:3, *$:4[0..2]) %*/
5088 | f_rest_arg opt_args_tail(block_args_tail)
5090 $$ = new_args(p, 0, 0, $1, 0, $2, &@$);
5091 /*% ripper: params!(Qnil, Qnil, $:1, Qnil, *$:2[0..2]) %*/
5093 | f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
5095 $$ = new_args(p, 0, 0, $1, $3, $4, &@$);
5096 /*% ripper: params!(Qnil, Qnil, $:1, $:3, *$:4[0..2]) %*/
5100 $$ = new_args(p, 0, 0, 0, 0, $1, &@$);
5101 /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, *$:1[0..2]) %*/
5105opt_block_param : none
5108 p->command_start = TRUE;
5112block_param_def : '|' opt_bv_decl '|'
5114 p->max_numparam = ORDINAL_PARAM;
5115 p->ctxt.in_argdef = 0;
5117 /*% ripper: block_var!(params!(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil), $:2) %*/
5119 | '|' block_param opt_bv_decl '|'
5121 p->max_numparam = ORDINAL_PARAM;
5122 p->ctxt.in_argdef = 0;
5124 /*% ripper: block_var!($:2, $:3) %*/
5132 /*% ripper: Qfalse %*/
5134 | '\n'? ';' bv_decls '\n'?
5142 /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
5144 /*% ripper[brace]: rb_ary_push($:1, $:3) %*/
5159 $$ = p->max_numparam;
5160 p->max_numparam = 0;
5165 $$ = numparam_push(p);
5175lambda : tLAMBDA[lpar]
5177 token_info_push(p, "->", &@1);
5180 max_numparam numparam it_id allow_exits
5187 int max_numparam = p->max_numparam;
5188 ID it_id = p->it_id;
5189 p->lex.lpar_beg = $lpar;
5190 p->max_numparam = $max_numparam;
5192 restore_block_exit(p, $allow_exits);
5194 $args = args_with_numbered(p, $args, max_numparam, it_id);
5196 YYLTYPE loc = code_loc_gen(&@args, &@body);
5197 $$ = NEW_LAMBDA($args, $body, &loc);
5198 nd_set_line(RNODE_LAMBDA($$)->nd_body, @body.end_pos.lineno);
5199 nd_set_line($$, @args.end_pos.lineno);
5200 nd_set_first_loc($$, @1.beg_pos);
5202 /*% ripper: lambda!($:args, $:body) %*/
5203 numparam_pop(p, $numparam);
5208f_larglist : '(' f_args opt_bv_decl ')'
5210 p->ctxt.in_argdef = 0;
5212 p->max_numparam = ORDINAL_PARAM;
5213 /*% ripper: paren!($:2) %*/
5217 p->ctxt.in_argdef = 0;
5218 if (!args_info_empty_p(&$1->nd_ainfo))
5219 p->max_numparam = ORDINAL_PARAM;
5224lambda_body : tLAMBEG compstmt '}'
5226 token_info_pop(p, "}", &@3);
5232 push_end_expect_token_locations(p, &@1.beg_pos);
5241do_block : k_do_block do_body k_end
5244 set_embraced_location($$, &@1, &@3);
5249block_call : command do_block
5251 if (nd_type_p($1, NODE_YIELD)) {
5252 compile_error(p, "block given to yield");
5255 block_dup_check(p, get_nd_args(p, $1), $2);
5257 $$ = method_add_block(p, $1, $2, &@$);
5259 /*% ripper: method_add_block!($:1, $:2) %*/
5261 | block_call call_op2 operation2 opt_paren_args
5263 bool has_args = $4 != 0;
5264 if (NODE_EMPTY_ARGS_P($4)) $4 = 0;
5265 $$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
5266 /*% ripper: call!($:1, $:2, $:3) %*/
5268 /*% ripper: method_add_arg!($:$, $:4) %*/
5271 | block_call call_op2 operation2 opt_paren_args brace_block
5273 if (NODE_EMPTY_ARGS_P($4)) $4 = 0;
5274 $$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
5275 /*% ripper: command_call!($:1, $:2, $:3, $:4) %*/
5277 /*% ripper: method_add_block!($:$, $:5) %*/
5280 | block_call call_op2 operation2 command_args do_block
5282 $$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
5283 /*% ripper: method_add_block!(command_call!($:1, $:2, $:3, $:4), $:5) %*/
5287method_call : fcall paren_args
5291 nd_set_last_loc($1, @2.end_pos);
5292 /*% ripper: method_add_arg!(fcall!($:1), $:2) %*/
5294 | primary_value call_op operation2 opt_paren_args
5296 bool has_args = $4 != 0;
5297 if (NODE_EMPTY_ARGS_P($4)) $4 = 0;
5298 $$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
5299 nd_set_line($$, @3.end_pos.lineno);
5300 /*% ripper: call!($:1, $:2, $:3) %*/
5302 /*% ripper: method_add_arg!($:$, $:4) %*/
5305 | primary_value tCOLON2 operation2 paren_args
5307 $$ = new_qcall(p, idCOLON2, $1, $3, $4, &@3, &@$);
5308 nd_set_line($$, @3.end_pos.lineno);
5309 /*% ripper: method_add_arg!(call!($:1, $:2, $:3), $:4) %*/
5311 | primary_value tCOLON2 operation3
5313 $$ = new_qcall(p, idCOLON2, $1, $3, 0, &@3, &@$);
5314 /*% ripper: call!($:1, $:2, $:3) %*/
5316 | primary_value call_op paren_args
5318 $$ = new_qcall(p, $2, $1, idCall, $3, &@2, &@$);
5319 nd_set_line($$, @2.end_pos.lineno);
5320 /*% ripper: method_add_arg!(call!($:1, $:2, ID2VAL(idCall)), $:3) %*/
5322 | primary_value tCOLON2 paren_args
5324 $$ = new_qcall(p, idCOLON2, $1, idCall, $3, &@2, &@$);
5325 nd_set_line($$, @2.end_pos.lineno);
5326 /*% ripper: method_add_arg!(call!($:1, $:2, ID2VAL(idCall)), $:3) %*/
5328 | keyword_super paren_args
5330 $$ = NEW_SUPER($2, &@$);
5331 /*% ripper: super!($:2) %*/
5335 $$ = NEW_ZSUPER(&@$);
5336 /*% ripper: zsuper! %*/
5338 | primary_value '[' opt_call_args rbracket
5340 $$ = NEW_CALL($1, tAREF, $3, &@$);
5342 /*% ripper: aref!($:1, $:3) %*/
5346brace_block : '{' brace_body '}'
5349 set_embraced_location($$, &@1, &@3);
5352 | k_do do_body k_end
5355 set_embraced_location($$, &@1, &@3);
5360brace_body : {$$ = dyna_push(p);}[dyna]<vars>
5361 max_numparam numparam it_id allow_exits
5362 opt_block_param[args] compstmt
5364 int max_numparam = p->max_numparam;
5365 ID it_id = p->it_id;
5366 p->max_numparam = $max_numparam;
5368 $args = args_with_numbered(p, $args, max_numparam, it_id);
5369 $$ = NEW_ITER($args, $compstmt, &@$);
5370 /*% ripper: brace_block!($:args, $:compstmt) %*/
5371 restore_block_exit(p, $allow_exits);
5372 numparam_pop(p, $numparam);
5381 max_numparam numparam it_id allow_exits
5382 opt_block_param[args] bodystmt
5384 int max_numparam = p->max_numparam;
5385 ID it_id = p->it_id;
5386 p->max_numparam = $max_numparam;
5388 $args = args_with_numbered(p, $args, max_numparam, it_id);
5389 $$ = NEW_ITER($args, $bodystmt, &@$);
5390 /*% ripper: do_block!($:args, $:bodystmt) %*/
5392 restore_block_exit(p, $allow_exits);
5393 numparam_pop(p, $numparam);
5398case_args : arg_value
5400 check_literal_when(p, $arg_value, &@arg_value);
5401 $$ = NEW_LIST($arg_value, &@$);
5402 /*% ripper: args_add!(args_new!, $:arg_value) %*/
5406 $$ = NEW_SPLAT($arg_value, &@$, &@tSTAR);
5407 /*% ripper: args_add_star!(args_new!, $:arg_value) %*/
5409 | case_args[non_last_args] ',' arg_value
5411 check_literal_when(p, $arg_value, &@arg_value);
5412 $$ = last_arg_append(p, $non_last_args, $arg_value, &@$);
5413 /*% ripper: args_add!($:non_last_args, $:arg_value) %*/
5415 | case_args[non_last_args] ',' tSTAR arg_value
5417 $$ = rest_arg_append(p, $non_last_args, $arg_value, &@$);
5418 /*% ripper: args_add_star!($:non_last_args, $:arg_value) %*/
5422case_body : k_when case_args then
5426 $$ = NEW_WHEN($2, $4, $5, &@$, &@1, &@3);
5428 /*% ripper: when!($:2, $:4, $:5) %*/
5436p_pvtbl : {$$ = p->pvtbl; p->pvtbl = st_init_numtable();};
5437p_pktbl : {$$ = p->pktbl; p->pktbl = 0;};
5441 SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
5442 p->command_start = FALSE;
5443 p->ctxt.in_kwarg = 1;
5447p_case_body : keyword_in
5448 p_in_kwarg[ctxt] p_pvtbl p_pktbl
5449 p_top_expr[expr] then
5451 pop_pktbl(p, $p_pktbl);
5452 pop_pvtbl(p, $p_pvtbl);
5453 p->ctxt.in_kwarg = $ctxt.in_kwarg;
5458 $$ = NEW_IN($expr, $compstmt, $cases, &@$);
5459 /*% ripper: in!($:expr, $:compstmt, $:cases) %*/
5467p_top_expr : p_top_expr_body
5468 | p_top_expr_body modifier_if expr_value
5470 $$ = new_if(p, $3, $1, 0, &@$);
5472 /*% ripper: if_mod!($:3, $:1) %*/
5474 | p_top_expr_body modifier_unless expr_value
5476 $$ = new_unless(p, $3, $1, 0, &@$, &@2, &NULL_LOC, &NULL_LOC);
5478 /*% ripper: unless_mod!($:3, $:1) %*/
5482p_top_expr_body : p_expr
5485 $$ = new_array_pattern_tail(p, 0, 1, 0, 0, &@$);
5486 $$ = new_array_pattern(p, 0, $1, $$, &@$);
5487 /*% ripper: aryptn!(Qnil, [$:1], Qnil, Qnil) %*/
5491 $$ = new_array_pattern(p, 0, $1, $3, &@$);
5492 nd_set_first_loc($$, @1.beg_pos);
5493 /*% ripper: aryptn!(Qnil, aryptn_pre_args(p, $:1, $:3[0]), *$:3[1..2]) %*/
5497 $$ = new_find_pattern(p, 0, $1, &@$);
5498 /*% ripper: fndptn!(Qnil, *$:1[0..2]) %*/
5502 $$ = new_array_pattern(p, 0, 0, $1, &@$);
5503 /*% ripper: aryptn!(Qnil, *$:1[0..2]) %*/
5507 $$ = new_hash_pattern(p, 0, $1, &@$);
5508 /*% ripper: hshptn!(Qnil, *$:1[0..1]) %*/
5515p_as : p_expr tASSOC p_variable
5517 NODE *n = NEW_LIST($1, &@$);
5518 n = list_append(p, n, $3);
5519 $$ = new_hash(p, n, &@$);
5520 /*% ripper: binary!($:1, ID2VAL((id_assoc)), $:3) %*/
5525p_alt : p_alt '|' p_expr_basic
5527 $$ = NEW_OR($1, $3, &@$, &@2);
5528 /*% ripper: binary!($:1, ID2VAL(idOr), $:3) %*/
5533p_lparen : '(' p_pktbl
5540p_lbracket : '[' p_pktbl
5547p_expr_basic : p_value
5549 | p_const p_lparen[p_pktbl] p_args rparen
5551 pop_pktbl(p, $p_pktbl);
5552 $$ = new_array_pattern(p, $p_const, 0, $p_args, &@$);
5553 nd_set_first_loc($$, @p_const.beg_pos);
5554 /*% ripper: aryptn!($:p_const, *$:p_args[0..2]) %*/
5556 | p_const p_lparen[p_pktbl] p_find rparen
5558 pop_pktbl(p, $p_pktbl);
5559 $$ = new_find_pattern(p, $p_const, $p_find, &@$);
5560 nd_set_first_loc($$, @p_const.beg_pos);
5561 /*% ripper: fndptn!($:p_const, *$:p_find[0..2]) %*/
5563 | p_const p_lparen[p_pktbl] p_kwargs rparen
5565 pop_pktbl(p, $p_pktbl);
5566 $$ = new_hash_pattern(p, $p_const, $p_kwargs, &@$);
5567 nd_set_first_loc($$, @p_const.beg_pos);
5568 /*% ripper: hshptn!($:p_const, *$:p_kwargs[0..1]) %*/
5570 | p_const '(' rparen
5572 $$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
5573 $$ = new_array_pattern(p, $p_const, 0, $$, &@$);
5574 /*% ripper: aryptn!($:p_const, Qnil, Qnil, Qnil) %*/
5576 | p_const p_lbracket[p_pktbl] p_args rbracket
5578 pop_pktbl(p, $p_pktbl);
5579 $$ = new_array_pattern(p, $p_const, 0, $p_args, &@$);
5580 nd_set_first_loc($$, @p_const.beg_pos);
5581 /*% ripper: aryptn!($:p_const, *$:p_args[0..2]) %*/
5583 | p_const p_lbracket[p_pktbl] p_find rbracket
5585 pop_pktbl(p, $p_pktbl);
5586 $$ = new_find_pattern(p, $p_const, $p_find, &@$);
5587 nd_set_first_loc($$, @p_const.beg_pos);
5588 /*% ripper: fndptn!($:p_const, *$:p_find[0..2]) %*/
5590 | p_const p_lbracket[p_pktbl] p_kwargs rbracket
5592 pop_pktbl(p, $p_pktbl);
5593 $$ = new_hash_pattern(p, $p_const, $p_kwargs, &@$);
5594 nd_set_first_loc($$, @p_const.beg_pos);
5595 /*% ripper: hshptn!($:p_const, *$:p_kwargs[0..1]) %*/
5597 | p_const '[' rbracket
5599 $$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
5600 $$ = new_array_pattern(p, $1, 0, $$, &@$);
5601 /*% ripper: aryptn!($:1, Qnil, Qnil, Qnil) %*/
5603 | tLBRACK p_args rbracket
5605 $$ = new_array_pattern(p, 0, 0, $p_args, &@$);
5606 /*% ripper: aryptn!(Qnil, *$:p_args[0..2]) %*/
5608 | tLBRACK p_find rbracket
5610 $$ = new_find_pattern(p, 0, $p_find, &@$);
5611 /*% ripper: fndptn!(Qnil, *$:p_find[0..2]) %*/
5615 $$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
5616 $$ = new_array_pattern(p, 0, 0, $$, &@$);
5617 /*% ripper: aryptn!(Qnil, Qnil, Qnil, Qnil) %*/
5619 | tLBRACE p_pktbl lex_ctxt[ctxt]
5621 p->ctxt.in_kwarg = 0;
5625 pop_pktbl(p, $p_pktbl);
5626 p->ctxt.in_kwarg = $ctxt.in_kwarg;
5627 $$ = new_hash_pattern(p, 0, $p_kwargs, &@$);
5628 /*% ripper: hshptn!(Qnil, *$:p_kwargs[0..1]) %*/
5632 $$ = new_hash_pattern_tail(p, 0, 0, &@$);
5633 $$ = new_hash_pattern(p, 0, $$, &@$);
5634 /*% ripper: hshptn!(Qnil, Qnil, Qnil) %*/
5636 | tLPAREN p_pktbl p_expr rparen
5638 pop_pktbl(p, $p_pktbl);
5640 /*% ripper: $:p_expr %*/
5646 NODE *pre_args = NEW_LIST($1, &@$);
5647 $$ = new_array_pattern_tail(p, pre_args, 0, 0, 0, &@$);
5648 /*% ripper: [[$:1], Qnil, Qnil] %*/
5652 $$ = new_array_pattern_tail(p, $1, 1, 0, 0, &@$);
5653 /*% ripper: [$:1, Qnil, Qnil] %*/
5657 $$ = new_array_pattern_tail(p, list_concat($1, $2), 0, 0, 0, &@$);
5658 /*% ripper: [rb_ary_concat($:1, $:2), Qnil, Qnil] %*/
5660 | p_args_head p_rest
5662 $$ = new_array_pattern_tail(p, $1, 1, $2, 0, &@$);
5663 /*% ripper: [$:1, $:2, Qnil] %*/
5665 | p_args_head p_rest ',' p_args_post
5667 $$ = new_array_pattern_tail(p, $1, 1, $2, $4, &@$);
5668 /*% ripper: [$:1, $:2, $:4] %*/
5673p_args_head : p_arg ','
5677 | p_args_head p_arg ','
5679 $$ = list_concat($1, $2);
5680 /*% ripper: rb_ary_concat($:1, $:2) %*/
5686 $$ = new_array_pattern_tail(p, 0, 1, $1, 0, &@$);
5687 /*% ripper: [Qnil, $:1, Qnil] %*/
5689 | p_rest ',' p_args_post
5691 $$ = new_array_pattern_tail(p, 0, 1, $1, $3, &@$);
5692 /*% ripper: [Qnil, $:1, $:3] %*/
5696p_find : p_rest ',' p_args_post ',' p_rest
5698 $$ = new_find_pattern_tail(p, $1, $3, $5, &@$);
5699 /*% ripper: [$:1, $:3, $:5] %*/
5704p_rest : tSTAR tIDENTIFIER
5706 error_duplicate_pattern_variable(p, $2, &@2);
5707 /*% ripper: var_field!($:2) %*/
5708 $$ = assignable(p, $2, 0, &@$);
5713 /*% ripper: var_field!(Qnil) %*/
5718 | p_args_post ',' p_arg
5720 $$ = list_concat($1, $3);
5721 /*% ripper: rb_ary_concat($:1, $:3) %*/
5727 $$ = NEW_LIST($1, &@$);
5728 /*% ripper: [$:1] %*/
5732p_kwargs : p_kwarg ',' p_any_kwrest
5734 $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), $3, &@$);
5735 /*% ripper: [$:1, $:3] %*/
5739 $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$);
5740 /*% ripper: [$:1, Qnil] %*/
5744 $$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$);
5745 /*% ripper: [$:1, Qnil] %*/
5749 $$ = new_hash_pattern_tail(p, new_hash(p, 0, &@$), $1, &@$);
5750 /*% ripper: [[], $:1] %*/
5755 /*% ripper[brace]: [$:1] %*/
5758 $$ = list_concat($1, $3);
5759 /*% ripper: rb_ary_push($:1, $:3) %*/
5763p_kw : p_kw_label p_expr
5765 error_duplicate_pattern_key(p, $1, &@1);
5766 $$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@1), &@$), $2);
5767 /*% ripper: [$:1, $:2] %*/
5771 error_duplicate_pattern_key(p, $1, &@1);
5772 if ($1 && !is_local_id($1)) {
5773 yyerror1(&@1, "key must be valid as local variables");
5775 error_duplicate_pattern_variable(p, $1, &@1);
5776 $$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@$), &@$), assignable(p, $1, 0, &@$));
5777 /*% ripper: [$:1, Qnil] %*/
5782 | tSTRING_BEG string_contents tLABEL_END
5784 YYLTYPE loc = code_loc_gen(&@1, &@3);
5785 if (!$2 || nd_type_p($2, NODE_STR)) {
5786 NODE *node = dsym_node(p, $2, &loc);
5787 $$ = rb_sym2id(rb_node_sym_string_val(node));
5790 yyerror1(&loc, "symbol literal with interpolation is not allowed");
5791 $$ = rb_intern_str(STR_NEW0());
5797p_kwrest : kwrest_mark tIDENTIFIER
5800 /*% ripper: var_field!($:2) %*/
5805 /*% ripper: Qnil %*/
5809p_kwnorest : kwrest_mark keyword_nil
5815p_any_kwrest : p_kwrest
5819 /*% ripper: var_field!(ID2VAL(idNil)) %*/
5823p_value : p_primitive
5824 | p_primitive tDOT2 p_primitive
5828 $$ = NEW_DOT2($1, $3, &@$);
5829 /*% ripper: dot2!($:1, $:3) %*/
5831 | p_primitive tDOT3 p_primitive
5835 $$ = NEW_DOT3($1, $3, &@$);
5836 /*% ripper: dot3!($:1, $:3) %*/
5841 $$ = NEW_DOT2($1, new_nil_at(p, &@2.end_pos), &@$);
5842 /*% ripper: dot2!($:1, Qnil) %*/
5847 $$ = NEW_DOT3($1, new_nil_at(p, &@2.end_pos), &@$);
5848 /*% ripper: dot3!($:1, Qnil) %*/
5853 | tBDOT2 p_primitive
5856 $$ = NEW_DOT2(new_nil_at(p, &@1.beg_pos), $2, &@$);
5857 /*% ripper: dot2!(Qnil, $:2) %*/
5859 | tBDOT3 p_primitive
5862 $$ = NEW_DOT3(new_nil_at(p, &@1.beg_pos), $2, &@$);
5863 /*% ripper: dot3!(Qnil, $:2) %*/
5867p_primitive : inline_primary
5870 if (!($$ = gettable(p, $1, &@$))) $$ = NEW_ERROR(&@$);
5871 /*% ripper: var_ref!($:1) %*/
5876p_variable : tIDENTIFIER
5878 error_duplicate_pattern_variable(p, $1, &@1);
5879 /*% ripper: var_field!($:1) %*/
5880 $$ = assignable(p, $1, 0, &@$);
5884p_var_ref : '^' tIDENTIFIER
5886 NODE *n = gettable(p, $2, &@$);
5890 else if (!(nd_type_p(n, NODE_LVAR) || nd_type_p(n, NODE_DVAR))) {
5891 compile_error(p, "%"PRIsVALUE": no such local variable", rb_id2str($2));
5894 /*% ripper: var_ref!($:2) %*/
5898 if (!($$ = gettable(p, $2, &@$))) $$ = NEW_ERROR(&@$);
5899 /*% ripper: var_ref!($:2) %*/
5903p_expr_ref : '^' tLPAREN expr_value rparen
5905 $$ = NEW_BLOCK($3, &@$);
5906 /*% ripper: begin!($:3) %*/
5910p_const : tCOLON3 cname
5912 $$ = NEW_COLON3($2, &@$);
5913 /*% ripper: top_const_ref!($:2) %*/
5915 | p_const tCOLON2 cname
5917 $$ = NEW_COLON2($1, $3, &@$);
5918 /*% ripper: const_path_ref!($:1, $:3) %*/
5922 $$ = gettable(p, $1, &@$);
5923 /*% ripper: var_ref!($:1) %*/
5927opt_rescue : k_rescue exc_list exc_var then
5933 err = NEW_ERRINFO(&@3);
5934 err = node_assign(p, $3, err, NO_LEX_CTXT, &@3);
5936 $$ = NEW_RESBODY($2, $3, $5, $6, &@$);
5946 /*% ripper: rescue!($:2, $:3, $:5, $:6) %*/
5953 $$ = NEW_LIST($1, &@$);
5954 /*% ripper: rb_ary_new3(1, $:1) %*/
5958 if (!($$ = splat_array($1))) $$ = $1;
5971opt_ensure : k_ensure stmts terms?
5973 p->ctxt.in_rescue = $1.in_rescue;
5975 void_expr(p, void_stmts(p, $$));
5976 /*% ripper: ensure!($:2) %*/
5989 node = NEW_STR(STRING_NEW0(), &@$);
5992 node = evstr2dstr(p, node);
6003 $$ = literal_concat(p, $1, $2, &@$);
6004 /*% ripper: string_concat!($:1, $:2) %*/
6008string1 : tSTRING_BEG string_contents tSTRING_END
6010 $$ = heredoc_dedent(p, $2);
6011 if ($$) nd_set_loc($$, &@$);
6013 if (p->heredoc_indent > 0) {
6014 /*% ripper: heredoc_dedent!($:$, INT2NUM(%{p->heredoc_indent})) %*/
6015 p->heredoc_indent = 0;
6017 /*% ripper: string_literal!($:$) %*/
6021xstring : tXSTRING_BEG xstring_contents tSTRING_END
6023 $$ = new_xstring(p, heredoc_dedent(p, $2), &@$);
6025 if (p->heredoc_indent > 0) {
6026 /*% ripper: heredoc_dedent!($:$, INT2NUM(%{p->heredoc_indent})) %*/
6027 p->heredoc_indent = 0;
6029 /*% ripper: xstring_literal!($:$) %*/
6033regexp : tREGEXP_BEG regexp_contents tREGEXP_END
6035 $$ = new_regexp(p, $2, $3, &@$);
6036 /*% ripper: regexp_literal!($:2, $:3) %*/
6040words : words(tWORDS_BEG, word_list) <node>
6043word_list : /* none */
6046 /*% ripper: words_new! %*/
6048 | word_list word ' '+
6050 $$ = list_append(p, $1, evstr2dstr(p, $2));
6051 /*% ripper: words_add!($:1, $:2) %*/
6055word : string_content
6056 /*% ripper[brace]: word_add!(word_new!, $:1) %*/
6057 | word string_content
6059 $$ = literal_concat(p, $1, $2, &@$);
6060 /*% ripper: word_add!($:1, $:2) %*/
6064symbols : words(tSYMBOLS_BEG, symbol_list) <node>
6067symbol_list : /* none */
6070 /*% ripper: symbols_new! %*/
6072 | symbol_list word ' '+
6074 $$ = symbol_append(p, $1, evstr2dstr(p, $2));
6075 /*% ripper: symbols_add!($:1, $:2) %*/
6079qwords : words(tQWORDS_BEG, qword_list) <node>
6082qsymbols : words(tQSYMBOLS_BEG, qsym_list) <node>
6085qword_list : /* none */
6088 /*% ripper: qwords_new! %*/
6090 | qword_list tSTRING_CONTENT ' '+
6092 $$ = list_append(p, $1, $2);
6093 /*% ripper: qwords_add!($:1, $:2) %*/
6097qsym_list : /* none */
6100 /*% ripper: qsymbols_new! %*/
6102 | qsym_list tSTRING_CONTENT ' '+
6104 $$ = symbol_append(p, $1, $2);
6105 /*% ripper: qsymbols_add!($:1, $:2) %*/
6109string_contents : /* none */
6112 /*% ripper: string_content! %*/
6114 | string_contents string_content
6116 $$ = literal_concat(p, $1, $2, &@$);
6117 /*% ripper: string_add!($:1, $:2) %*/
6121xstring_contents: /* none */
6124 /*% ripper: xstring_new! %*/
6126 | xstring_contents string_content
6128 $$ = literal_concat(p, $1, $2, &@$);
6129 /*% ripper: xstring_add!($:1, $:2) %*/
6133regexp_contents: /* none */
6136 /*% ripper: regexp_new! %*/
6138 | regexp_contents string_content
6140 NODE *head = $1, *tail = $2;
6148 switch (nd_type(head)) {
6150 head = str2dstr(p, head);
6155 head = list_append(p, NEW_DSTR(0, &@$), head);
6158 $$ = list_append(p, head, tail);
6160 /*% ripper: regexp_add!($:1, $:2) %*/
6164string_content : tSTRING_CONTENT
6165 /*% ripper[brace]: $:1 %*/
6168 /* need to backup p->lex.strterm so that a string literal `%&foo,#$&,bar&` can be parsed */
6169 $$ = p->lex.strterm;
6171 SET_LEX_STATE(EXPR_BEG);
6175 p->lex.strterm = $2;
6176 $$ = NEW_EVSTR($3, &@$);
6177 nd_set_line($$, @3.end_pos.lineno);
6178 /*% ripper: string_dvar!($:3) %*/
6180 | tSTRING_DBEG[state]
6184 /* need to backup p->lex.strterm so that a string literal `%!foo,#{ !0 },bar!` can be parsed */
6185 $$ = p->lex.strterm;
6187 SET_LEX_STATE(EXPR_BEG);
6190 $$ = p->lex.brace_nest;
6191 p->lex.brace_nest = 0;
6194 $$ = p->heredoc_indent;
6195 p->heredoc_indent = 0;
6197 compstmt string_dend
6201 p->lex.strterm = $term;
6202 SET_LEX_STATE($state);
6203 p->lex.brace_nest = $brace;
6204 p->heredoc_indent = $indent;
6205 p->heredoc_line_indent = -1;
6206 if ($compstmt) nd_unset_fl_newline($compstmt);
6207 $$ = new_evstr(p, $compstmt, &@$);
6208 /*% ripper: string_embexpr!($:compstmt) %*/
6212string_dend : tSTRING_DEND
6216string_dvar : nonlocal_var
6218 if (!($$ = gettable(p, $1, &@$))) $$ = NEW_ERROR(&@$);
6219 /*% ripper: var_ref!($:1) %*/
6230 SET_LEX_STATE(EXPR_END);
6231 VALUE str = rb_id2str($2);
6234 * set_yylval_noname sets invalid id to yylval.
6235 * This branch can be removed once yylval is changed to
6236 * hold lexed string.
6238 if (!str) str = STR_NEW0();
6239 $$ = NEW_SYM(str, &@$);
6240 /*% ripper: symbol_literal!(symbol!($:2)) %*/
6248dsym : tSYMBEG string_contents tSTRING_END
6250 SET_LEX_STATE(EXPR_END);
6251 $$ = dsym_node(p, $2, &@$);
6252 /*% ripper: dyna_symbol!($:2) %*/
6256numeric : simple_numeric
6257 | tUMINUS_NUM simple_numeric %prec tLOWEST
6261 /*% ripper: unary!(ID2VAL(idUMinus), $:2) %*/
6265simple_numeric : tINTEGER
6276user_variable : ident_or_const
6280keyword_variable: keyword_nil {$$ = KWD2EID(nil, $1);}
6281 | keyword_self {$$ = KWD2EID(self, $1);}
6282 | keyword_true {$$ = KWD2EID(true, $1);}
6283 | keyword_false {$$ = KWD2EID(false, $1);}
6284 | keyword__FILE__ {$$ = KWD2EID(_FILE__, $1);}
6285 | keyword__LINE__ {$$ = KWD2EID(_LINE__, $1);}
6286 | keyword__ENCODING__ {$$ = KWD2EID(_ENCODING__, $1);}
6289var_ref : user_variable
6291 if (!($$ = gettable(p, $1, &@$))) $$ = NEW_ERROR(&@$);
6292 if (ifdef_ripper(id_is_var(p, $1), false)) {
6293 /*% ripper: var_ref!($:1) %*/
6296 /*% ripper: vcall!($:1) %*/
6301 if (!($$ = gettable(p, $1, &@$))) $$ = NEW_ERROR(&@$);
6302 /*% ripper: var_ref!($:1) %*/
6306var_lhs : user_or_keyword_variable
6308 /*% ripper: var_field!($:1) %*/
6309 $$ = assignable(p, $1, 0, &@$);
6319 SET_LEX_STATE(EXPR_BEG);
6320 p->command_start = TRUE;
6330 /*% ripper: Qnil %*/
6334f_opt_paren_args: f_paren_args
6337 p->ctxt.in_argdef = 0;
6338 $$ = new_args_tail(p, 0, 0, 0, &@0);
6339 $$ = new_args(p, 0, 0, 0, 0, $$, &@0);
6340 /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil) %*/
6344f_paren_args : '(' f_args rparen
6347 /*% ripper: paren!($:2) %*/
6348 SET_LEX_STATE(EXPR_BEG);
6349 p->command_start = TRUE;
6350 p->ctxt.in_argdef = 0;
6354f_arglist : f_paren_args
6357 p->ctxt.in_kwarg = 1;
6358 p->ctxt.in_argdef = 1;
6359 SET_LEX_STATE(p->lex.state|EXPR_LABEL); /* force for args */
6363 p->ctxt.in_kwarg = $1.in_kwarg;
6364 p->ctxt.in_argdef = 0;
6366 SET_LEX_STATE(EXPR_BEG);
6367 p->command_start = TRUE;
6372args_tail : f_kwarg(f_kw) ',' f_kwrest opt_f_block_arg
6374 $$ = new_args_tail(p, $1, $3, $4, &@3);
6375 /*% ripper: [$:1, $:3, $:4] %*/
6377 | f_kwarg(f_kw) opt_f_block_arg
6379 $$ = new_args_tail(p, $1, 0, $2, &@1);
6380 /*% ripper: [$:1, Qnil, $:2] %*/
6382 | f_any_kwrest opt_f_block_arg
6384 $$ = new_args_tail(p, 0, $1, $2, &@1);
6385 /*% ripper: [Qnil, $:1, $:2] %*/
6389 $$ = new_args_tail(p, 0, 0, $1, &@1);
6390 /*% ripper: [Qnil, Qnil, $:1] %*/
6394 ID fwd = $args_forward;
6395 if (lambda_beginning_p() ||
6396 (p->lex.lpar_beg >= 0 && p->lex.lpar_beg+1 == p->lex.paren_nest)) {
6397 yyerror0("unexpected ... in lambda argument");
6401 add_forwarding_args(p);
6403 $$ = new_args_tail(p, 0, fwd, arg_FWD_BLOCK, &@1);
6404 $$->nd_ainfo.forwarding = 1;
6405 /*% ripper: [Qnil, $:1, Qnil] %*/
6409f_args : f_arg ',' f_optarg(arg_value) ',' f_rest_arg opt_args_tail(args_tail)
6411 $$ = new_args(p, $1, $3, $5, 0, $6, &@$);
6412 /*% ripper: params!($:1, $:3, $:5, Qnil, *$:6[0..2]) %*/
6414 | f_arg ',' f_optarg(arg_value) ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
6416 $$ = new_args(p, $1, $3, $5, $7, $8, &@$);
6417 /*% ripper: params!($:1, $:3, $:5, $:7, *$:8[0..2]) %*/
6419 | f_arg ',' f_optarg(arg_value) opt_args_tail(args_tail)
6421 $$ = new_args(p, $1, $3, 0, 0, $4, &@$);
6422 /*% ripper: params!($:1, $:3, Qnil, Qnil, *$:4[0..2]) %*/
6424 | f_arg ',' f_optarg(arg_value) ',' f_arg opt_args_tail(args_tail)
6426 $$ = new_args(p, $1, $3, 0, $5, $6, &@$);
6427 /*% ripper: params!($:1, $:3, Qnil, $:5, *$:6[0..2]) %*/
6429 | f_arg ',' f_rest_arg opt_args_tail(args_tail)
6431 $$ = new_args(p, $1, 0, $3, 0, $4, &@$);
6432 /*% ripper: params!($:1, Qnil, $:3, Qnil, *$:4[0..2]) %*/
6434 | f_arg ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
6436 $$ = new_args(p, $1, 0, $3, $5, $6, &@$);
6437 /*% ripper: params!($:1, Qnil, $:3, $:5, *$:6[0..2]) %*/
6439 | f_arg opt_args_tail(args_tail)
6441 $$ = new_args(p, $1, 0, 0, 0, $2, &@$);
6442 /*% ripper: params!($:1, Qnil, Qnil, Qnil, *$:2[0..2]) %*/
6444 | f_optarg(arg_value) ',' f_rest_arg opt_args_tail(args_tail)
6446 $$ = new_args(p, 0, $1, $3, 0, $4, &@$);
6447 /*% ripper: params!(Qnil, $:1, $:3, Qnil, *$:4[0..2]) %*/
6449 | f_optarg(arg_value) ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
6451 $$ = new_args(p, 0, $1, $3, $5, $6, &@$);
6452 /*% ripper: params!(Qnil, $:1, $:3, $:5, *$:6[0..2]) %*/
6454 | f_optarg(arg_value) opt_args_tail(args_tail)
6456 $$ = new_args(p, 0, $1, 0, 0, $2, &@$);
6457 /*% ripper: params!(Qnil, $:1, Qnil, Qnil, *$:2[0..2]) %*/
6459 | f_optarg(arg_value) ',' f_arg opt_args_tail(args_tail)
6461 $$ = new_args(p, 0, $1, 0, $3, $4, &@$);
6462 /*% ripper: params!(Qnil, $:1, Qnil, $:3, *$:4[0..2]) %*/
6464 | f_rest_arg opt_args_tail(args_tail)
6466 $$ = new_args(p, 0, 0, $1, 0, $2, &@$);
6467 /*% ripper: params!(Qnil, Qnil, $:1, Qnil, *$:2[0..2]) %*/
6469 | f_rest_arg ',' f_arg opt_args_tail(args_tail)
6471 $$ = new_args(p, 0, 0, $1, $3, $4, &@$);
6472 /*% ripper: params!(Qnil, Qnil, $:1, $:3, *$:4[0..2]) %*/
6476 $$ = new_args(p, 0, 0, 0, 0, $1, &@$);
6477 /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, *$:1[0..2]) %*/
6481 $$ = new_args_tail(p, 0, 0, 0, &@0);
6482 $$ = new_args(p, 0, 0, 0, 0, $$, &@0);
6483 /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil) %*/
6487args_forward : tBDOT3
6489#ifdef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
6494 /*% ripper: args_forward! %*/
6498f_bad_arg : tCONSTANT
6500 static const char mesg[] = "formal argument cannot be a constant";
6502 yyerror1(&@1, mesg);
6505 /*% ripper[error]: param_error!(ERR_MESG(), $:1) %*/
6509 static const char mesg[] = "formal argument cannot be an instance variable";
6511 yyerror1(&@1, mesg);
6514 /*% ripper[error]: param_error!(ERR_MESG(), $:1) %*/
6518 static const char mesg[] = "formal argument cannot be a global variable";
6520 yyerror1(&@1, mesg);
6523 /*% ripper[error]: param_error!(ERR_MESG(), $:1) %*/
6527 static const char mesg[] = "formal argument cannot be a class variable";
6529 yyerror1(&@1, mesg);
6532 /*% ripper[error]: param_error!(ERR_MESG(), $:1) %*/
6536f_norm_arg : f_bad_arg
6539 VALUE e = formal_argument_error(p, $$ = $1);
6541 /*% ripper[error]: param_error!(?e, $:1) %*/
6543 p->max_numparam = ORDINAL_PARAM;
6547f_arg_asgn : f_norm_arg
6555f_arg_item : f_arg_asgn
6557 $$ = NEW_ARGS_AUX($1, 1, &NULL_LOC);
6560 | tLPAREN f_margs rparen
6562 ID tid = internal_id(p);
6564 loc.beg_pos = @2.beg_pos;
6565 loc.end_pos = @2.beg_pos;
6567 if (dyna_in_block(p)) {
6568 $2->nd_value = NEW_DVAR(tid, &loc);
6571 $2->nd_value = NEW_LVAR(tid, &loc);
6573 $$ = NEW_ARGS_AUX(tid, 1, &NULL_LOC);
6574 $$->nd_next = (NODE *)$2;
6575 /*% ripper: mlhs_paren!($:2) %*/
6580 /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
6581 | f_arg ',' f_arg_item
6585 $$->nd_next = block_append(p, $$->nd_next, $3->nd_next);
6586 rb_discard_node(p, (NODE *)$3);
6587 /*% ripper: rb_ary_push($:1, $:3) %*/
6594 VALUE e = formal_argument_error(p, $$ = $1);
6597 /*% ripper[error]: param_error!(?e, $:1) %*/
6600 * Workaround for Prism::ParseTest#test_filepath for
6601 * "unparser/corpus/literal/def.txt"
6603 * See the discussion on https://github.com/ruby/ruby/pull/9923
6605 arg_var(p, ifdef_ripper(0, $1));
6607 p->max_numparam = ORDINAL_PARAM;
6608 p->ctxt.in_argdef = 0;
6612f_kw : f_label arg_value
6614 p->ctxt.in_argdef = 1;
6615 $$ = new_kw_arg(p, assignable(p, $1, $2, &@$), &@$);
6616 /*% ripper: [$:$, $:2] %*/
6620 p->ctxt.in_argdef = 1;
6621 $$ = new_kw_arg(p, assignable(p, $1, NODE_SPECIAL_REQUIRED_KEYWORD, &@$), &@$);
6622 /*% ripper: [$:$, 0] %*/
6626f_block_kw : f_label primary_value
6628 p->ctxt.in_argdef = 1;
6629 $$ = new_kw_arg(p, assignable(p, $1, $2, &@$), &@$);
6630 /*% ripper: [$:$, $:2] %*/
6634 p->ctxt.in_argdef = 1;
6635 $$ = new_kw_arg(p, assignable(p, $1, NODE_SPECIAL_REQUIRED_KEYWORD, &@$), &@$);
6636 /*% ripper: [$:$, 0] %*/
6644f_no_kwarg : p_kwnorest
6646 /*% ripper: nokw_param!(Qnil) %*/
6650f_kwrest : kwrest_mark tIDENTIFIER
6652 arg_var(p, shadowing_lvar(p, $2));
6654 /*% ripper: kwrest_param!($:2) %*/
6658 arg_var(p, idFWD_KWREST);
6660 /*% ripper: kwrest_param!(Qnil) %*/
6668f_rest_arg : restarg_mark tIDENTIFIER
6670 arg_var(p, shadowing_lvar(p, $2));
6672 /*% ripper: rest_param!($:2) %*/
6676 arg_var(p, idFWD_REST);
6678 /*% ripper: rest_param!(Qnil) %*/
6686f_block_arg : blkarg_mark tIDENTIFIER
6688 arg_var(p, shadowing_lvar(p, $2));
6690 /*% ripper: blockarg!($:2) %*/
6694 arg_var(p, idFWD_BLOCK);
6696 /*% ripper: blockarg!(Qnil) %*/
6700opt_f_block_arg : ',' f_block_arg
6708 /*% ripper: Qnil %*/
6719 SET_LEX_STATE(EXPR_BEG);
6720 p->ctxt.in_argdef = 0;
6724 p->ctxt.in_argdef = 1;
6725 NODE *expr = last_expr_node($3);
6726 switch (nd_type(expr)) {
6740 case NODE_IMAGINARY:
6744 yyerror1(&expr->nd_loc, "can't define singleton method for literals");
6751 /*% ripper: paren!($:3) %*/
6759 /*% ripper: assoclist_from_args!($:1) %*/
6764 /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
6773 if (RNODE_LIST(assocs)->nd_head) {
6774 NODE *n = RNODE_LIST(tail)->nd_next;
6775 if (!RNODE_LIST(tail)->nd_head && nd_type_p(n, NODE_LIST) &&
6776 nd_type_p((n = RNODE_LIST(n)->nd_head), NODE_HASH)) {
6778 tail = RNODE_HASH(n)->nd_head;
6782 assocs = list_concat(assocs, tail);
6786 /*% ripper: rb_ary_push($:1, $:3) %*/
6790assoc : arg_value tASSOC arg_value
6792 $$ = list_append(p, NEW_LIST($1, &@$), $3);
6793 /*% ripper: assoc_new!($:1, $:3) %*/
6797 $$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@1), &@$), $2);
6798 /*% ripper: assoc_new!($:1, $:2) %*/
6802 NODE *val = gettable(p, $1, &@$);
6803 if (!val) val = NEW_ERROR(&@$);
6804 $$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@1), &@$), val);
6805 /*% ripper: assoc_new!($:1, Qnil) %*/
6807 | tSTRING_BEG string_contents tLABEL_END arg_value
6809 YYLTYPE loc = code_loc_gen(&@1, &@3);
6810 $$ = list_append(p, NEW_LIST(dsym_node(p, $2, &loc), &loc), $4);
6811 /*% ripper: assoc_new!(dyna_symbol!($:2), $:4) %*/
6815 $$ = list_append(p, NEW_LIST(0, &@$), $2);
6816 /*% ripper: assoc_splat!($:2) %*/
6820 forwarding_arg_check(p, idFWD_KWREST, idFWD_ALL, "keyword rest");
6821 $$ = list_append(p, NEW_LIST(0, &@$),
6822 NEW_LVAR(idFWD_KWREST, &@$));
6823 /*% ripper: assoc_splat!(Qnil) %*/
6827operation : ident_or_const
6831operation2 : operation
6835operation3 : tIDENTIFIER
6865term : ';' {yyerrok;token_flush(p);}
6868 @$.end_pos = @$.beg_pos;
6874 | terms ';' {yyerrok;}
6886# define yylval (*p->lval)
6888static int regx_options(struct parser_params*);
6889static int tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**,rb_encoding**);
6890static void tokaddmbc(struct parser_params *p, int c, rb_encoding *enc);
6891static enum yytokentype parse_string(struct parser_params*,rb_strterm_literal_t*);
6892static enum yytokentype here_document(struct parser_params*,rb_strterm_heredoc_t*);
6894#define set_parser_s_value(x) (ifdef_ripper(p->s_value = (x), (void)0))
6896# define set_yylval_node(x) { \
6898 rb_parser_set_location(p, &_cur_loc); \
6899 yylval.node = (x); \
6900 set_parser_s_value(STR_NEW(p->lex.ptok, p->lex.pcur-p->lex.ptok)); \
6902# define set_yylval_str(x) \
6904 set_yylval_node(NEW_STR(x, &_cur_loc)); \
6905 set_parser_s_value(rb_str_new_mutable_parser_string(x)); \
6907# define set_yylval_num(x) { \
6909 set_parser_s_value(x); \
6911# define set_yylval_id(x) (yylval.id = (x))
6912# define set_yylval_name(x) { \
6913 (yylval.id = (x)); \
6914 set_parser_s_value(ID2SYM(x)); \
6916# define yylval_id() (yylval.id)
6918#define set_yylval_noname() set_yylval_id(keyword_nil)
6919#define has_delayed_token(p) (p->delayed.token != NULL)
6922#define literal_flush(p, ptr) ((p)->lex.ptok = (ptr))
6923#define dispatch_scan_event(p, t) parser_dispatch_scan_event(p, t, __LINE__)
6926parser_has_token(struct parser_params *p)
6928 const char *const pcur = p->lex.pcur;
6929 const char *const ptok = p->lex.ptok;
6930 if (p->keep_tokens && (pcur < ptok)) {
6931 rb_bug("lex.pcur < lex.ptok. (line: %d) %"PRIdPTRDIFF"|%"PRIdPTRDIFF"|%"PRIdPTRDIFF"",
6932 p->ruby_sourceline, ptok - p->lex.pbeg, pcur - ptok, p->lex.pend - pcur);
6941 case '"': return "\\\"";
6942 case '\\': return "\\\\";
6943 case '\0': return "\\0";
6944 case '\n': return "\\n";
6945 case '\r': return "\\r";
6946 case '\t': return "\\t";
6947 case '\f': return "\\f";
6948 case '\013': return "\\v";
6949 case '\010': return "\\b";
6950 case '\007': return "\\a";
6951 case '\033': return "\\e";
6952 case '\x7f': return "\\c?";
6957static rb_parser_string_t *
6958rb_parser_str_escape(struct parser_params *p, rb_parser_string_t *str)
6960 rb_encoding *enc = p->enc;
6961 const char *ptr = str->ptr;
6962 const char *pend = ptr + str->len;
6963 const char *prev = ptr;
6964 char charbuf[5] = {'\\', 'x', 0, 0, 0};
6965 rb_parser_string_t * result = rb_parser_string_new(p, 0, 0);
6967 while (ptr < pend) {
6970 int n = rb_enc_precise_mbclen(ptr, pend, enc);
6971 if (!MBCLEN_CHARFOUND_P(n)) {
6972 if (ptr > prev) parser_str_cat(result, prev, ptr - prev);
6973 n = rb_enc_mbminlen(enc);
6975 n = (int)(pend - ptr);
6977 c = *ptr & 0xf0 >> 4;
6978 charbuf[2] = (c < 10) ? '0' + c : 'A' + c - 10;
6980 charbuf[3] = (c < 10) ? '0' + c : 'A' + c - 10;
6981 parser_str_cat(result, charbuf, 4);
6986 n = MBCLEN_CHARFOUND_LEN(n);
6987 c = rb_enc_mbc_to_codepoint(ptr, pend, enc);
6989 cc = escaped_char(c);
6991 if (ptr - n > prev) parser_str_cat(result, prev, ptr - n - prev);
6992 parser_str_cat_cstr(result, cc);
6995 else if (rb_enc_isascii(c, enc) && ISPRINT(c)) {
6998 if (ptr - n > prev) {
6999 parser_str_cat(result, prev, ptr - n - prev);
7002 parser_str_cat(result, prev, ptr - prev);
7006 if (ptr > prev) parser_str_cat(result, prev, ptr - prev);
7012parser_append_tokens(struct parser_params *p, rb_parser_string_t *str, enum yytokentype t, int line)
7014 rb_parser_ast_token_t *token = xcalloc(1, sizeof(rb_parser_ast_token_t));
7015 token->id = p->token_id;
7016 token->type_name = parser_token2char(p, t);
7018 token->loc.beg_pos = p->yylloc->beg_pos;
7019 token->loc.end_pos = p->yylloc->end_pos;
7020 rb_parser_ary_push_ast_token(p, p->tokens, token);
7024 rb_parser_string_t *str_escaped = rb_parser_str_escape(p, str);
7025 rb_parser_printf(p, "Append tokens (line: %d) [%d, :%s, \"%s\", [%d, %d, %d, %d]]\n",
7026 line, token->id, token->type_name, str_escaped->ptr,
7027 token->loc.beg_pos.lineno, token->loc.beg_pos.column,
7028 token->loc.end_pos.lineno, token->loc.end_pos.column);
7029 rb_parser_string_free(p, str_escaped);
7034parser_dispatch_scan_event(struct parser_params *p, enum yytokentype t, int line)
7036 debug_token_line(p, "parser_dispatch_scan_event", line);
7038 if (!parser_has_token(p)) return;
7040 RUBY_SET_YYLLOC(*p->yylloc);
7042 if (p->keep_tokens) {
7043 rb_parser_string_t *str = rb_parser_encoding_string_new(p, p->lex.ptok, p->lex.pcur - p->lex.ptok, p->enc);
7044 parser_append_tokens(p, str, t, line);
7050#define dispatch_delayed_token(p, t) parser_dispatch_delayed_token(p, t, __LINE__)
7052parser_dispatch_delayed_token(struct parser_params *p, enum yytokentype t, int line)
7054 debug_token_line(p, "parser_dispatch_delayed_token", line);
7056 if (!has_delayed_token(p)) return;
7058 RUBY_SET_YYLLOC_OF_DELAYED_TOKEN(*p->yylloc);
7060 if (p->keep_tokens) {
7061 /* p->delayed.token is freed by rb_parser_tokens_free */
7062 parser_append_tokens(p, p->delayed.token, t, line);
7064 rb_parser_string_free(p, p->delayed.token);
7067 p->delayed.token = NULL;
7070#define literal_flush(p, ptr) ((void)(ptr))
7073ripper_has_scan_event(struct parser_params *p)
7075 if (p->lex.pcur < p->lex.ptok) rb_raise(rb_eRuntimeError, "lex.pcur < lex.ptok");
7076 return p->lex.pcur > p->lex.ptok;
7080ripper_scan_event_val(struct parser_params *p, enum yytokentype t)
7082 VALUE str = STR_NEW(p->lex.ptok, p->lex.pcur - p->lex.ptok);
7083 VALUE rval = ripper_dispatch1(p, ripper_token2eventid(t), str);
7084 RUBY_SET_YYLLOC(*p->yylloc);
7090ripper_dispatch_scan_event(struct parser_params *p, enum yytokentype t)
7092 if (!ripper_has_scan_event(p)) return;
7094 set_parser_s_value(ripper_scan_event_val(p, t));
7096#define dispatch_scan_event(p, t) ripper_dispatch_scan_event(p, t)
7099ripper_dispatch_delayed_token(struct parser_params *p, enum yytokentype t)
7101 /* save and adjust the location to delayed token for callbacks */
7102 int saved_line = p->ruby_sourceline;
7103 const char *saved_tokp = p->lex.ptok;
7106 if (!has_delayed_token(p)) return;
7107 p->ruby_sourceline = p->delayed.beg_line;
7108 p->lex.ptok = p->lex.pbeg + p->delayed.beg_col;
7109 str = rb_str_new_mutable_parser_string(p->delayed.token);
7110 rb_parser_string_free(p, p->delayed.token);
7111 s_value = ripper_dispatch1(p, ripper_token2eventid(t), str);
7112 set_parser_s_value(s_value);
7113 p->delayed.token = NULL;
7114 p->ruby_sourceline = saved_line;
7115 p->lex.ptok = saved_tokp;
7117#define dispatch_delayed_token(p, t) ripper_dispatch_delayed_token(p, t)
7121is_identchar(struct parser_params *p, const char *ptr, const char *MAYBE_UNUSED(ptr_end), rb_encoding *enc)
7123 return rb_enc_isalnum((unsigned char)*ptr, enc) || *ptr == '_' || !ISASCII(*ptr);
7127parser_is_identchar(struct parser_params *p)
7129 return !(p)->eofp && is_identchar(p, p->lex.pcur-1, p->lex.pend, p->enc);
7133parser_isascii(struct parser_params *p)
7135 return ISASCII(*(p->lex.pcur-1));
7139token_info_setup(token_info *ptinfo, const char *ptr, const rb_code_location_t *loc)
7141 int column = 1, nonspc = 0, i;
7142 for (i = 0; i < loc->beg_pos.column; i++, ptr++) {
7144 column = (((column - 1) / TAB_WIDTH) + 1) * TAB_WIDTH;
7147 if (*ptr != ' ' && *ptr != '\t') {
7152 ptinfo->beg = loc->beg_pos;
7153 ptinfo->indent = column;
7154 ptinfo->nonspc = nonspc;
7158token_info_push(struct parser_params *p, const char *token, const rb_code_location_t *loc)
7162 if (!p->token_info_enabled) return;
7163 ptinfo = ALLOC(token_info);
7164 ptinfo->token = token;
7165 ptinfo->next = p->token_info;
7166 token_info_setup(ptinfo, p->lex.pbeg, loc);
7168 p->token_info = ptinfo;
7172token_info_pop(struct parser_params *p, const char *token, const rb_code_location_t *loc)
7174 token_info *ptinfo_beg = p->token_info;
7176 if (!ptinfo_beg) return;
7178 /* indentation check of matched keywords (begin..end, if..end, etc.) */
7179 token_info_warn(p, token, ptinfo_beg, 1, loc);
7181 p->token_info = ptinfo_beg->next;
7182 ruby_sized_xfree(ptinfo_beg, sizeof(*ptinfo_beg));
7186token_info_drop(struct parser_params *p, const char *token, rb_code_position_t beg_pos)
7188 token_info *ptinfo_beg = p->token_info;
7190 if (!ptinfo_beg) return;
7191 p->token_info = ptinfo_beg->next;
7193 if (ptinfo_beg->beg.lineno != beg_pos.lineno ||
7194 ptinfo_beg->beg.column != beg_pos.column ||
7195 strcmp(ptinfo_beg->token, token)) {
7196 compile_error(p, "token position mismatch: %d:%d:%s expected but %d:%d:%s",
7197 beg_pos.lineno, beg_pos.column, token,
7198 ptinfo_beg->beg.lineno, ptinfo_beg->beg.column,
7202 ruby_sized_xfree(ptinfo_beg, sizeof(*ptinfo_beg));
7206token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc)
7208 token_info ptinfo_end_body, *ptinfo_end = &ptinfo_end_body;
7209 if (!p->token_info_enabled) return;
7210 if (!ptinfo_beg) return;
7211 token_info_setup(ptinfo_end, p->lex.pbeg, loc);
7212 if (ptinfo_beg->beg.lineno == ptinfo_end->beg.lineno) return; /* ignore one-line block */
7213 if (ptinfo_beg->nonspc || ptinfo_end->nonspc) return; /* ignore keyword in the middle of a line */
7214 if (ptinfo_beg->indent == ptinfo_end->indent) return; /* the indents are matched */
7215 if (!same && ptinfo_beg->indent < ptinfo_end->indent) return;
7216 rb_warn3L(ptinfo_end->beg.lineno,
7217 "mismatched indentations at '%s' with '%s' at %d",
7218 WARN_S(token), WARN_S(ptinfo_beg->token), WARN_I(ptinfo_beg->beg.lineno));
7222parser_precise_mbclen(struct parser_params *p, const char *ptr)
7224 int len = rb_enc_precise_mbclen(ptr, p->lex.pend, p->enc);
7225 if (!MBCLEN_CHARFOUND_P(len)) {
7226 compile_error(p, "invalid multibyte char (%s)", rb_enc_name(p->enc));
7234parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc)
7236 rb_parser_string_t *str;
7237 int lineno = p->ruby_sourceline;
7241 else if (yylloc->beg_pos.lineno == lineno) {
7242 str = p->lex.lastline;
7247 ruby_show_error_line(p, p->error_buffer, yylloc, lineno, str);
7251parser_yyerror(struct parser_params *p, const rb_code_location_t *yylloc, const char *msg)
7257 yylloc = RUBY_SET_YYLLOC(current);
7259 else if ((p->ruby_sourceline != yylloc->beg_pos.lineno &&
7260 p->ruby_sourceline != yylloc->end_pos.lineno)) {
7264 parser_compile_error(p, yylloc, "%s", msg);
7265 parser_show_error_line(p, yylloc);
7270parser_yyerror0(struct parser_params *p, const char *msg)
7273 return parser_yyerror(p, RUBY_SET_YYLLOC(current), msg);
7277ruby_show_error_line(struct parser_params *p, VALUE errbuf, const YYLTYPE *yylloc, int lineno, rb_parser_string_t *str)
7280 const int max_line_margin = 30;
7281 const char *ptr, *ptr_end, *pt, *pb;
7282 const char *pre = "", *post = "", *pend;
7283 const char *code = "", *caret = "";
7285 const char *const pbeg = PARSER_STRING_PTR(str);
7290 if (!yylloc) return;
7291 pend = rb_parser_string_end(str);
7292 if (pend > pbeg && pend[-1] == '\n') {
7293 if (--pend > pbeg && pend[-1] == '\r') --pend;
7297 if (lineno == yylloc->end_pos.lineno &&
7298 (pend - pbeg) > yylloc->end_pos.column) {
7299 pt = pbeg + yylloc->end_pos.column;
7303 lim = ptr - pbeg > max_line_margin ? ptr - max_line_margin : pbeg;
7304 while ((lim < ptr) && (*(ptr-1) != '\n')) ptr--;
7306 lim = pend - ptr_end > max_line_margin ? ptr_end + max_line_margin : pend;
7307 while ((ptr_end < lim) && (*ptr_end != '\n') && (*ptr_end != '\r')) ptr_end++;
7309 len = ptr_end - ptr;
7312 ptr = rb_enc_prev_char(pbeg, ptr, pt, rb_parser_str_get_encoding(str));
7313 if (ptr > pbeg) pre = "...";
7315 if (ptr_end < pend) {
7316 ptr_end = rb_enc_prev_char(pt, ptr_end, pend, rb_parser_str_get_encoding(str));
7317 if (ptr_end < pend) post = "...";
7321 if (lineno == yylloc->beg_pos.lineno) {
7322 pb += yylloc->beg_pos.column;
7323 if (pb > pt) pb = pt;
7325 if (pb < ptr) pb = ptr;
7326 if (len <= 4 && yylloc->beg_pos.lineno == yylloc->end_pos.lineno) {
7329 if (RTEST(errbuf)) {
7330 mesg = rb_attr_get(errbuf, idMesg);
7331 if (char_at_end(p, mesg, '\n') != '\n')
7332 rb_str_cat_cstr(mesg, "\n");
7335 mesg = rb_enc_str_new(0, 0, rb_parser_str_get_encoding(str));
7337 if (!errbuf && rb_stderr_tty_p()) {
7338#define CSI_BEGIN "\033["
7341 CSI_BEGIN""CSI_SGR"%s" /* pre */
7342 CSI_BEGIN"1"CSI_SGR"%.*s"
7343 CSI_BEGIN"1;4"CSI_SGR"%.*s"
7344 CSI_BEGIN";1"CSI_SGR"%.*s"
7345 CSI_BEGIN""CSI_SGR"%s" /* post */
7348 (int)(pb - ptr), ptr,
7350 (int)(ptr_end - pt), pt,
7356 len = ptr_end - ptr;
7357 lim = pt < pend ? pt : pend;
7358 i = (int)(lim - ptr);
7359 buf = ALLOCA_N(char, i+2);
7364 *p2++ = *ptr++ == '\t' ? '\t' : ' ';
7370 memset(p2, '~', (lim - ptr));
7374 rb_str_catf(mesg, "%s%.*s%s\n""%s%s\n",
7375 pre, (int)len, code, post,
7378 if (!errbuf) rb_write_error_str(mesg);
7383parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg)
7385 const char *pcur = 0, *ptok = 0;
7386 if (p->ruby_sourceline == yylloc->beg_pos.lineno &&
7387 p->ruby_sourceline == yylloc->end_pos.lineno) {
7390 p->lex.ptok = p->lex.pbeg + yylloc->beg_pos.column;
7391 p->lex.pcur = p->lex.pbeg + yylloc->end_pos.column;
7393 parser_yyerror0(p, msg);
7402parser_yyerror0(struct parser_params *p, const char *msg)
7404 dispatch1(parse_error, STR_NEW2(msg));
7410parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc)
7416vtable_size(const struct vtable *tbl)
7418 if (!DVARS_TERMINAL_P(tbl)) {
7426static struct vtable *
7427vtable_alloc_gen(struct parser_params *p, int line, struct vtable *prev)
7429 struct vtable *tbl = ALLOC(struct vtable);
7432 tbl->tbl = ALLOC_N(ID, tbl->capa);
7436 rb_parser_printf(p, "vtable_alloc:%d: %p\n", line, (void *)tbl);
7441#define vtable_alloc(prev) vtable_alloc_gen(p, __LINE__, prev)
7444vtable_free_gen(struct parser_params *p, int line, const char *name,
7449 rb_parser_printf(p, "vtable_free:%d: %s(%p)\n", line, name, (void *)tbl);
7452 if (!DVARS_TERMINAL_P(tbl)) {
7454 ruby_sized_xfree(tbl->tbl, tbl->capa * sizeof(ID));
7456 ruby_sized_xfree(tbl, sizeof(*tbl));
7459#define vtable_free(tbl) vtable_free_gen(p, __LINE__, #tbl, tbl)
7462vtable_add_gen(struct parser_params *p, int line, const char *name,
7463 struct vtable *tbl, ID id)
7467 rb_parser_printf(p, "vtable_add:%d: %s(%p), %s\n",
7468 line, name, (void *)tbl, rb_id2name(id));
7471 if (DVARS_TERMINAL_P(tbl)) {
7472 rb_parser_fatal(p, "vtable_add: vtable is not allocated (%p)", (void *)tbl);
7475 if (tbl->pos == tbl->capa) {
7476 tbl->capa = tbl->capa * 2;
7477 SIZED_REALLOC_N(tbl->tbl, ID, tbl->capa, tbl->pos);
7479 tbl->tbl[tbl->pos++] = id;
7481#define vtable_add(tbl, id) vtable_add_gen(p, __LINE__, #tbl, tbl, id)
7484vtable_pop_gen(struct parser_params *p, int line, const char *name,
7485 struct vtable *tbl, int n)
7488 rb_parser_printf(p, "vtable_pop:%d: %s(%p), %d\n",
7489 line, name, (void *)tbl, n);
7492 rb_parser_fatal(p, "vtable_pop: unreachable (%d < %d)", tbl->pos, n);
7497#define vtable_pop(tbl, n) vtable_pop_gen(p, __LINE__, #tbl, tbl, n)
7500vtable_included(const struct vtable * tbl, ID id)
7504 if (!DVARS_TERMINAL_P(tbl)) {
7505 for (i = 0; i < tbl->pos; i++) {
7506 if (tbl->tbl[i] == id) {
7514static void parser_prepare(struct parser_params *p);
7517e_option_supplied(struct parser_params *p)
7519 return strcmp(p->ruby_sourcefile, "-e") == 0;
7523static NODE *parser_append_options(struct parser_params *p, NODE *node);
7526yycompile0(VALUE arg)
7530 struct parser_params *p = (struct parser_params *)arg;
7533 if (!compile_for_eval && !NIL_P(p->ruby_sourcefile_string) && !e_option_supplied(p)) {
7537 if (p->debug_lines) {
7538 p->ast->body.script_lines = p->debug_lines;
7542#define RUBY_DTRACE_PARSE_HOOK(name) \
7543 if (RUBY_DTRACE_PARSE_##name##_ENABLED()) { \
7544 RUBY_DTRACE_PARSE_##name(p->ruby_sourcefile, p->ruby_sourceline); \
7546 RUBY_DTRACE_PARSE_HOOK(BEGIN);
7548 RUBY_DTRACE_PARSE_HOOK(END);
7552 xfree(p->lex.strterm);
7554 p->lex.pcur = p->lex.pbeg = p->lex.pend = 0;
7555 if (n || p->error_p) {
7556 VALUE mesg = p->error_buffer;
7558 mesg = syntax_error_new();
7560 if (!p->error_tolerant) {
7561 rb_set_errinfo(mesg);
7565 tree = p->eval_tree;
7567 tree = NEW_NIL(&NULL_LOC);
7570 rb_parser_ary_t *tokens = p->tokens;
7572 NODE *body = parser_append_options(p, RNODE_SCOPE(tree)->nd_body);
7573 prelude = block_append(p, p->eval_tree_begin, body);
7574 RNODE_SCOPE(tree)->nd_body = prelude;
7575 p->ast->body.frozen_string_literal = p->frozen_string_literal;
7576 p->ast->body.coverage_enabled = cov;
7577 if (p->keep_tokens) {
7578 p->ast->node_buffer->tokens = tokens;
7582 p->ast->body.root = tree;
7583 p->ast->body.line_count = p->line_count;
7588yycompile(struct parser_params *p, VALUE fname, int line)
7592 p->ruby_sourcefile_string = Qnil;
7593 p->ruby_sourcefile = "(none)";
7596 p->ruby_sourcefile_string = rb_str_to_interned_str(fname);
7597 p->ruby_sourcefile = StringValueCStr(fname);
7599 p->ruby_sourceline = line - 1;
7603 p->ast = ast = rb_ast_new();
7604 compile_callback(yycompile0, (VALUE)p);
7616must_be_ascii_compatible(struct parser_params *p, rb_parser_string_t *s)
7618 rb_encoding *enc = rb_parser_str_get_encoding(s);
7619 if (!rb_enc_asciicompat(enc)) {
7620 rb_raise(rb_eArgError, "invalid source encoding");
7625static rb_parser_string_t *
7626lex_getline(struct parser_params *p)
7628 rb_parser_string_t *line = (*p->lex.gets)(p, p->lex.input, p->line_count);
7629 if (!line) return 0;
7631 string_buffer_append(p, line);
7632 must_be_ascii_compatible(p, line);
7638rb_parser_compile(rb_parser_t *p, rb_parser_lex_gets_func *gets, VALUE fname, rb_parser_input_data input, int line)
7641 p->lex.input = input;
7642 p->lex.pbeg = p->lex.pcur = p->lex.pend = 0;
7644 return yycompile(p, fname, line);
7648#define STR_FUNC_ESCAPE 0x01
7649#define STR_FUNC_EXPAND 0x02
7650#define STR_FUNC_REGEXP 0x04
7651#define STR_FUNC_QWORDS 0x08
7652#define STR_FUNC_SYMBOL 0x10
7653#define STR_FUNC_INDENT 0x20
7654#define STR_FUNC_LABEL 0x40
7655#define STR_FUNC_LIST 0x4000
7656#define STR_FUNC_TERM 0x8000
7659 str_label = STR_FUNC_LABEL,
7661 str_dquote = (STR_FUNC_EXPAND),
7662 str_xquote = (STR_FUNC_EXPAND),
7663 str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
7664 str_sword = (STR_FUNC_QWORDS|STR_FUNC_LIST),
7665 str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND|STR_FUNC_LIST),
7666 str_ssym = (STR_FUNC_SYMBOL),
7667 str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND)
7670static rb_parser_string_t *
7671parser_str_new(struct parser_params *p, const char *ptr, long len, rb_encoding *enc, int func, rb_encoding *enc0)
7673 rb_parser_string_t *pstr;
7675 pstr = rb_parser_encoding_string_new(p, ptr, len, enc);
7677 if (!(func & STR_FUNC_REGEXP)) {
7678 if (rb_parser_is_ascii_string(p, pstr)) {
7680 else if (rb_is_usascii_enc((void *)enc0) && enc != rb_utf8_encoding()) {
7681 /* everything is valid in ASCII-8BIT */
7682 enc = rb_ascii8bit_encoding();
7683 PARSER_ENCODING_CODERANGE_SET(pstr, enc, RB_PARSER_ENC_CODERANGE_VALID);
7691strterm_is_heredoc(rb_strterm_t *strterm)
7693 return strterm->heredoc;
7696static rb_strterm_t *
7697new_strterm(struct parser_params *p, int func, int term, int paren)
7699 rb_strterm_t *strterm = ZALLOC(rb_strterm_t);
7700 strterm->u.literal.func = func;
7701 strterm->u.literal.term = term;
7702 strterm->u.literal.paren = paren;
7706static rb_strterm_t *
7707new_heredoc(struct parser_params *p)
7709 rb_strterm_t *strterm = ZALLOC(rb_strterm_t);
7710 strterm->heredoc = true;
7714#define peek(p,c) peek_n(p, (c), 0)
7715#define peek_n(p,c,n) (!lex_eol_n_p(p, n) && (c) == (unsigned char)(p)->lex.pcur[n])
7716#define peekc(p) peekc_n(p, 0)
7717#define peekc_n(p,n) (lex_eol_n_p(p, n) ? -1 : (unsigned char)(p)->lex.pcur[n])
7719#define add_delayed_token(p, tok, end) parser_add_delayed_token(p, tok, end, __LINE__)
7721parser_add_delayed_token(struct parser_params *p, const char *tok, const char *end, int line)
7723 debug_token_line(p, "add_delayed_token", line);
7726 if (has_delayed_token(p)) {
7727 bool next_line = parser_string_char_at_end(p, p->delayed.token, 0) == '\n';
7728 int end_line = (next_line ? 1 : 0) + p->delayed.end_line;
7729 int end_col = (next_line ? 0 : p->delayed.end_col);
7730 if (end_line != p->ruby_sourceline || end_col != tok - p->lex.pbeg) {
7731 dispatch_delayed_token(p, tSTRING_CONTENT);
7734 if (!has_delayed_token(p)) {
7735 p->delayed.token = rb_parser_string_new(p, 0, 0);
7736 rb_parser_enc_associate(p, p->delayed.token, p->enc);
7737 p->delayed.beg_line = p->ruby_sourceline;
7738 p->delayed.beg_col = rb_long2int(tok - p->lex.pbeg);
7740 parser_str_cat(p->delayed.token, tok, end - tok);
7741 p->delayed.end_line = p->ruby_sourceline;
7742 p->delayed.end_col = rb_long2int(end - p->lex.pbeg);
7748set_lastline(struct parser_params *p, rb_parser_string_t *str)
7750 p->lex.pbeg = p->lex.pcur = PARSER_STRING_PTR(str);
7751 p->lex.pend = p->lex.pcur + PARSER_STRING_LEN(str);
7752 p->lex.lastline = str;
7756nextline(struct parser_params *p, int set_encoding)
7758 rb_parser_string_t *str = p->lex.nextline;
7759 p->lex.nextline = 0;
7764 if (!lex_eol_ptr_p(p, p->lex.pbeg) && *(p->lex.pend-1) != '\n') {
7768 if (!p->lex.input || !(str = lex_getline(p))) {
7775 if (p->debug_lines) {
7776 if (set_encoding) rb_parser_enc_associate(p, str, p->enc);
7777 rb_parser_string_t *copy = rb_parser_string_deep_copy(p, str);
7778 rb_parser_ary_push_script_line(p, p->debug_lines, copy);
7783 else if (str == AFTER_HEREDOC_WITHOUT_TERMINTOR) {
7784 /* after here-document without terminator */
7787 add_delayed_token(p, p->lex.ptok, p->lex.pend);
7788 if (p->heredoc_end > 0) {
7789 p->ruby_sourceline = p->heredoc_end;
7792 p->ruby_sourceline++;
7793 set_lastline(p, str);
7799parser_cr(struct parser_params *p, int c)
7801 if (peek(p, '\n')) {
7809nextc0(struct parser_params *p, int set_encoding)
7813 if (UNLIKELY(lex_eol_p(p) || p->eofp || p->lex.nextline > AFTER_HEREDOC_WITHOUT_TERMINTOR)) {
7814 if (nextline(p, set_encoding)) return -1;
7816 c = (unsigned char)*p->lex.pcur++;
7817 if (UNLIKELY(c == '\r')) {
7818 c = parser_cr(p, c);
7823#define nextc(p) nextc0(p, TRUE)
7826pushback(struct parser_params *p, int c)
7828 if (c == -1) return;
7831 if (p->lex.pcur > p->lex.pbeg && p->lex.pcur[0] == '\n' && p->lex.pcur[-1] == '\r') {
7836#define was_bol(p) ((p)->lex.pcur == (p)->lex.pbeg + 1)
7838#define tokfix(p) ((p)->tokenbuf[(p)->tokidx]='\0')
7839#define tok(p) (p)->tokenbuf
7840#define toklen(p) (p)->tokidx
7843looking_at_eol_p(struct parser_params *p)
7845 const char *ptr = p->lex.pcur;
7846 while (!lex_eol_ptr_p(p, ptr)) {
7847 int c = (unsigned char)*ptr++;
7848 int eol = (c == '\n' || c == '#');
7849 if (eol || !ISSPACE(c)) {
7857newtok(struct parser_params *p)
7862 p->tokenbuf = ALLOC_N(char, 60);
7864 if (p->toksiz > 4096) {
7866 REALLOC_N(p->tokenbuf, char, 60);
7872tokspace(struct parser_params *p, int n)
7876 if (p->tokidx >= p->toksiz) {
7877 do {p->toksiz *= 2;} while (p->toksiz < p->tokidx);
7878 REALLOC_N(p->tokenbuf, char, p->toksiz);
7880 return &p->tokenbuf[p->tokidx-n];
7884tokadd(struct parser_params *p, int c)
7886 p->tokenbuf[p->tokidx++] = (char)c;
7887 if (p->tokidx >= p->toksiz) {
7889 REALLOC_N(p->tokenbuf, char, p->toksiz);
7894tok_hex(struct parser_params *p, size_t *numlen)
7898 c = (int)ruby_scan_hex(p->lex.pcur, 2, numlen);
7900 flush_string_content(p, p->enc, rb_strlen_lit("\\x"));
7901 yyerror0("invalid hex escape");
7902 dispatch_scan_event(p, tSTRING_CONTENT);
7905 p->lex.pcur += *numlen;
7909#define tokcopy(p, n) memcpy(tokspace(p, n), (p)->lex.pcur - (n), (n))
7912escaped_control_code(int c)
7938#define WARN_SPACE_CHAR(c, prefix) \
7939 rb_warn1("invalid character syntax; use "prefix"\\%c", WARN_I(c))
7942tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
7943 int regexp_literal, const char *begin)
7945 const int wide = !begin;
7947 int codepoint = (int)ruby_scan_hex(p->lex.pcur, wide ? p->lex.pend - p->lex.pcur : 4, &numlen);
7949 p->lex.pcur += numlen;
7950 if (p->lex.strterm == NULL ||
7951 strterm_is_heredoc(p->lex.strterm) ||
7952 (p->lex.strterm->u.literal.func != str_regexp)) {
7953 if (!begin) begin = p->lex.pcur;
7954 if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) {
7955 flush_string_content(p, rb_utf8_encoding(), p->lex.pcur - begin);
7956 yyerror0("invalid Unicode escape");
7957 dispatch_scan_event(p, tSTRING_CONTENT);
7958 return wide && numlen > 0;
7960 if (codepoint > 0x10ffff) {
7961 flush_string_content(p, rb_utf8_encoding(), p->lex.pcur - begin);
7962 yyerror0("invalid Unicode codepoint (too large)");
7963 dispatch_scan_event(p, tSTRING_CONTENT);
7966 if ((codepoint & 0xfffff800) == 0xd800) {
7967 flush_string_content(p, rb_utf8_encoding(), p->lex.pcur - begin);
7968 yyerror0("invalid Unicode codepoint");
7969 dispatch_scan_event(p, tSTRING_CONTENT);
7973 if (regexp_literal) {
7974 tokcopy(p, (int)numlen);
7976 else if (codepoint >= 0x80) {
7977 rb_encoding *utf8 = rb_utf8_encoding();
7978 if (*encp && utf8 != *encp) {
7979 YYLTYPE loc = RUBY_INIT_YYLLOC();
7980 compile_error(p, "UTF-8 mixed within %s source", rb_enc_name(*encp));
7981 parser_show_error_line(p, &loc);
7985 tokaddmbc(p, codepoint, *encp);
7988 tokadd(p, codepoint);
7993static int tokadd_mbchar(struct parser_params *p, int c);
7996tokskip_mbchar(struct parser_params *p)
7998 int len = parser_precise_mbclen(p, p->lex.pcur-1);
8000 p->lex.pcur += len - 1;
8005/* return value is for ?\u3042 */
8007tokadd_utf8(struct parser_params *p, rb_encoding **encp,
8008 int term, int symbol_literal, int regexp_literal)
8011 * If `term` is not -1, then we allow multiple codepoints in \u{}
8012 * upto `term` byte, otherwise we're parsing a character literal.
8013 * And then add the codepoints to the current token.
8015 static const char multiple_codepoints[] = "Multiple codepoints at single character literal";
8017 const int open_brace = '{', close_brace = '}';
8019 if (regexp_literal) { tokadd(p, '\\'); tokadd(p, 'u'); }
8021 if (peek(p, open_brace)) { /* handle \u{...} form */
8022 if (regexp_literal && p->lex.strterm->u.literal.func == str_regexp) {
8024 * Skip parsing validation code and copy bytes as-is until term or
8025 * closing brace, in order to correctly handle extended regexps where
8026 * invalid unicode escapes are allowed in comments. The regexp parser
8027 * does its own validation and will catch any issues.
8029 tokadd(p, open_brace);
8030 while (!lex_eol_ptr_p(p, ++p->lex.pcur)) {
8032 if (c == close_brace) {
8037 else if (c == term) {
8040 if (c == '\\' && !lex_eol_n_p(p, 1)) {
8044 tokadd_mbchar(p, c);
8048 const char *second = NULL;
8049 int c, last = nextc(p);
8050 if (lex_eol_p(p)) goto unterminated;
8051 while (ISSPACE(c = peekc(p)) && !lex_eol_ptr_p(p, ++p->lex.pcur));
8052 while (c != close_brace) {
8053 if (c == term) goto unterminated;
8054 if (second == multiple_codepoints)
8055 second = p->lex.pcur;
8056 if (regexp_literal) tokadd(p, last);
8057 if (!tokadd_codepoint(p, encp, regexp_literal, NULL)) {
8060 while (ISSPACE(c = peekc(p))) {
8061 if (lex_eol_ptr_p(p, ++p->lex.pcur)) goto unterminated;
8064 if (term == -1 && !second)
8065 second = multiple_codepoints;
8068 if (c != close_brace) {
8070 flush_string_content(p, rb_utf8_encoding(), 0);
8071 yyerror0("unterminated Unicode escape");
8072 dispatch_scan_event(p, tSTRING_CONTENT);
8075 if (second && second != multiple_codepoints) {
8076 const char *pcur = p->lex.pcur;
8077 p->lex.pcur = second;
8078 dispatch_scan_event(p, tSTRING_CONTENT);
8081 yyerror0(multiple_codepoints);
8085 if (regexp_literal) tokadd(p, close_brace);
8089 else { /* handle \uxxxx form */
8090 if (!tokadd_codepoint(p, encp, regexp_literal, p->lex.pcur - rb_strlen_lit("\\u"))) {
8097#define ESCAPE_CONTROL 1
8098#define ESCAPE_META 2
8101read_escape(struct parser_params *p, int flags, const char *begin)
8106 switch (c = nextc(p)) {
8107 case '\\': /* Backslash */
8110 case 'n': /* newline */
8113 case 't': /* horizontal tab */
8116 case 'r': /* carriage-return */
8119 case 'f': /* form-feed */
8122 case 'v': /* vertical tab */
8125 case 'a': /* alarm(bell) */
8128 case 'e': /* escape */
8131 case '0': case '1': case '2': case '3': /* octal constant */
8132 case '4': case '5': case '6': case '7':
8134 c = (int)ruby_scan_oct(p->lex.pcur, 3, &numlen);
8135 p->lex.pcur += numlen;
8138 case 'x': /* hex constant */
8139 c = tok_hex(p, &numlen);
8140 if (numlen == 0) return 0;
8143 case 'b': /* backspace */
8146 case 's': /* space */
8150 if (flags & ESCAPE_META) goto eof;
8151 if ((c = nextc(p)) != '-') {
8154 if ((c = nextc(p)) == '\\') {
8160 return read_escape(p, flags|ESCAPE_META, begin) | 0x80;
8162 else if (c == -1) goto eof;
8163 else if (!ISASCII(c)) {
8168 int c2 = escaped_control_code(c);
8170 if (ISCNTRL(c) || !(flags & ESCAPE_CONTROL)) {
8171 WARN_SPACE_CHAR(c2, "\\M-");
8174 WARN_SPACE_CHAR(c2, "\\C-\\M-");
8177 else if (ISCNTRL(c)) goto eof;
8178 return ((c & 0xff) | 0x80);
8182 if ((c = nextc(p)) != '-') {
8186 if (flags & ESCAPE_CONTROL) goto eof;
8187 if ((c = nextc(p))== '\\') {
8193 c = read_escape(p, flags|ESCAPE_CONTROL, begin);
8197 else if (c == -1) goto eof;
8198 else if (!ISASCII(c)) {
8203 int c2 = escaped_control_code(c);
8206 if (flags & ESCAPE_META) {
8207 WARN_SPACE_CHAR(c2, "\\M-");
8210 WARN_SPACE_CHAR(c2, "");
8214 if (flags & ESCAPE_META) {
8215 WARN_SPACE_CHAR(c2, "\\M-\\C-");
8218 WARN_SPACE_CHAR(c2, "\\C-");
8222 else if (ISCNTRL(c)) goto eof;
8228 flush_string_content(p, p->enc, p->lex.pcur - begin);
8229 yyerror0("Invalid escape character syntax");
8230 dispatch_scan_event(p, tSTRING_CONTENT);
8239tokaddmbc(struct parser_params *p, int c, rb_encoding *enc)
8241 int len = rb_enc_codelen(c, enc);
8242 rb_enc_mbcput(c, tokspace(p, len), enc);
8246tokadd_escape(struct parser_params *p)
8250 const char *begin = p->lex.pcur;
8252 switch (c = nextc(p)) {
8254 return 0; /* just ignore */
8256 case '0': case '1': case '2': case '3': /* octal constant */
8257 case '4': case '5': case '6': case '7':
8259 ruby_scan_oct(--p->lex.pcur, 3, &numlen);
8260 if (numlen == 0) goto eof;
8261 p->lex.pcur += numlen;
8262 tokcopy(p, (int)numlen + 1);
8266 case 'x': /* hex constant */
8268 tok_hex(p, &numlen);
8269 if (numlen == 0) return -1;
8270 tokcopy(p, (int)numlen + 2);
8276 flush_string_content(p, p->enc, p->lex.pcur - begin);
8277 yyerror0("Invalid escape character syntax");
8289char_to_option(int c)
8295 val = RE_ONIG_OPTION_IGNORECASE;
8298 val = RE_ONIG_OPTION_EXTEND;
8301 val = RE_ONIG_OPTION_MULTILINE;
8310#define ARG_ENCODING_FIXED 16
8311#define ARG_ENCODING_NONE 32
8312#define ENC_ASCII8BIT 1
8314#define ENC_Windows_31J 3
8318char_to_option_kcode(int c, int *option, int *kcode)
8324 *kcode = ENC_ASCII8BIT;
8325 return (*option = ARG_ENCODING_NONE);
8327 *kcode = ENC_EUC_JP;
8330 *kcode = ENC_Windows_31J;
8337 return (*option = char_to_option(c));
8339 *option = ARG_ENCODING_FIXED;
8344regx_options(struct parser_params *p)
8352 while (c = nextc(p), ISALPHA(c)) {
8354 options |= RE_OPTION_ONCE;
8356 else if (char_to_option_kcode(c, &opt, &kc)) {
8358 if (kc != ENC_ASCII8BIT) kcode = c;
8372 YYLTYPE loc = RUBY_INIT_YYLLOC();
8374 compile_error(p, "unknown regexp option%s - %*s",
8375 toklen(p) > 1 ? "s" : "", toklen(p), tok(p));
8376 parser_show_error_line(p, &loc);
8378 return options | RE_OPTION_ENCODING(kcode);
8382tokadd_mbchar(struct parser_params *p, int c)
8384 int len = parser_precise_mbclen(p, p->lex.pcur-1);
8385 if (len < 0) return -1;
8387 p->lex.pcur += --len;
8388 if (len > 0) tokcopy(p, len);
8393simple_re_meta(int c)
8396 case '$': case '*': case '+': case '.':
8397 case '?': case '^': case '|':
8398 case ')': case ']': case '}': case '>':
8406parser_update_heredoc_indent(struct parser_params *p, int c)
8408 if (p->heredoc_line_indent == -1) {
8409 if (c == '\n') p->heredoc_line_indent = 0;
8413 p->heredoc_line_indent++;
8416 else if (c == '\t') {
8417 int w = (p->heredoc_line_indent / TAB_WIDTH) + 1;
8418 p->heredoc_line_indent = w * TAB_WIDTH;
8421 else if (c != '\n') {
8422 if (p->heredoc_indent > p->heredoc_line_indent) {
8423 p->heredoc_indent = p->heredoc_line_indent;
8425 p->heredoc_line_indent = -1;
8428 /* Whitespace only line has no indentation */
8429 p->heredoc_line_indent = 0;
8436parser_mixed_error(struct parser_params *p, rb_encoding *enc1, rb_encoding *enc2)
8438 YYLTYPE loc = RUBY_INIT_YYLLOC();
8439 const char *n1 = rb_enc_name(enc1), *n2 = rb_enc_name(enc2);
8440 compile_error(p, "%s mixed within %s source", n1, n2);
8441 parser_show_error_line(p, &loc);
8445parser_mixed_escape(struct parser_params *p, const char *beg, rb_encoding *enc1, rb_encoding *enc2)
8447 const char *pos = p->lex.pcur;
8449 parser_mixed_error(p, enc1, enc2);
8454nibble_char_upper(unsigned int c)
8457 return c + (c < 10 ? '0' : 'A' - 10);
8461tokadd_string(struct parser_params *p,
8462 int func, int term, int paren, long *nest,
8463 rb_encoding **encp, rb_encoding **enc)
8468 const int heredoc_end = (p->heredoc_end ? p->heredoc_end + 1 : 0);
8469 int top_of_line = FALSE;
8472#define mixed_error(enc1, enc2) \
8473 (void)(erred || (parser_mixed_error(p, enc1, enc2), erred = true))
8474#define mixed_escape(beg, enc1, enc2) \
8475 (void)(erred || (parser_mixed_escape(p, beg, enc1, enc2), erred = true))
8477 while ((c = nextc(p)) != -1) {
8478 if (p->heredoc_indent > 0) {
8479 parser_update_heredoc_indent(p, c);
8482 if (top_of_line && heredoc_end == p->ruby_sourceline) {
8488 if (paren && c == paren) {
8491 else if (c == term) {
8492 if (!nest || !*nest) {
8498 else if ((func & STR_FUNC_EXPAND) && c == '#' && !lex_eol_p(p)) {
8499 unsigned char c2 = *p->lex.pcur;
8500 if (c2 == '$' || c2 == '@' || c2 == '{') {
8505 else if (c == '\\') {
8509 if (func & STR_FUNC_QWORDS) break;
8510 if (func & STR_FUNC_EXPAND) {
8511 if (!(func & STR_FUNC_INDENT) || (p->heredoc_indent < 0))
8522 if (func & STR_FUNC_ESCAPE) tokadd(p, c);
8526 if ((func & STR_FUNC_EXPAND) == 0) {
8530 tokadd_utf8(p, enc, term,
8531 func & STR_FUNC_SYMBOL,
8532 func & STR_FUNC_REGEXP);
8536 if (c == -1) return -1;
8538 if ((func & STR_FUNC_EXPAND) == 0) tokadd(p, '\\');
8541 if (func & STR_FUNC_REGEXP) {
8547 c = read_escape(p, 0, p->lex.pcur - 1);
8549 char *t = tokspace(p, rb_strlen_lit("\\x00"));
8552 *t++ = nibble_char_upper(c >> 4);
8553 *t++ = nibble_char_upper(c);
8558 if (c == term && !simple_re_meta(c)) {
8563 if ((c = tokadd_escape(p)) < 0)
8565 if (*enc && *enc != *encp) {
8566 mixed_escape(p->lex.ptok+2, *enc, *encp);
8570 else if (func & STR_FUNC_EXPAND) {
8572 if (func & STR_FUNC_ESCAPE) tokadd(p, '\\');
8573 c = read_escape(p, 0, p->lex.pcur - 1);
8575 else if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
8576 /* ignore backslashed spaces in %w */
8578 else if (c != term && !(paren && c == paren)) {
8585 else if (!parser_isascii(p)) {
8590 else if (*enc != *encp) {
8591 mixed_error(*enc, *encp);
8594 if (tokadd_mbchar(p, c) == -1) return -1;
8597 else if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
8605 else if (*enc != *encp) {
8606 mixed_error(*enc, *encp);
8612 top_of_line = (c == '\n');
8616 if (*enc) *encp = *enc;
8620#define NEW_STRTERM(func, term, paren) new_strterm(p, func, term, paren)
8623flush_string_content(struct parser_params *p, rb_encoding *enc, size_t back)
8625 p->lex.pcur -= back;
8626 if (has_delayed_token(p)) {
8627 ptrdiff_t len = p->lex.pcur - p->lex.ptok;
8629 rb_parser_enc_str_buf_cat(p, p->delayed.token, p->lex.ptok, len, enc);
8630 p->delayed.end_line = p->ruby_sourceline;
8631 p->delayed.end_col = rb_long2int(p->lex.pcur - p->lex.pbeg);
8633 dispatch_delayed_token(p, tSTRING_CONTENT);
8634 p->lex.ptok = p->lex.pcur;
8636 dispatch_scan_event(p, tSTRING_CONTENT);
8637 p->lex.pcur += back;
8640/* this can be shared with ripper, since it's independent from struct
8643#define BIT(c, idx) (((c) / 32 - 1 == idx) ? (1U << ((c) % 32)) : 0)
8644#define SPECIAL_PUNCT(idx) ( \
8645 BIT('~', idx) | BIT('*', idx) | BIT('$', idx) | BIT('?', idx) | \
8646 BIT('!', idx) | BIT('@', idx) | BIT('/', idx) | BIT('\\', idx) | \
8647 BIT(';', idx) | BIT(',', idx) | BIT('.', idx) | BIT('=', idx) | \
8648 BIT(':', idx) | BIT('<', idx) | BIT('>', idx) | BIT('\"', idx) | \
8649 BIT('&', idx) | BIT('`', idx) | BIT('\'', idx) | BIT('+', idx) | \
8651const uint_least32_t ruby_global_name_punct_bits[] = {
8660static enum yytokentype
8661parser_peek_variable_name(struct parser_params *p)
8664 const char *ptr = p->lex.pcur;
8666 if (lex_eol_ptr_n_p(p, ptr, 1)) return 0;
8670 if ((c = *ptr) == '-') {
8671 if (lex_eol_ptr_p(p, ++ptr)) return 0;
8674 else if (is_global_name_punct(c) || ISDIGIT(c)) {
8675 return tSTRING_DVAR;
8679 if ((c = *ptr) == '@') {
8680 if (lex_eol_ptr_p(p, ++ptr)) return 0;
8686 p->command_start = TRUE;
8687 yylval.state = p->lex.state;
8688 return tSTRING_DBEG;
8692 if (!ISASCII(c) || c == '_' || ISALPHA(c))
8693 return tSTRING_DVAR;
8697#define IS_ARG() IS_lex_state(EXPR_ARG_ANY)
8698#define IS_END() IS_lex_state(EXPR_END_ANY)
8699#define IS_BEG() (IS_lex_state(EXPR_BEG_ANY) || IS_lex_state_all(EXPR_ARG|EXPR_LABELED))
8700#define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
8701#define IS_LABEL_POSSIBLE() (\
8702 (IS_lex_state(EXPR_LABEL|EXPR_ENDFN) && !cmd_state) || \
8704#define IS_LABEL_SUFFIX(n) (peek_n(p, ':',(n)) && !peek_n(p, ':', (n)+1))
8705#define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)
8707static inline enum yytokentype
8708parser_string_term(struct parser_params *p, int func)
8710 xfree(p->lex.strterm);
8712 if (func & STR_FUNC_REGEXP) {
8713 set_yylval_num(regx_options(p));
8714 dispatch_scan_event(p, tREGEXP_END);
8715 SET_LEX_STATE(EXPR_END);
8718 if ((func & STR_FUNC_LABEL) && IS_LABEL_SUFFIX(0)) {
8720 SET_LEX_STATE(EXPR_ARG|EXPR_LABELED);
8723 SET_LEX_STATE(EXPR_END);
8727static enum yytokentype
8728parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
8730 int func = quote->func;
8731 int term = quote->term;
8732 int paren = quote->paren;
8734 rb_encoding *enc = p->enc;
8735 rb_encoding *base_enc = 0;
8736 rb_parser_string_t *lit;
8738 if (func & STR_FUNC_TERM) {
8739 if (func & STR_FUNC_QWORDS) nextc(p); /* delayed term */
8740 SET_LEX_STATE(EXPR_END);
8741 xfree(p->lex.strterm);
8743 return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END;
8746 if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
8747 while (c != '\n' && ISSPACE(c = nextc(p)));
8750 if (func & STR_FUNC_LIST) {
8751 quote->func &= ~STR_FUNC_LIST;
8754 if (c == term && !quote->nest) {
8755 if (func & STR_FUNC_QWORDS) {
8756 quote->func |= STR_FUNC_TERM;
8757 pushback(p, c); /* dispatch the term at tSTRING_END */
8758 add_delayed_token(p, p->lex.ptok, p->lex.pcur);
8761 return parser_string_term(p, func);
8764 if (!ISSPACE(c)) pushback(p, c);
8765 add_delayed_token(p, p->lex.ptok, p->lex.pcur);
8769 if ((func & STR_FUNC_EXPAND) && c == '#') {
8770 enum yytokentype t = parser_peek_variable_name(p);
8776 if (tokadd_string(p, func, term, paren, "e->nest,
8777 &enc, &base_enc) == -1) {
8780# define unterminated_literal(mesg) yyerror0(mesg)
8782# define unterminated_literal(mesg) compile_error(p, mesg)
8784 literal_flush(p, p->lex.pcur);
8785 if (func & STR_FUNC_QWORDS) {
8786 /* no content to add, bailing out here */
8787 unterminated_literal("unterminated list meets end of file");
8788 xfree(p->lex.strterm);
8792 if (func & STR_FUNC_REGEXP) {
8793 unterminated_literal("unterminated regexp meets end of file");
8796 unterminated_literal("unterminated string meets end of file");
8798 quote->func |= STR_FUNC_TERM;
8803 lit = STR_NEW3(tok(p), toklen(p), enc, func);
8804 set_yylval_str(lit);
8805 flush_string_content(p, enc, 0);
8807 return tSTRING_CONTENT;
8810static enum yytokentype
8811heredoc_identifier(struct parser_params *p)
8814 * term_len is length of `<<"END"` except `END`,
8815 * in this case term_len is 4 (<, <, " and ").
8817 long len, offset = p->lex.pcur - p->lex.pbeg;
8818 int c = nextc(p), term, func = 0, quote = 0;
8819 enum yytokentype token = tSTRING_BEG;
8824 func = STR_FUNC_INDENT;
8827 else if (c == '~') {
8829 func = STR_FUNC_INDENT;
8835 func |= str_squote; goto quoted;
8837 func |= str_dquote; goto quoted;
8839 token = tXSTRING_BEG;
8840 func |= str_xquote; goto quoted;
8847 while ((c = nextc(p)) != term) {
8848 if (c == -1 || c == '\r' || c == '\n') {
8849 yyerror0("unterminated here document identifier");
8856 if (!parser_is_identchar(p)) {
8858 if (func & STR_FUNC_INDENT) {
8859 pushback(p, indent > 0 ? '~' : '-');
8865 int n = parser_precise_mbclen(p, p->lex.pcur-1);
8866 if (n < 0) return 0;
8868 } while ((c = nextc(p)) != -1 && parser_is_identchar(p));
8873 len = p->lex.pcur - (p->lex.pbeg + offset) - quote;
8874 if ((unsigned long)len >= HERETERM_LENGTH_MAX)
8875 yyerror0("too long here document identifier");
8876 dispatch_scan_event(p, tHEREDOC_BEG);
8879 p->lex.strterm = new_heredoc(p);
8880 rb_strterm_heredoc_t *here = &p->lex.strterm->u.heredoc;
8881 here->offset = offset;
8882 here->sourceline = p->ruby_sourceline;
8883 here->length = (unsigned)len;
8884 here->quote = quote;
8886 here->lastline = p->lex.lastline;
8889 p->heredoc_indent = indent;
8890 p->heredoc_line_indent = 0;
8895heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
8897 rb_parser_string_t *line;
8898 rb_strterm_t *term = p->lex.strterm;
8901 line = here->lastline;
8902 p->lex.lastline = line;
8903 p->lex.pbeg = PARSER_STRING_PTR(line);
8904 p->lex.pend = p->lex.pbeg + PARSER_STRING_LEN(line);
8905 p->lex.pcur = p->lex.pbeg + here->offset + here->length + here->quote;
8906 p->lex.ptok = p->lex.pbeg + here->offset - here->quote;
8907 p->heredoc_end = p->ruby_sourceline;
8908 p->ruby_sourceline = (int)here->sourceline;
8909 if (p->eofp) p->lex.nextline = AFTER_HEREDOC_WITHOUT_TERMINTOR;
8915dedent_string_column(const char *str, long len, int width)
8919 for (i = 0; i < len && col < width; i++) {
8920 if (str[i] == ' ') {
8923 else if (str[i] == '\t') {
8924 int n = TAB_WIDTH * (col / TAB_WIDTH + 1);
8925 if (n > width) break;
8937dedent_string(struct parser_params *p, rb_parser_string_t *string, int width)
8943 len = PARSER_STRING_LEN(string);
8944 str = PARSER_STRING_PTR(string);
8946 i = dedent_string_column(str, len, width);
8949 rb_parser_str_modify(string);
8950 str = PARSER_STRING_PTR(string);
8951 if (PARSER_STRING_LEN(string) != len)
8952 rb_fatal("literal string changed: %s", PARSER_STRING_PTR(string));
8953 MEMMOVE(str, str + i, char, len - i);
8954 rb_parser_str_set_len(p, string, len - i);
8959heredoc_dedent(struct parser_params *p, NODE *root)
8961 NODE *node, *str_node, *prev_node;
8962 int indent = p->heredoc_indent;
8963 rb_parser_string_t *prev_lit = 0;
8965 if (indent <= 0) return root;
8966 if (!root) return root;
8968 prev_node = node = str_node = root;
8969 if (nd_type_p(root, NODE_LIST)) str_node = RNODE_LIST(root)->nd_head;
8972 rb_parser_string_t *lit = RNODE_STR(str_node)->string;
8973 if (nd_fl_newline(str_node)) {
8974 dedent_string(p, lit, indent);
8979 else if (!literal_concat0(p, prev_lit, lit)) {
8983 NODE *end = RNODE_LIST(node)->as.nd_end;
8984 node = RNODE_LIST(prev_node)->nd_next = RNODE_LIST(node)->nd_next;
8986 if (nd_type_p(prev_node, NODE_DSTR))
8987 nd_set_type(prev_node, NODE_STR);
8990 RNODE_LIST(node)->as.nd_end = end;
8995 while ((nd_type_p(node, NODE_LIST) || nd_type_p(node, NODE_DSTR)) && (node = RNODE_LIST(prev_node = node)->nd_next) != 0) {
8997 if (!nd_type_p(node, NODE_LIST)) break;
8998 if ((str_node = RNODE_LIST(node)->nd_head) != 0) {
8999 enum node_type type = nd_type(str_node);
9000 if (type == NODE_STR || type == NODE_DSTR) break;
9010whole_match_p(struct parser_params *p, const char *eos, long len, int indent)
9012 const char *beg = p->lex.pbeg;
9013 const char *ptr = p->lex.pend;
9015 if (ptr - beg < len) return FALSE;
9016 if (ptr > beg && ptr[-1] == '\n') {
9017 if (--ptr > beg && ptr[-1] == '\r') --ptr;
9018 if (ptr - beg < len) return FALSE;
9020 if (strncmp(eos, ptr -= len, len)) return FALSE;
9022 while (beg < ptr && ISSPACE(*beg)) beg++;
9028word_match_p(struct parser_params *p, const char *word, long len)
9030 if (strncmp(p->lex.pcur, word, len)) return 0;
9031 if (lex_eol_n_p(p, len)) return 1;
9032 int c = (unsigned char)p->lex.pcur[len];
9033 if (ISSPACE(c)) return 1;
9035 case '\0': case '\004': case '\032': return 1;
9040#define NUM_SUFFIX_R (1<<0)
9041#define NUM_SUFFIX_I (1<<1)
9042#define NUM_SUFFIX_ALL 3
9045number_literal_suffix(struct parser_params *p, int mask)
9048 const char *lastp = p->lex.pcur;
9050 while ((c = nextc(p)) != -1) {
9051 if ((mask & NUM_SUFFIX_I) && c == 'i') {
9052 result |= (mask & NUM_SUFFIX_I);
9053 mask &= ~NUM_SUFFIX_I;
9054 /* r after i, rational of complex is disallowed */
9055 mask &= ~NUM_SUFFIX_R;
9058 if ((mask & NUM_SUFFIX_R) && c == 'r') {
9059 result |= (mask & NUM_SUFFIX_R);
9060 mask &= ~NUM_SUFFIX_R;
9063 if (!ISASCII(c) || ISALPHA(c) || c == '_') {
9064 p->lex.pcur = lastp;
9065 literal_flush(p, p->lex.pcur);
9074static enum yytokentype
9075set_number_literal(struct parser_params *p, enum yytokentype type, int suffix, int base, int seen_point)
9077 enum rb_numeric_type numeric_type = integer_literal;
9079 if (type == tFLOAT) {
9080 numeric_type = float_literal;
9083 if (suffix & NUM_SUFFIX_R) {
9085 numeric_type = rational_literal;
9087 if (suffix & NUM_SUFFIX_I) {
9093 set_yylval_node(NEW_INTEGER(strdup(tok(p)), base, &_cur_loc));
9096 set_yylval_node(NEW_FLOAT(strdup(tok(p)), &_cur_loc));
9099 set_yylval_node(NEW_RATIONAL(strdup(tok(p)), base, seen_point, &_cur_loc));
9102 set_yylval_node(NEW_IMAGINARY(strdup(tok(p)), base, seen_point, numeric_type, &_cur_loc));
9103 (void)numeric_type; /* for ripper */
9106 rb_bug("unexpected token: %d", type);
9108 SET_LEX_STATE(EXPR_END);
9112#define dispatch_heredoc_end(p) parser_dispatch_heredoc_end(p, __LINE__)
9114parser_dispatch_heredoc_end(struct parser_params *p, int line)
9116 if (has_delayed_token(p))
9117 dispatch_delayed_token(p, tSTRING_CONTENT);
9120 VALUE str = STR_NEW(p->lex.ptok, p->lex.pend - p->lex.ptok);
9121 ripper_dispatch1(p, ripper_token2eventid(tHEREDOC_END), str);
9123 if (p->keep_tokens) {
9124 rb_parser_string_t *str = rb_parser_encoding_string_new(p, p->lex.ptok, p->lex.pend - p->lex.ptok, p->enc);
9125 RUBY_SET_YYLLOC_OF_HEREDOC_END(*p->yylloc);
9126 parser_append_tokens(p, str, tHEREDOC_END, line);
9130 RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(*p->yylloc);
9135static enum yytokentype
9136here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
9138 int c, func, indent = 0;
9139 const char *eos, *ptr, *ptr_end;
9141 rb_parser_string_t *str = 0;
9142 rb_encoding *enc = p->enc;
9143 rb_encoding *base_enc = 0;
9149 eos = PARSER_STRING_PTR(here->lastline) + here->offset;
9151 indent = (func = here->func) & STR_FUNC_INDENT;
9153 if ((c = nextc(p)) == -1) {
9156 if (!has_delayed_token(p)) {
9157 dispatch_scan_event(p, tSTRING_CONTENT);
9160 if ((len = p->lex.pcur - p->lex.ptok) > 0) {
9161 if (!(func & STR_FUNC_REGEXP)) {
9162 int cr = ENC_CODERANGE_UNKNOWN;
9163 rb_str_coderange_scan_restartable(p->lex.ptok, p->lex.pcur, enc, &cr);
9164 if (cr != ENC_CODERANGE_7BIT &&
9165 rb_is_usascii_enc(p->enc) &&
9166 enc != rb_utf8_encoding()) {
9167 enc = rb_ascii8bit_encoding();
9170 rb_parser_enc_str_buf_cat(p, p->delayed.token, p->lex.ptok, len, enc);
9172 dispatch_delayed_token(p, tSTRING_CONTENT);
9176 heredoc_restore(p, &p->lex.strterm->u.heredoc);
9177 compile_error(p, "can't find string \"%.*s\" anywhere before EOF",
9180 SET_LEX_STATE(EXPR_END);
9185 /* not beginning of line, cannot be the terminator */
9187 else if (p->heredoc_line_indent == -1) {
9188 /* `heredoc_line_indent == -1` means
9189 * - "after an interpolation in the same line", or
9190 * - "in a continuing line"
9192 p->heredoc_line_indent = 0;
9194 else if (whole_match_p(p, eos, len, indent)) {
9195 dispatch_heredoc_end(p);
9197 heredoc_restore(p, &p->lex.strterm->u.heredoc);
9199 SET_LEX_STATE(EXPR_END);
9203 if (!(func & STR_FUNC_EXPAND)) {
9205 ptr = PARSER_STRING_PTR(p->lex.lastline);
9206 ptr_end = p->lex.pend;
9207 if (ptr_end > ptr) {
9208 switch (ptr_end[-1]) {
9210 if (--ptr_end == ptr || ptr_end[-1] != '\r') {
9219 if (p->heredoc_indent > 0) {
9221 while (ptr + i < ptr_end && parser_update_heredoc_indent(p, ptr[i]))
9223 p->heredoc_line_indent = 0;
9227 parser_str_cat(str, ptr, ptr_end - ptr);
9229 str = rb_parser_encoding_string_new(p, ptr, ptr_end - ptr, enc);
9230 if (!lex_eol_ptr_p(p, ptr_end)) parser_str_cat_cstr(str, "\n");
9232 if (p->heredoc_indent > 0) {
9235 if (nextc(p) == -1) {
9237 rb_parser_string_free(p, str);
9242 } while (!whole_match_p(p, eos, len, indent));
9245 /* int mb = ENC_CODERANGE_7BIT, *mbp = &mb;*/
9248 enum yytokentype t = parser_peek_variable_name(p);
9249 if (p->heredoc_line_indent != -1) {
9250 if (p->heredoc_indent > p->heredoc_line_indent) {
9251 p->heredoc_indent = p->heredoc_line_indent;
9253 p->heredoc_line_indent = -1;
9262 if ((c = tokadd_string(p, func, '\n', 0, NULL, &enc, &base_enc)) == -1) {
9263 if (p->eofp) goto error;
9267 if (c == '\\') p->heredoc_line_indent = -1;
9269 str = STR_NEW3(tok(p), toklen(p), enc, func);
9271 set_yylval_str(str);
9273 if (bol) nd_set_fl_newline(yylval.node);
9275 flush_string_content(p, enc, 0);
9276 return tSTRING_CONTENT;
9278 tokadd(p, nextc(p));
9279 if (p->heredoc_indent > 0) {
9283 /* if (mbp && mb == ENC_CODERANGE_UNKNOWN) mbp = 0;*/
9284 if ((c = nextc(p)) == -1) goto error;
9285 } while (!whole_match_p(p, eos, len, indent));
9286 str = STR_NEW3(tok(p), toklen(p), enc, func);
9288 dispatch_heredoc_end(p);
9289 heredoc_restore(p, &p->lex.strterm->u.heredoc);
9291 p->lex.strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0);
9293 /* Preserve s_value for set_yylval_str */
9294 s_value = p->s_value;
9296 set_yylval_str(str);
9298 set_parser_s_value(s_value);
9302 if (bol) nd_set_fl_newline(yylval.node);
9304 return tSTRING_CONTENT;
9310arg_ambiguous(struct parser_params *p, char c)
9314 rb_warning1("ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after '%c' operator", WARN_I(c));
9317 rb_warning1("ambiguous first argument; put parentheses or a space even after '%c' operator", WARN_I(c));
9320 dispatch1(arg_ambiguous, rb_usascii_str_new(&c, 1));
9325/* returns true value if formal argument error;
9326 * Qtrue, or error message if ripper */
9328formal_argument_error(struct parser_params *p, ID id)
9330 switch (id_type(id)) {
9334# define ERR(mesg) (yyerror0(mesg), Qtrue)
9336# define ERR(mesg) WARN_S(mesg)
9339 return ERR("formal argument cannot be a constant");
9341 return ERR("formal argument cannot be an instance variable");
9343 return ERR("formal argument cannot be a global variable");
9345 return ERR("formal argument cannot be a class variable");
9347 return ERR("formal argument must be local variable");
9350 shadowing_lvar(p, id);
9356lvar_defined(struct parser_params *p, ID id)
9358 return (dyna_in_block(p) && dvar_defined(p, id)) || local_id(p, id);
9361/* emacsen -*- hack */
9363parser_encode_length(struct parser_params *p, const char *name, long len)
9367 if (len > 5 && name[nlen = len - 5] == '-') {
9368 if (rb_memcicmp(name + nlen + 1, "unix", 4) == 0)
9371 if (len > 4 && name[nlen = len - 4] == '-') {
9372 if (rb_memcicmp(name + nlen + 1, "dos", 3) == 0)
9374 if (rb_memcicmp(name + nlen + 1, "mac", 3) == 0 &&
9375 !(len == 8 && rb_memcicmp(name, "utf8-mac", len) == 0))
9376 /* exclude UTF8-MAC because the encoding named "UTF8" doesn't exist in Ruby */
9383parser_set_encode(struct parser_params *p, const char *name)
9389 const char *wrong = 0;
9391 case 'e': case 'E': wrong = "external"; break;
9392 case 'i': case 'I': wrong = "internal"; break;
9393 case 'f': case 'F': wrong = "filesystem"; break;
9394 case 'l': case 'L': wrong = "locale"; break;
9396 if (wrong && STRCASECMP(name, wrong) == 0) goto unknown;
9397 idx = rb_enc_find_index(name);
9400 excargs[1] = rb_sprintf("unknown encoding name: %s", name);
9402 excargs[0] = rb_eArgError;
9403 excargs[2] = rb_make_backtrace();
9404 rb_ary_unshift(excargs[2], rb_sprintf("%"PRIsVALUE":%d", p->ruby_sourcefile_string, p->ruby_sourceline));
9405 VALUE exc = rb_make_exception(3, excargs);
9406 ruby_show_error_line(p, exc, &(YYLTYPE)RUBY_INIT_YYLLOC(), p->ruby_sourceline, p->lex.lastline);
9408 rb_ast_free(p->ast);
9413 enc = rb_enc_from_index(idx);
9414 if (!rb_enc_asciicompat(enc)) {
9415 excargs[1] = rb_sprintf("%s is not ASCII compatible", rb_enc_name(enc));
9420 if (p->debug_lines) {
9422 for (i = 0; i < p->debug_lines->len; i++) {
9423 rb_parser_enc_associate(p, p->debug_lines->data[i], enc);
9430comment_at_top(struct parser_params *p)
9432 if (p->token_seen) return false;
9433 return (p->line_count == (p->has_shebang ? 2 : 1));
9436typedef long (*rb_magic_comment_length_t)(struct parser_params *p, const char *name, long len);
9437typedef void (*rb_magic_comment_setter_t)(struct parser_params *p, const char *name, const char *val);
9439static int parser_invalid_pragma_value(struct parser_params *p, const char *name, const char *val);
9442magic_comment_encoding(struct parser_params *p, const char *name, const char *val)
9444 if (!comment_at_top(p)) {
9447 parser_set_encode(p, val);
9451parser_get_bool(struct parser_params *p, const char *name, const char *val)
9455 if (STRCASECMP(val, "true") == 0) {
9460 if (STRCASECMP(val, "false") == 0) {
9465 return parser_invalid_pragma_value(p, name, val);
9469parser_invalid_pragma_value(struct parser_params *p, const char *name, const char *val)
9471 rb_warning2("invalid value for %s: %s", WARN_S(name), WARN_S(val));
9476parser_set_token_info(struct parser_params *p, const char *name, const char *val)
9478 int b = parser_get_bool(p, name, val);
9479 if (b >= 0) p->token_info_enabled = b;
9483parser_set_frozen_string_literal(struct parser_params *p, const char *name, const char *val)
9487 if (p->token_seen) {
9488 rb_warning1("'%s' is ignored after any tokens", WARN_S(name));
9492 b = parser_get_bool(p, name, val);
9495 p->frozen_string_literal = b;
9499parser_set_shareable_constant_value(struct parser_params *p, const char *name, const char *val)
9501 for (const char *s = p->lex.pbeg, *e = p->lex.pcur; s < e; ++s) {
9502 if (*s == ' ' || *s == '\t') continue;
9503 if (*s == '#') break;
9504 rb_warning1("'%s' is ignored unless in comment-only line", WARN_S(name));
9510 if (STRCASECMP(val, "none") == 0) {
9511 p->ctxt.shareable_constant_value = rb_parser_shareable_none;
9516 if (STRCASECMP(val, "literal") == 0) {
9517 p->ctxt.shareable_constant_value = rb_parser_shareable_literal;
9522 if (STRCASECMP(val, "experimental_copy") == 0) {
9523 p->ctxt.shareable_constant_value = rb_parser_shareable_copy;
9526 if (STRCASECMP(val, "experimental_everything") == 0) {
9527 p->ctxt.shareable_constant_value = rb_parser_shareable_everything;
9532 parser_invalid_pragma_value(p, name, val);
9537parser_set_past_scope(struct parser_params *p, const char *name, const char *val)
9539 int b = parser_get_bool(p, name, val);
9540 if (b >= 0) p->past_scope_enabled = b;
9544struct magic_comment {
9546 rb_magic_comment_setter_t func;
9547 rb_magic_comment_length_t length;
9550static const struct magic_comment magic_comments[] = {
9551 {"coding", magic_comment_encoding, parser_encode_length},
9552 {"encoding", magic_comment_encoding, parser_encode_length},
9553 {"frozen_string_literal", parser_set_frozen_string_literal},
9554 {"shareable_constant_value", parser_set_shareable_constant_value},
9555 {"warn_indent", parser_set_token_info},
9557 {"warn_past_scope", parser_set_past_scope},
9562magic_comment_marker(const char *str, long len)
9569 if (str[i-1] == '*' && str[i-2] == '-') {
9575 if (i + 1 >= len) return 0;
9576 if (str[i+1] != '-') {
9579 else if (str[i-1] != '-') {
9595parser_magic_comment(struct parser_params *p, const char *str, long len)
9598 VALUE name = 0, val = 0;
9599 const char *beg, *end, *vbeg, *vend;
9600#define str_copy(_s, _p, _n) ((_s) \
9601 ? (void)(rb_str_resize((_s), (_n)), \
9602 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
9603 : (void)((_s) = STR_NEW((_p), (_n))))
9605 if (len <= 7) return FALSE;
9606 if (!!(beg = magic_comment_marker(str, len))) {
9607 if (!(end = magic_comment_marker(beg, str + len - beg)))
9611 len = end - beg - 3;
9614 /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
9616 const struct magic_comment *mc = magic_comments;
9621 for (; len > 0 && *str; str++, --len) {
9623 case '\'': case '"': case ':': case ';':
9626 if (!ISSPACE(*str)) break;
9628 for (beg = str; len > 0; str++, --len) {
9630 case '\'': case '"': case ':': case ';':
9633 if (ISSPACE(*str)) break;
9638 for (end = str; len > 0 && ISSPACE(*str); str++, --len);
9641 if (!indicator) return FALSE;
9645 do str++; while (--len > 0 && ISSPACE(*str));
9647 const char *tok_beg = str;
9649 for (vbeg = ++str; --len > 0 && *str != '"'; str++) {
9662 for (vbeg = str; len > 0 && *str != '"' && *str != ';' && !ISSPACE(*str); --len, str++);
9665 const char *tok_end = str;
9667 while (len > 0 && (*str == ';' || ISSPACE(*str))) --len, str++;
9670 while (len > 0 && (ISSPACE(*str))) --len, str++;
9671 if (len) return FALSE;
9675 str_copy(name, beg, n);
9676 s = RSTRING_PTR(name);
9677 for (i = 0; i < n; ++i) {
9678 if (s[i] == '-') s[i] = '_';
9681 if (STRNCASECMP(mc->name, s, n) == 0 && !mc->name[n]) {
9684 n = (*mc->length)(p, vbeg, n);
9686 str_copy(val, vbeg, n);
9687 p->lex.ptok = tok_beg;
9688 p->lex.pcur = tok_end;
9689 (*mc->func)(p, mc->name, RSTRING_PTR(val));
9692 } while (++mc < magic_comments + numberof(magic_comments));
9694 str_copy(val, vbeg, vend - vbeg);
9695 dispatch2(magic_comment, name, val);
9703set_file_encoding(struct parser_params *p, const char *str, const char *send)
9706 const char *beg = str;
9710 if (send - str <= 6) return;
9712 case 'C': case 'c': str += 6; continue;
9713 case 'O': case 'o': str += 5; continue;
9714 case 'D': case 'd': str += 4; continue;
9715 case 'I': case 'i': str += 3; continue;
9716 case 'N': case 'n': str += 2; continue;
9717 case 'G': case 'g': str += 1; continue;
9724 if (ISSPACE(*str)) break;
9727 if (STRNCASECMP(str-6, "coding", 6) == 0) break;
9732 if (++str >= send) return;
9733 } while (ISSPACE(*str));
9735 if (*str != '=' && *str != ':') return;
9740 while ((*str == '-' || *str == '_' || ISALNUM(*str)) && ++str < send);
9741 s = rb_str_new(beg, parser_encode_length(p, beg, str - beg));
9744 parser_set_encode(p, RSTRING_PTR(s));
9745 rb_str_resize(s, 0);
9749parser_prepare(struct parser_params *p)
9751 int c = nextc0(p, FALSE);
9752 p->token_info_enabled = !compile_for_eval && RTEST(ruby_verbose);
9755 if (peek(p, '!')) p->has_shebang = 1;
9757 case 0xef: /* UTF-8 BOM marker */
9758 if (!lex_eol_n_p(p, 2) &&
9759 (unsigned char)p->lex.pcur[0] == 0xbb &&
9760 (unsigned char)p->lex.pcur[1] == 0xbf) {
9761 p->enc = rb_utf8_encoding();
9764 if (p->debug_lines) {
9765 rb_parser_string_set_encoding(p->lex.lastline, p->enc);
9768 p->lex.pbeg = p->lex.pcur;
9773 case -1: /* end of script. */
9777 p->enc = rb_parser_str_get_encoding(p->lex.lastline);
9781#define ambiguous_operator(tok, op, syn) ( \
9782 rb_warning0("'"op"' after local variable or literal is interpreted as binary operator"), \
9783 rb_warning0("even though it seems like "syn""))
9785#define ambiguous_operator(tok, op, syn) \
9786 dispatch2(operator_ambiguous, TOKEN2VAL(tok), rb_str_new_cstr(syn))
9788#define warn_balanced(tok, op, syn) ((void) \
9789 (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN) && \
9790 space_seen && !ISSPACE(c) && \
9791 (ambiguous_operator(tok, op, syn), 0)), \
9792 (enum yytokentype)(tok))
9794static enum yytokentype
9795no_digits(struct parser_params *p)
9797 yyerror0("numeric literal without digits");
9798 if (peek(p, '_')) nextc(p);
9799 /* dummy 0, for tUMINUS_NUM at numeric */
9800 return set_number_literal(p, tINTEGER, 0, 10, 0);
9803static enum yytokentype
9804parse_numeric(struct parser_params *p, int c)
9806 int is_float, seen_point, seen_e, nondigit;
9809 is_float = seen_point = seen_e = nondigit = 0;
9810 SET_LEX_STATE(EXPR_END);
9812 if (c == '-' || c == '+') {
9817 int start = toklen(p);
9819 if (c == 'x' || c == 'X') {
9822 if (c != -1 && ISXDIGIT(c)) {
9825 if (nondigit) break;
9829 if (!ISXDIGIT(c)) break;
9832 } while ((c = nextc(p)) != -1);
9836 if (toklen(p) == start) {
9837 return no_digits(p);
9839 else if (nondigit) goto trailing_uc;
9840 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
9841 return set_number_literal(p, tINTEGER, suffix, 16, 0);
9843 if (c == 'b' || c == 'B') {
9846 if (c == '0' || c == '1') {
9849 if (nondigit) break;
9853 if (c != '0' && c != '1') break;
9856 } while ((c = nextc(p)) != -1);
9860 if (toklen(p) == start) {
9861 return no_digits(p);
9863 else if (nondigit) goto trailing_uc;
9864 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
9865 return set_number_literal(p, tINTEGER, suffix, 2, 0);
9867 if (c == 'd' || c == 'D') {
9870 if (c != -1 && ISDIGIT(c)) {
9873 if (nondigit) break;
9877 if (!ISDIGIT(c)) break;
9880 } while ((c = nextc(p)) != -1);
9884 if (toklen(p) == start) {
9885 return no_digits(p);
9887 else if (nondigit) goto trailing_uc;
9888 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
9889 return set_number_literal(p, tINTEGER, suffix, 10, 0);
9895 if (c == 'o' || c == 'O') {
9896 /* prefixed octal */
9898 if (c == -1 || c == '_' || !ISDIGIT(c)) {
9900 return no_digits(p);
9903 if (c >= '0' && c <= '7') {
9908 if (nondigit) break;
9912 if (c < '0' || c > '9') break;
9913 if (c > '7') goto invalid_octal;
9916 } while ((c = nextc(p)) != -1);
9917 if (toklen(p) > start) {
9920 if (nondigit) goto trailing_uc;
9921 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
9922 return set_number_literal(p, tINTEGER, suffix, 8, 0);
9929 if (c > '7' && c <= '9') {
9931 yyerror0("Invalid octal digit");
9933 else if (c == '.' || c == 'e' || c == 'E') {
9939 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
9940 return set_number_literal(p, tINTEGER, suffix, 10, 0);
9946 case '0': case '1': case '2': case '3': case '4':
9947 case '5': case '6': case '7': case '8': case '9':
9953 if (nondigit) goto trailing_uc;
9954 if (seen_point || seen_e) {
9959 if (c0 == -1 || !ISDIGIT(c0)) {
9965 seen_point = toklen(p);
9984 if (c != '-' && c != '+' && !ISDIGIT(c)) {
9990 tokadd(p, nondigit);
9994 nondigit = (c == '-' || c == '+') ? c : 0;
9997 case '_': /* `_' in number just ignored */
9998 if (nondigit) goto decode_num;
10012 literal_flush(p, p->lex.pcur - 1);
10013 YYLTYPE loc = RUBY_INIT_YYLLOC();
10014 compile_error(p, "trailing '%c' in number", nondigit);
10015 parser_show_error_line(p, &loc);
10019 enum yytokentype type = tFLOAT;
10021 suffix = number_literal_suffix(p, seen_e ? NUM_SUFFIX_I : NUM_SUFFIX_ALL);
10022 if (suffix & NUM_SUFFIX_R) {
10027 if (errno == ERANGE) {
10028 rb_warning1("Float %s out of range", WARN_S(tok(p)));
10032 return set_number_literal(p, type, suffix, 0, seen_point);
10034 suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
10035 return set_number_literal(p, tINTEGER, suffix, 10, 0);
10038static enum yytokentype
10039parse_qmark(struct parser_params *p, int space_seen)
10043 rb_parser_string_t *lit;
10046 SET_LEX_STATE(EXPR_VALUE);
10051 compile_error(p, "incomplete character syntax");
10054 if (rb_enc_isspace(c, p->enc)) {
10056 int c2 = escaped_control_code(c);
10058 WARN_SPACE_CHAR(c2, "?");
10063 SET_LEX_STATE(EXPR_VALUE);
10068 if (!parser_isascii(p)) {
10069 if (tokadd_mbchar(p, c) == -1) return 0;
10071 else if ((rb_enc_isalnum(c, p->enc) || c == '_') &&
10072 !lex_eol_p(p) && is_identchar(p, p->lex.pcur, p->lex.pend, p->enc)) {
10074 const char *start = p->lex.pcur - 1, *ptr = start;
10076 int n = parser_precise_mbclen(p, ptr);
10077 if (n < 0) return -1;
10079 } while (!lex_eol_ptr_p(p, ptr) && is_identchar(p, ptr, p->lex.pend, p->enc));
10080 rb_warn2("'?' just followed by '%.*s' is interpreted as" \
10081 " a conditional operator, put a space after '?'",
10082 WARN_I((int)(ptr - start)), WARN_S_L(start, (ptr - start)));
10086 else if (c == '\\') {
10087 if (peek(p, 'u')) {
10089 enc = rb_utf8_encoding();
10090 tokadd_utf8(p, &enc, -1, 0, 0);
10092 else if (!ISASCII(c = peekc(p)) && c != -1) {
10094 if (tokadd_mbchar(p, c) == -1) return 0;
10097 c = read_escape(p, 0, p->lex.pcur - rb_strlen_lit("?\\"));
10105 lit = STR_NEW3(tok(p), toklen(p), enc, 0);
10106 set_yylval_str(lit);
10107 SET_LEX_STATE(EXPR_END);
10111static enum yytokentype
10112parse_percent(struct parser_params *p, const int space_seen, const enum lex_state_e last_state)
10115 const char *ptok = p->lex.pcur;
10123 if (c == -1) goto unterminated;
10126 if (!ISASCII(c)) goto unknown;
10131 if (rb_enc_isalnum(term, p->enc) || !parser_isascii(p)) {
10134 c = parser_precise_mbclen(p, p->lex.pcur);
10135 if (c < 0) return 0;
10137 yyerror0("unknown type of %string");
10143 compile_error(p, "unterminated quoted string meets end of file");
10147 if (term == '(') term = ')';
10148 else if (term == '[') term = ']';
10149 else if (term == '{') term = '}';
10150 else if (term == '<') term = '>';
10153 p->lex.ptok = ptok-1;
10156 p->lex.strterm = NEW_STRTERM(str_dquote, term, paren);
10157 return tSTRING_BEG;
10160 p->lex.strterm = NEW_STRTERM(str_squote, term, paren);
10161 return tSTRING_BEG;
10164 p->lex.strterm = NEW_STRTERM(str_dword, term, paren);
10168 p->lex.strterm = NEW_STRTERM(str_sword, term, paren);
10169 return tQWORDS_BEG;
10172 p->lex.strterm = NEW_STRTERM(str_dword, term, paren);
10173 return tSYMBOLS_BEG;
10176 p->lex.strterm = NEW_STRTERM(str_sword, term, paren);
10177 return tQSYMBOLS_BEG;
10180 p->lex.strterm = NEW_STRTERM(str_xquote, term, paren);
10181 return tXSTRING_BEG;
10184 p->lex.strterm = NEW_STRTERM(str_regexp, term, paren);
10185 return tREGEXP_BEG;
10188 p->lex.strterm = NEW_STRTERM(str_ssym, term, paren);
10189 SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);
10193 yyerror0("unknown type of %string");
10197 if ((c = nextc(p)) == '=') {
10198 set_yylval_id('%');
10199 SET_LEX_STATE(EXPR_BEG);
10202 if (IS_SPCARG(c) || (IS_lex_state(EXPR_FITEM) && c == 's')) {
10205 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
10207 return warn_balanced('%', "%%", "string literal");
10211tokadd_ident(struct parser_params *p, int c)
10214 if (tokadd_mbchar(p, c) == -1) return -1;
10216 } while (parser_is_identchar(p));
10222tokenize_ident(struct parser_params *p)
10224 ID ident = TOK_INTERN();
10226 set_yylval_name(ident);
10232parse_numvar(struct parser_params *p)
10236 unsigned long n = ruby_scan_digits(tok(p)+1, toklen(p)-1, 10, &len, &overflow);
10237 const unsigned long nth_ref_max =
10238 ((FIXNUM_MAX < INT_MAX) ? FIXNUM_MAX : INT_MAX) >> 1;
10239 /* NTH_REF is left-shifted to be ORed with back-ref flag and
10240 * turned into a Fixnum, in compile.c */
10242 if (overflow || n > nth_ref_max) {
10243 /* compile_error()? */
10244 rb_warn1("'%s' is too big for a number variable, always nil", WARN_S(tok(p)));
10245 return 0; /* $0 is $PROGRAM_NAME, not NTH_REF */
10252static enum yytokentype
10253parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
10255 const char *ptr = p->lex.pcur;
10258 SET_LEX_STATE(EXPR_END);
10259 p->lex.ptok = ptr - 1; /* from '$' */
10263 case '_': /* $_: last read line string */
10265 if (parser_is_identchar(p)) {
10273 case '~': /* $~: match-data */
10274 case '*': /* $*: argv */
10275 case '$': /* $$: pid */
10276 case '?': /* $?: last status */
10277 case '!': /* $!: error string */
10278 case '@': /* $@: error position */
10279 case '/': /* $/: input record separator */
10280 case '\\': /* $\: output record separator */
10281 case ';': /* $;: field separator */
10282 case ',': /* $,: output field separator */
10283 case '.': /* $.: last read line number */
10284 case '=': /* $=: ignorecase */
10285 case ':': /* $:: load path */
10286 case '<': /* $<: default input handle */
10287 case '>': /* $>: default output handle */
10288 case '\"': /* $": already loaded files */
10297 if (parser_is_identchar(p)) {
10298 if (tokadd_mbchar(p, c) == -1) return 0;
10309 case '&': /* $&: last match */
10310 case '`': /* $`: string before last match */
10311 case '\'': /* $': string after last match */
10312 case '+': /* $+: string matches last paren. */
10313 if (IS_lex_state_for(last_state, EXPR_FNAME)) {
10318 set_yylval_node(NEW_BACK_REF(c, &_cur_loc));
10321 case '1': case '2': case '3':
10322 case '4': case '5': case '6':
10323 case '7': case '8': case '9':
10328 } while (c != -1 && ISDIGIT(c));
10330 if (IS_lex_state_for(last_state, EXPR_FNAME)) goto gvar;
10332 c = parse_numvar(p);
10333 set_yylval_node(NEW_NTH_REF(c, &_cur_loc));
10337 if (!parser_is_identchar(p)) {
10338 YYLTYPE loc = RUBY_INIT_YYLLOC();
10339 if (c == -1 || ISSPACE(c)) {
10340 compile_error(p, "'$' without identifiers is not allowed as a global variable name");
10344 compile_error(p, "'$%c' is not allowed as a global variable name", c);
10346 parser_show_error_line(p, &loc);
10347 set_yylval_noname();
10355 if (tokadd_ident(p, c)) return 0;
10356 SET_LEX_STATE(EXPR_END);
10357 if (VALID_SYMNAME_P(tok(p), toklen(p), p->enc, ID_GLOBAL)) {
10361 compile_error(p, "'%.*s' is not allowed as a global variable name", toklen(p), tok(p));
10362 set_yylval_noname();
10368parser_numbered_param(struct parser_params *p, int n)
10370 if (n < 0) return false;
10372 if (DVARS_TERMINAL_P(p->lvtbl->args) || DVARS_TERMINAL_P(p->lvtbl->args->prev)) {
10375 if (p->max_numparam == ORDINAL_PARAM) {
10376 compile_error(p, "ordinary parameter is defined");
10379 struct vtable *args = p->lvtbl->args;
10380 if (p->max_numparam < n) {
10381 p->max_numparam = n;
10383 while (n > args->pos) {
10384 vtable_add(args, NUMPARAM_IDX_TO_ID(args->pos+1));
10389static enum yytokentype
10390parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
10392 const char *ptr = p->lex.pcur;
10393 enum yytokentype result = tIVAR;
10394 register int c = nextc(p);
10397 p->lex.ptok = ptr - 1; /* from '@' */
10405 SET_LEX_STATE(IS_lex_state_for(last_state, EXPR_FNAME) ? EXPR_ENDFN : EXPR_END);
10406 if (c == -1 || !parser_is_identchar(p)) {
10408 RUBY_SET_YYLLOC(loc);
10409 if (result == tIVAR) {
10410 compile_error(p, "'@' without identifiers is not allowed as an instance variable name");
10413 compile_error(p, "'@@' without identifiers is not allowed as a class variable name");
10415 parser_show_error_line(p, &loc);
10416 set_yylval_noname();
10417 SET_LEX_STATE(EXPR_END);
10420 else if (ISDIGIT(c)) {
10422 RUBY_SET_YYLLOC(loc);
10423 if (result == tIVAR) {
10424 compile_error(p, "'@%c' is not allowed as an instance variable name", c);
10427 compile_error(p, "'@@%c' is not allowed as a class variable name", c);
10429 parser_show_error_line(p, &loc);
10430 set_yylval_noname();
10431 SET_LEX_STATE(EXPR_END);
10435 if (tokadd_ident(p, c)) return 0;
10440static enum yytokentype
10441parse_ident(struct parser_params *p, int c, int cmd_state)
10443 enum yytokentype result;
10444 bool is_ascii = true;
10445 const enum lex_state_e last_state = p->lex.state;
10447 int enforce_keyword_end = 0;
10450 if (!ISASCII(c)) is_ascii = false;
10451 if (tokadd_mbchar(p, c) == -1) return 0;
10453 } while (parser_is_identchar(p));
10454 if ((c == '!' || c == '?') && !peek(p, '=')) {
10458 else if (c == '=' && IS_lex_state(EXPR_FNAME) &&
10459 (!peek(p, '~') && !peek(p, '>') && (!peek(p, '=') || (peek_n(p, '>', 1))))) {
10460 result = tIDENTIFIER;
10464 result = tCONSTANT; /* assume provisionally */
10469 if (IS_LABEL_POSSIBLE()) {
10470 if (IS_LABEL_SUFFIX(0)) {
10471 SET_LEX_STATE(EXPR_ARG|EXPR_LABELED);
10479 if (peek_end_expect_token_locations(p)) {
10480 const rb_code_position_t *end_pos;
10481 int lineno, column;
10482 int beg_pos = (int)(p->lex.ptok - p->lex.pbeg);
10484 end_pos = peek_end_expect_token_locations(p)->pos;
10485 lineno = end_pos->lineno;
10486 column = end_pos->column;
10489 rb_parser_printf(p, "enforce_keyword_end check. current: (%d, %d), peek: (%d, %d)\n",
10490 p->ruby_sourceline, beg_pos, lineno, column);
10493 if ((p->ruby_sourceline > lineno) && (beg_pos <= column)) {
10494 const struct kwtable *kw;
10496 if ((IS_lex_state(EXPR_DOT)) && (kw = rb_reserved_word(tok(p), toklen(p))) && (kw && kw->id[0] == keyword_end)) {
10497 if (p->debug) rb_parser_printf(p, "enforce_keyword_end is enabled\n");
10498 enforce_keyword_end = 1;
10504 if (is_ascii && (!IS_lex_state(EXPR_DOT) || enforce_keyword_end)) {
10505 const struct kwtable *kw;
10507 /* See if it is a reserved word. */
10508 kw = rb_reserved_word(tok(p), toklen(p));
10510 enum lex_state_e state = p->lex.state;
10511 if (IS_lex_state_for(state, EXPR_FNAME)) {
10512 SET_LEX_STATE(EXPR_ENDFN);
10513 set_yylval_name(rb_intern2(tok(p), toklen(p)));
10516 SET_LEX_STATE(kw->state);
10517 if (IS_lex_state(EXPR_BEG)) {
10518 p->command_start = TRUE;
10520 if (kw->id[0] == keyword_do) {
10521 if (lambda_beginning_p()) {
10522 p->lex.lpar_beg = -1; /* make lambda_beginning_p() == FALSE in the body of "-> do ... end" */
10523 return keyword_do_LAMBDA;
10525 if (COND_P()) return keyword_do_cond;
10526 if (CMDARG_P() && !IS_lex_state_for(state, EXPR_CMDARG))
10527 return keyword_do_block;
10530 if (IS_lex_state_for(state, (EXPR_BEG | EXPR_LABELED | EXPR_CLASS)))
10533 if (kw->id[0] != kw->id[1])
10534 SET_LEX_STATE(EXPR_BEG | EXPR_LABEL);
10540 if (IS_lex_state(EXPR_BEG_ANY | EXPR_ARG_ANY | EXPR_DOT)) {
10542 SET_LEX_STATE(EXPR_CMDARG);
10545 SET_LEX_STATE(EXPR_ARG);
10548 else if (p->lex.state == EXPR_FNAME) {
10549 SET_LEX_STATE(EXPR_ENDFN);
10552 SET_LEX_STATE(EXPR_END);
10555 ident = tokenize_ident(p);
10556 if (result == tCONSTANT && is_local_id(ident)) result = tIDENTIFIER;
10557 if (!IS_lex_state_for(last_state, EXPR_DOT|EXPR_FNAME) &&
10558 (result == tIDENTIFIER) && /* not EXPR_FNAME, not attrasgn */
10559 (lvar_defined(p, ident) || NUMPARAM_ID_P(ident))) {
10560 SET_LEX_STATE(EXPR_END|EXPR_LABEL);
10566warn_cr(struct parser_params *p)
10570 /* carried over with p->lex.nextline for nextc() */
10571 rb_warn0("encountered \\r in middle of line, treated as a mere space");
10575static enum yytokentype
10576parser_yylex(struct parser_params *p)
10579 int space_seen = 0;
10582 enum lex_state_e last_state;
10583 int fallthru = FALSE;
10584 int token_seen = p->token_seen;
10586 if (p->lex.strterm) {
10587 if (strterm_is_heredoc(p->lex.strterm)) {
10589 return here_document(p, &p->lex.strterm->u.heredoc);
10593 return parse_string(p, &p->lex.strterm->u.literal);
10596 cmd_state = p->command_start;
10597 p->command_start = FALSE;
10598 p->token_seen = TRUE;
10603 last_state = p->lex.state;
10604 switch (c = nextc(p)) {
10605 case '\0': /* NUL */
10606 case '\004': /* ^D */
10607 case '\032': /* ^Z */
10608 case -1: /* end of script. */
10611 if (p->end_expect_token_locations) {
10612 pop_end_expect_token_locations(p);
10613 RUBY_SET_YYLLOC_OF_DUMMY_END(*p->yylloc);
10617 /* Set location for end-of-input because dispatch_scan_event is not called. */
10618 RUBY_SET_YYLLOC(*p->yylloc);
10619 return END_OF_INPUT;
10625 case ' ': case '\t': case '\f':
10626 case '\13': /* '\v' */
10628 while ((c = nextc(p))) {
10633 case ' ': case '\t': case '\f':
10634 case '\13': /* '\v' */
10642 dispatch_scan_event(p, tSP);
10648 case '#': /* it's a comment */
10649 p->token_seen = token_seen;
10650 const char *const pcur = p->lex.pcur, *const ptok = p->lex.ptok;
10651 /* no magic_comment in shebang line */
10652 if (!parser_magic_comment(p, p->lex.pcur, p->lex.pend - p->lex.pcur)) {
10653 if (comment_at_top(p)) {
10654 set_file_encoding(p, p->lex.pcur, p->lex.pend);
10657 p->lex.pcur = pcur, p->lex.ptok = ptok;
10659 dispatch_scan_event(p, tCOMMENT);
10663 p->token_seen = token_seen;
10664 rb_parser_string_t *prevline = p->lex.lastline;
10665 c = (IS_lex_state(EXPR_BEG|EXPR_CLASS|EXPR_FNAME|EXPR_DOT) &&
10666 !IS_lex_state(EXPR_LABELED));
10667 if (c || IS_lex_state_all(EXPR_ARG|EXPR_LABELED)) {
10669 dispatch_scan_event(p, tIGNORED_NL);
10672 if (!c && p->ctxt.in_kwarg) {
10673 goto normal_newline;
10678 switch (c = nextc(p)) {
10679 case ' ': case '\t': case '\f': case '\r':
10680 case '\13': /* '\v' */
10686 dispatch_scan_event(p, tSP);
10692 dispatch_delayed_token(p, tIGNORED_NL);
10693 if (peek(p, '.') == (c == '&')) {
10695 dispatch_scan_event(p, tSP);
10700 p->ruby_sourceline--;
10701 p->lex.nextline = p->lex.lastline;
10702 set_lastline(p, prevline);
10703 case -1: /* EOF no decrement*/
10704 if (c == -1 && space_seen) {
10705 dispatch_scan_event(p, tSP);
10710 RUBY_SET_YYLLOC(*p->yylloc);
10712 goto normal_newline;
10716 p->command_start = TRUE;
10717 SET_LEX_STATE(EXPR_BEG);
10721 if ((c = nextc(p)) == '*') {
10722 if ((c = nextc(p)) == '=') {
10723 set_yylval_id(idPow);
10724 SET_LEX_STATE(EXPR_BEG);
10728 if (IS_SPCARG(c)) {
10729 rb_warning0("'**' interpreted as argument prefix");
10732 else if (IS_BEG()) {
10736 c = warn_balanced((enum ruby_method_ids)tPOW, "**", "argument prefix");
10741 set_yylval_id('*');
10742 SET_LEX_STATE(EXPR_BEG);
10746 if (IS_SPCARG(c)) {
10747 rb_warning0("'*' interpreted as argument prefix");
10750 else if (IS_BEG()) {
10754 c = warn_balanced('*', "*", "argument prefix");
10757 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
10762 if (IS_AFTER_OPERATOR()) {
10763 SET_LEX_STATE(EXPR_ARG);
10769 SET_LEX_STATE(EXPR_BEG);
10782 /* skip embedded rd document */
10783 if (word_match_p(p, "begin", 5)) {
10784 int first_p = TRUE;
10787 dispatch_scan_event(p, tEMBDOC_BEG);
10791 dispatch_scan_event(p, tEMBDOC);
10796 compile_error(p, "embedded document meets end of file");
10797 return END_OF_INPUT;
10799 if (c == '=' && word_match_p(p, "end", 3)) {
10805 dispatch_scan_event(p, tEMBDOC_END);
10810 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
10811 if ((c = nextc(p)) == '=') {
10812 if ((c = nextc(p)) == '=') {
10821 else if (c == '>') {
10830 !IS_lex_state(EXPR_DOT | EXPR_CLASS) &&
10832 (!IS_ARG() || IS_lex_state(EXPR_LABELED) || space_seen)) {
10833 enum yytokentype token = heredoc_identifier(p);
10834 if (token) return token < 0 ? 0 : token;
10836 if (IS_AFTER_OPERATOR()) {
10837 SET_LEX_STATE(EXPR_ARG);
10840 if (IS_lex_state(EXPR_CLASS))
10841 p->command_start = TRUE;
10842 SET_LEX_STATE(EXPR_BEG);
10845 if ((c = nextc(p)) == '>') {
10852 if ((c = nextc(p)) == '=') {
10853 set_yylval_id(idLTLT);
10854 SET_LEX_STATE(EXPR_BEG);
10858 return warn_balanced((enum ruby_method_ids)tLSHFT, "<<", "here document");
10864 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
10865 if ((c = nextc(p)) == '=') {
10869 if ((c = nextc(p)) == '=') {
10870 set_yylval_id(idGTGT);
10871 SET_LEX_STATE(EXPR_BEG);
10881 label = (IS_LABEL_POSSIBLE() ? str_label : 0);
10882 p->lex.strterm = NEW_STRTERM(str_dquote | label, '"', 0);
10883 p->lex.ptok = p->lex.pcur-1;
10884 return tSTRING_BEG;
10887 if (IS_lex_state(EXPR_FNAME)) {
10888 SET_LEX_STATE(EXPR_ENDFN);
10891 if (IS_lex_state(EXPR_DOT)) {
10893 SET_LEX_STATE(EXPR_CMDARG);
10895 SET_LEX_STATE(EXPR_ARG);
10898 p->lex.strterm = NEW_STRTERM(str_xquote, '`', 0);
10899 return tXSTRING_BEG;
10902 label = (IS_LABEL_POSSIBLE() ? str_label : 0);
10903 p->lex.strterm = NEW_STRTERM(str_squote | label, '\'', 0);
10904 p->lex.ptok = p->lex.pcur-1;
10905 return tSTRING_BEG;
10908 return parse_qmark(p, space_seen);
10911 if ((c = nextc(p)) == '&') {
10912 SET_LEX_STATE(EXPR_BEG);
10913 if ((c = nextc(p)) == '=') {
10914 set_yylval_id(idANDOP);
10915 SET_LEX_STATE(EXPR_BEG);
10921 else if (c == '=') {
10922 set_yylval_id('&');
10923 SET_LEX_STATE(EXPR_BEG);
10926 else if (c == '.') {
10927 set_yylval_id(idANDDOT);
10928 SET_LEX_STATE(EXPR_DOT);
10932 if (IS_SPCARG(c)) {
10934 (c = peekc_n(p, 1)) == -1 ||
10935 !(c == '\'' || c == '"' ||
10936 is_identchar(p, (p->lex.pcur+1), p->lex.pend, p->enc))) {
10937 rb_warning0("'&' interpreted as argument prefix");
10941 else if (IS_BEG()) {
10945 c = warn_balanced('&', "&", "argument prefix");
10947 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
10951 if ((c = nextc(p)) == '|') {
10952 SET_LEX_STATE(EXPR_BEG);
10953 if ((c = nextc(p)) == '=') {
10954 set_yylval_id(idOROP);
10955 SET_LEX_STATE(EXPR_BEG);
10959 if (IS_lex_state_for(last_state, EXPR_BEG)) {
10967 set_yylval_id('|');
10968 SET_LEX_STATE(EXPR_BEG);
10971 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG|EXPR_LABEL);
10977 if (IS_AFTER_OPERATOR()) {
10978 SET_LEX_STATE(EXPR_ARG);
10986 set_yylval_id('+');
10987 SET_LEX_STATE(EXPR_BEG);
10990 if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous(p, '+'))) {
10991 SET_LEX_STATE(EXPR_BEG);
10993 if (c != -1 && ISDIGIT(c)) {
10994 return parse_numeric(p, '+');
10998 SET_LEX_STATE(EXPR_BEG);
11000 return warn_balanced('+', "+", "unary operator");
11004 if (IS_AFTER_OPERATOR()) {
11005 SET_LEX_STATE(EXPR_ARG);
11013 set_yylval_id('-');
11014 SET_LEX_STATE(EXPR_BEG);
11018 SET_LEX_STATE(EXPR_ENDFN);
11019 yylval.num = p->lex.lpar_beg;
11020 p->lex.lpar_beg = p->lex.paren_nest;
11023 if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous(p, '-'))) {
11024 SET_LEX_STATE(EXPR_BEG);
11026 if (c != -1 && ISDIGIT(c)) {
11027 return tUMINUS_NUM;
11031 SET_LEX_STATE(EXPR_BEG);
11033 return warn_balanced('-', "-", "unary operator");
11036 int is_beg = IS_BEG();
11037 SET_LEX_STATE(EXPR_BEG);
11038 if ((c = nextc(p)) == '.') {
11039 if ((c = nextc(p)) == '.') {
11040 if (p->ctxt.in_argdef || IS_LABEL_POSSIBLE()) {
11041 SET_LEX_STATE(EXPR_ENDARG);
11044 if (p->lex.paren_nest == 0 && looking_at_eol_p(p)) {
11045 rb_warn0("... at EOL, should be parenthesized?");
11047 return is_beg ? tBDOT3 : tDOT3;
11050 return is_beg ? tBDOT2 : tDOT2;
11053 if (c != -1 && ISDIGIT(c)) {
11054 char prev = p->lex.pcur-1 > p->lex.pbeg ? *(p->lex.pcur-2) : 0;
11055 parse_numeric(p, '.');
11056 if (ISDIGIT(prev)) {
11057 yyerror0("unexpected fraction part after numeric literal");
11060 yyerror0("no .<digit> floating literal anymore; put 0 before dot");
11062 SET_LEX_STATE(EXPR_END);
11063 p->lex.ptok = p->lex.pcur;
11066 set_yylval_id('.');
11067 SET_LEX_STATE(EXPR_DOT);
11071 case '0': case '1': case '2': case '3': case '4':
11072 case '5': case '6': case '7': case '8': case '9':
11073 return parse_numeric(p, c);
11078 SET_LEX_STATE(EXPR_ENDFN);
11079 p->lex.paren_nest--;
11085 SET_LEX_STATE(EXPR_END);
11086 p->lex.paren_nest--;
11090 /* tSTRING_DEND does COND_POP and CMDARG_POP in the yacc's rule */
11091 if (!p->lex.brace_nest--) return tSTRING_DEND;
11094 SET_LEX_STATE(EXPR_END);
11095 p->lex.paren_nest--;
11101 if (IS_BEG() || IS_lex_state(EXPR_CLASS) || IS_SPCARG(-1)) {
11102 SET_LEX_STATE(EXPR_BEG);
11105 set_yylval_id(idCOLON2);
11106 SET_LEX_STATE(EXPR_DOT);
11109 if (IS_END() || ISSPACE(c) || c == '#') {
11111 c = warn_balanced(':', ":", "symbol literal");
11112 SET_LEX_STATE(EXPR_BEG);
11117 p->lex.strterm = NEW_STRTERM(str_ssym, c, 0);
11120 p->lex.strterm = NEW_STRTERM(str_dsym, c, 0);
11126 SET_LEX_STATE(EXPR_FNAME);
11131 p->lex.strterm = NEW_STRTERM(str_regexp, '/', 0);
11132 return tREGEXP_BEG;
11134 if ((c = nextc(p)) == '=') {
11135 set_yylval_id('/');
11136 SET_LEX_STATE(EXPR_BEG);
11140 if (IS_SPCARG(c)) {
11141 arg_ambiguous(p, '/');
11142 p->lex.strterm = NEW_STRTERM(str_regexp, '/', 0);
11143 return tREGEXP_BEG;
11145 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
11146 return warn_balanced('/', "/", "regexp literal");
11149 if ((c = nextc(p)) == '=') {
11150 set_yylval_id('^');
11151 SET_LEX_STATE(EXPR_BEG);
11154 SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
11159 SET_LEX_STATE(EXPR_BEG);
11160 p->command_start = TRUE;
11164 SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
11168 if (IS_AFTER_OPERATOR()) {
11169 if ((c = nextc(p)) != '@') {
11172 SET_LEX_STATE(EXPR_ARG);
11175 SET_LEX_STATE(EXPR_BEG);
11183 else if (!space_seen) {
11184 /* foo( ... ) => method call, no ambiguity */
11186 else if (IS_ARG() || IS_lex_state_all(EXPR_END|EXPR_LABEL)) {
11189 else if (IS_lex_state(EXPR_ENDFN) && !lambda_beginning_p()) {
11190 rb_warning0("parentheses after method name is interpreted as "
11191 "an argument list, not a decomposed argument");
11193 p->lex.paren_nest++;
11196 SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
11200 p->lex.paren_nest++;
11201 if (IS_AFTER_OPERATOR()) {
11202 if ((c = nextc(p)) == ']') {
11203 p->lex.paren_nest--;
11204 SET_LEX_STATE(EXPR_ARG);
11205 if ((c = nextc(p)) == '=') {
11212 SET_LEX_STATE(EXPR_ARG|EXPR_LABEL);
11215 else if (IS_BEG()) {
11218 else if (IS_ARG() && (space_seen || IS_lex_state(EXPR_LABELED))) {
11221 SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
11227 ++p->lex.brace_nest;
11228 if (lambda_beginning_p())
11230 else if (IS_lex_state(EXPR_LABELED))
11231 c = tLBRACE; /* hash */
11232 else if (IS_lex_state(EXPR_ARG_ANY | EXPR_END | EXPR_ENDFN))
11233 c = '{'; /* block (primary) */
11234 else if (IS_lex_state(EXPR_ENDARG))
11235 c = tLBRACE_ARG; /* block (expr) */
11237 c = tLBRACE; /* hash */
11238 if (c != tLBRACE) {
11239 p->command_start = TRUE;
11240 SET_LEX_STATE(EXPR_BEG);
11243 SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
11245 ++p->lex.paren_nest; /* after lambda_beginning_p() */
11254 dispatch_scan_event(p, tSP);
11255 goto retry; /* skip \\n */
11257 if (c == ' ') return tSP;
11258 if (ISSPACE(c)) return c;
11263 return parse_percent(p, space_seen, last_state);
11266 return parse_gvar(p, last_state);
11269 return parse_atmark(p, last_state);
11272 if (was_bol(p) && whole_match_p(p, "__END__", 7, 0)) {
11273 p->ruby__end__seen = 1;
11277 dispatch_scan_event(p, k__END__);
11279 return END_OF_INPUT;
11285 if (!parser_is_identchar(p)) {
11286 compile_error(p, "Invalid char '\\x%02X' in expression", c);
11295 return parse_ident(p, c, cmd_state);
11298static enum yytokentype
11299yylex(YYSTYPE *lval, YYLTYPE *yylloc, struct parser_params *p)
11301 enum yytokentype t;
11305 p->yylloc = yylloc;
11307 t = parser_yylex(p);
11309 if (has_delayed_token(p))
11310 dispatch_delayed_token(p, t);
11311 else if (t != END_OF_INPUT)
11312 dispatch_scan_event(p, t);
11317#define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
11320node_new_internal(struct parser_params *p, enum node_type type, size_t size, size_t alignment)
11322 NODE *n = rb_ast_newnode(p->ast, type, size, alignment);
11324 rb_node_init(n, type);
11329nd_set_loc(NODE *nd, const YYLTYPE *loc)
11332 nd_set_line(nd, loc->beg_pos.lineno);
11337node_newnode(struct parser_params *p, enum node_type type, size_t size, size_t alignment, const rb_code_location_t *loc)
11339 NODE *n = node_new_internal(p, type, size, alignment);
11341 nd_set_loc(n, loc);
11342 nd_set_node_id(n, parser_get_node_id(p));
11346#define NODE_NEWNODE(node_type, type, loc) (type *)(node_newnode(p, node_type, sizeof(type), RUBY_ALIGNOF(type), loc))
11348static rb_node_scope_t *
11349rb_node_scope_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc)
11351 rb_ast_id_table_t *nd_tbl;
11352 nd_tbl = local_tbl(p);
11353 rb_node_scope_t *n = NODE_NEWNODE(NODE_SCOPE, rb_node_scope_t, loc);
11354 n->nd_tbl = nd_tbl;
11355 n->nd_body = nd_body;
11356 n->nd_args = nd_args;
11361static rb_node_scope_t *
11362rb_node_scope_new2(struct parser_params *p, rb_ast_id_table_t *nd_tbl, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc)
11364 rb_node_scope_t *n = NODE_NEWNODE(NODE_SCOPE, rb_node_scope_t, loc);
11365 n->nd_tbl = nd_tbl;
11366 n->nd_body = nd_body;
11367 n->nd_args = nd_args;
11372static rb_node_defn_t *
11373rb_node_defn_new(struct parser_params *p, ID nd_mid, NODE *nd_defn, const YYLTYPE *loc)
11375 rb_node_defn_t *n = NODE_NEWNODE(NODE_DEFN, rb_node_defn_t, loc);
11376 n->nd_mid = nd_mid;
11377 n->nd_defn = nd_defn;
11382static rb_node_defs_t *
11383rb_node_defs_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_defn, const YYLTYPE *loc)
11385 rb_node_defs_t *n = NODE_NEWNODE(NODE_DEFS, rb_node_defs_t, loc);
11386 n->nd_recv = nd_recv;
11387 n->nd_mid = nd_mid;
11388 n->nd_defn = nd_defn;
11393static rb_node_block_t *
11394rb_node_block_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
11396 rb_node_block_t *n = NODE_NEWNODE(NODE_BLOCK, rb_node_block_t, loc);
11397 n->nd_head = nd_head;
11398 n->nd_end = (NODE *)n;
11404static rb_node_for_t *
11405rb_node_for_new(struct parser_params *p, NODE *nd_iter, NODE *nd_body, const YYLTYPE *loc)
11407 rb_node_for_t *n = NODE_NEWNODE(NODE_FOR, rb_node_for_t, loc);
11408 n->nd_body = nd_body;
11409 n->nd_iter = nd_iter;
11414static rb_node_for_masgn_t *
11415rb_node_for_masgn_new(struct parser_params *p, NODE *nd_var, const YYLTYPE *loc)
11417 rb_node_for_masgn_t *n = NODE_NEWNODE(NODE_FOR_MASGN, rb_node_for_masgn_t, loc);
11418 n->nd_var = nd_var;
11423static rb_node_retry_t *
11424rb_node_retry_new(struct parser_params *p, const YYLTYPE *loc)
11426 rb_node_retry_t *n = NODE_NEWNODE(NODE_RETRY, rb_node_retry_t, loc);
11431static rb_node_begin_t *
11432rb_node_begin_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
11434 rb_node_begin_t *n = NODE_NEWNODE(NODE_BEGIN, rb_node_begin_t, loc);
11435 n->nd_body = nd_body;
11440static rb_node_rescue_t *
11441rb_node_rescue_new(struct parser_params *p, NODE *nd_head, NODE *nd_resq, NODE *nd_else, const YYLTYPE *loc)
11443 rb_node_rescue_t *n = NODE_NEWNODE(NODE_RESCUE, rb_node_rescue_t, loc);
11444 n->nd_head = nd_head;
11445 n->nd_resq = nd_resq;
11446 n->nd_else = nd_else;
11451static rb_node_resbody_t *
11452rb_node_resbody_new(struct parser_params *p, NODE *nd_args, NODE *nd_exc_var, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc)
11454 rb_node_resbody_t *n = NODE_NEWNODE(NODE_RESBODY, rb_node_resbody_t, loc);
11455 n->nd_args = nd_args;
11456 n->nd_exc_var = nd_exc_var;
11457 n->nd_body = nd_body;
11458 n->nd_next = nd_next;
11463static rb_node_ensure_t *
11464rb_node_ensure_new(struct parser_params *p, NODE *nd_head, NODE *nd_ensr, const YYLTYPE *loc)
11466 rb_node_ensure_t *n = NODE_NEWNODE(NODE_ENSURE, rb_node_ensure_t, loc);
11467 n->nd_head = nd_head;
11468 n->nd_ensr = nd_ensr;
11473static rb_node_and_t *
11474rb_node_and_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *operator_loc)
11476 rb_node_and_t *n = NODE_NEWNODE(NODE_AND, rb_node_and_t, loc);
11477 n->nd_1st = nd_1st;
11478 n->nd_2nd = nd_2nd;
11479 n->operator_loc = *operator_loc;
11484static rb_node_or_t *
11485rb_node_or_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *operator_loc)
11487 rb_node_or_t *n = NODE_NEWNODE(NODE_OR, rb_node_or_t, loc);
11488 n->nd_1st = nd_1st;
11489 n->nd_2nd = nd_2nd;
11490 n->operator_loc = *operator_loc;
11495static rb_node_return_t *
11496rb_node_return_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
11498 rb_node_return_t *n = NODE_NEWNODE(NODE_RETURN, rb_node_return_t, loc);
11499 n->nd_stts = nd_stts;
11500 n->keyword_loc = *keyword_loc;
11504static rb_node_yield_t *
11505rb_node_yield_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
11507 rb_node_yield_t *n = NODE_NEWNODE(NODE_YIELD, rb_node_yield_t, loc);
11508 n->nd_head = nd_head;
11513static rb_node_if_t *
11514rb_node_if_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, NODE *nd_else, const YYLTYPE *loc)
11516 rb_node_if_t *n = NODE_NEWNODE(NODE_IF, rb_node_if_t, loc);
11517 n->nd_cond = nd_cond;
11518 n->nd_body = nd_body;
11519 n->nd_else = nd_else;
11524static rb_node_unless_t *
11525rb_node_unless_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, NODE *nd_else, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc, const YYLTYPE *end_keyword_loc)
11527 rb_node_unless_t *n = NODE_NEWNODE(NODE_UNLESS, rb_node_unless_t, loc);
11528 n->nd_cond = nd_cond;
11529 n->nd_body = nd_body;
11530 n->nd_else = nd_else;
11531 n->keyword_loc = *keyword_loc;
11532 n->then_keyword_loc = *then_keyword_loc;
11533 n->end_keyword_loc = *end_keyword_loc;
11538static rb_node_class_t *
11539rb_node_class_new(struct parser_params *p, NODE *nd_cpath, NODE *nd_body, NODE *nd_super, const YYLTYPE *loc)
11541 /* Keep the order of node creation */
11542 NODE *scope = NEW_SCOPE(0, nd_body, loc);
11543 rb_node_class_t *n = NODE_NEWNODE(NODE_CLASS, rb_node_class_t, loc);
11544 n->nd_cpath = nd_cpath;
11545 n->nd_body = scope;
11546 n->nd_super = nd_super;
11551static rb_node_sclass_t *
11552rb_node_sclass_new(struct parser_params *p, NODE *nd_recv, NODE *nd_body, const YYLTYPE *loc)
11554 /* Keep the order of node creation */
11555 NODE *scope = NEW_SCOPE(0, nd_body, loc);
11556 rb_node_sclass_t *n = NODE_NEWNODE(NODE_SCLASS, rb_node_sclass_t, loc);
11557 n->nd_recv = nd_recv;
11558 n->nd_body = scope;
11563static rb_node_module_t *
11564rb_node_module_new(struct parser_params *p, NODE *nd_cpath, NODE *nd_body, const YYLTYPE *loc)
11566 /* Keep the order of node creation */
11567 NODE *scope = NEW_SCOPE(0, nd_body, loc);
11568 rb_node_module_t *n = NODE_NEWNODE(NODE_MODULE, rb_node_module_t, loc);
11569 n->nd_cpath = nd_cpath;
11570 n->nd_body = scope;
11575static rb_node_iter_t *
11576rb_node_iter_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc)
11578 /* Keep the order of node creation */
11579 NODE *scope = NEW_SCOPE(nd_args, nd_body, loc);
11580 rb_node_iter_t *n = NODE_NEWNODE(NODE_ITER, rb_node_iter_t, loc);
11581 n->nd_body = scope;
11587static rb_node_lambda_t *
11588rb_node_lambda_new(struct parser_params *p, rb_node_args_t *nd_args, NODE *nd_body, const YYLTYPE *loc)
11590 /* Keep the order of node creation */
11591 NODE *scope = NEW_SCOPE(nd_args, nd_body, loc);
11592 rb_node_lambda_t *n = NODE_NEWNODE(NODE_LAMBDA, rb_node_lambda_t, loc);
11593 n->nd_body = scope;
11598static rb_node_case_t *
11599rb_node_case_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc)
11601 rb_node_case_t *n = NODE_NEWNODE(NODE_CASE, rb_node_case_t, loc);
11602 n->nd_head = nd_head;
11603 n->nd_body = nd_body;
11604 n->case_keyword_loc = *case_keyword_loc;
11605 n->end_keyword_loc = *end_keyword_loc;
11610static rb_node_case2_t *
11611rb_node_case2_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc)
11613 rb_node_case2_t *n = NODE_NEWNODE(NODE_CASE2, rb_node_case2_t, loc);
11615 n->nd_body = nd_body;
11616 n->case_keyword_loc = *case_keyword_loc;
11617 n->end_keyword_loc = *end_keyword_loc;
11622static rb_node_case3_t *
11623rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc)
11625 rb_node_case3_t *n = NODE_NEWNODE(NODE_CASE3, rb_node_case3_t, loc);
11626 n->nd_head = nd_head;
11627 n->nd_body = nd_body;
11628 n->case_keyword_loc = *case_keyword_loc;
11629 n->end_keyword_loc = *end_keyword_loc;
11634static rb_node_when_t *
11635rb_node_when_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc)
11637 rb_node_when_t *n = NODE_NEWNODE(NODE_WHEN, rb_node_when_t, loc);
11638 n->nd_head = nd_head;
11639 n->nd_body = nd_body;
11640 n->nd_next = nd_next;
11641 n->keyword_loc = *keyword_loc;
11642 n->then_keyword_loc = *then_keyword_loc;
11647static rb_node_in_t *
11648rb_node_in_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc)
11650 rb_node_in_t *n = NODE_NEWNODE(NODE_IN, rb_node_in_t, loc);
11651 n->nd_head = nd_head;
11652 n->nd_body = nd_body;
11653 n->nd_next = nd_next;
11658static rb_node_while_t *
11659rb_node_while_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, long nd_state, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *closing_loc)
11661 rb_node_while_t *n = NODE_NEWNODE(NODE_WHILE, rb_node_while_t, loc);
11662 n->nd_cond = nd_cond;
11663 n->nd_body = nd_body;
11664 n->nd_state = nd_state;
11665 n->keyword_loc = *keyword_loc;
11666 n->closing_loc = *closing_loc;
11671static rb_node_until_t *
11672rb_node_until_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, long nd_state, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *closing_loc)
11674 rb_node_until_t *n = NODE_NEWNODE(NODE_UNTIL, rb_node_until_t, loc);
11675 n->nd_cond = nd_cond;
11676 n->nd_body = nd_body;
11677 n->nd_state = nd_state;
11678 n->keyword_loc = *keyword_loc;
11679 n->closing_loc = *closing_loc;
11684static rb_node_colon2_t *
11685rb_node_colon2_new(struct parser_params *p, NODE *nd_head, ID nd_mid, const YYLTYPE *loc)
11687 rb_node_colon2_t *n = NODE_NEWNODE(NODE_COLON2, rb_node_colon2_t, loc);
11688 n->nd_head = nd_head;
11689 n->nd_mid = nd_mid;
11694static rb_node_colon3_t *
11695rb_node_colon3_new(struct parser_params *p, ID nd_mid, const YYLTYPE *loc)
11697 rb_node_colon3_t *n = NODE_NEWNODE(NODE_COLON3, rb_node_colon3_t, loc);
11698 n->nd_mid = nd_mid;
11703static rb_node_dot2_t *
11704rb_node_dot2_new(struct parser_params *p, NODE *nd_beg, NODE *nd_end, const YYLTYPE *loc)
11706 rb_node_dot2_t *n = NODE_NEWNODE(NODE_DOT2, rb_node_dot2_t, loc);
11707 n->nd_beg = nd_beg;
11708 n->nd_end = nd_end;
11713static rb_node_dot3_t *
11714rb_node_dot3_new(struct parser_params *p, NODE *nd_beg, NODE *nd_end, const YYLTYPE *loc)
11716 rb_node_dot3_t *n = NODE_NEWNODE(NODE_DOT3, rb_node_dot3_t, loc);
11717 n->nd_beg = nd_beg;
11718 n->nd_end = nd_end;
11723static rb_node_self_t *
11724rb_node_self_new(struct parser_params *p, const YYLTYPE *loc)
11726 rb_node_self_t *n = NODE_NEWNODE(NODE_SELF, rb_node_self_t, loc);
11732static rb_node_nil_t *
11733rb_node_nil_new(struct parser_params *p, const YYLTYPE *loc)
11735 rb_node_nil_t *n = NODE_NEWNODE(NODE_NIL, rb_node_nil_t, loc);
11740static rb_node_true_t *
11741rb_node_true_new(struct parser_params *p, const YYLTYPE *loc)
11743 rb_node_true_t *n = NODE_NEWNODE(NODE_TRUE, rb_node_true_t, loc);
11748static rb_node_false_t *
11749rb_node_false_new(struct parser_params *p, const YYLTYPE *loc)
11751 rb_node_false_t *n = NODE_NEWNODE(NODE_FALSE, rb_node_false_t, loc);
11756static rb_node_super_t *
11757rb_node_super_new(struct parser_params *p, NODE *nd_args, const YYLTYPE *loc)
11759 rb_node_super_t *n = NODE_NEWNODE(NODE_SUPER, rb_node_super_t, loc);
11760 n->nd_args = nd_args;
11765static rb_node_zsuper_t *
11766rb_node_zsuper_new(struct parser_params *p, const YYLTYPE *loc)
11768 rb_node_zsuper_t *n = NODE_NEWNODE(NODE_ZSUPER, rb_node_zsuper_t, loc);
11773static rb_node_match2_t *
11774rb_node_match2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, const YYLTYPE *loc)
11776 rb_node_match2_t *n = NODE_NEWNODE(NODE_MATCH2, rb_node_match2_t, loc);
11777 n->nd_recv = nd_recv;
11778 n->nd_value = nd_value;
11784static rb_node_match3_t *
11785rb_node_match3_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, const YYLTYPE *loc)
11787 rb_node_match3_t *n = NODE_NEWNODE(NODE_MATCH3, rb_node_match3_t, loc);
11788 n->nd_recv = nd_recv;
11789 n->nd_value = nd_value;
11794/* TODO: Use union for NODE_LIST2 */
11795static rb_node_list_t *
11796rb_node_list_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
11798 rb_node_list_t *n = NODE_NEWNODE(NODE_LIST, rb_node_list_t, loc);
11799 n->nd_head = nd_head;
11806static rb_node_list_t *
11807rb_node_list_new2(struct parser_params *p, NODE *nd_head, long nd_alen, NODE *nd_next, const YYLTYPE *loc)
11809 rb_node_list_t *n = NODE_NEWNODE(NODE_LIST, rb_node_list_t, loc);
11810 n->nd_head = nd_head;
11811 n->as.nd_alen = nd_alen;
11812 n->nd_next = nd_next;
11817static rb_node_zlist_t *
11818rb_node_zlist_new(struct parser_params *p, const YYLTYPE *loc)
11820 rb_node_zlist_t *n = NODE_NEWNODE(NODE_ZLIST, rb_node_zlist_t, loc);
11825static rb_node_hash_t *
11826rb_node_hash_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
11828 rb_node_hash_t *n = NODE_NEWNODE(NODE_HASH, rb_node_hash_t, loc);
11829 n->nd_head = nd_head;
11835static rb_node_masgn_t *
11836rb_node_masgn_new(struct parser_params *p, NODE *nd_head, NODE *nd_args, const YYLTYPE *loc)
11838 rb_node_masgn_t *n = NODE_NEWNODE(NODE_MASGN, rb_node_masgn_t, loc);
11839 n->nd_head = nd_head;
11841 n->nd_args = nd_args;
11846static rb_node_gasgn_t *
11847rb_node_gasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc)
11849 rb_node_gasgn_t *n = NODE_NEWNODE(NODE_GASGN, rb_node_gasgn_t, loc);
11850 n->nd_vid = nd_vid;
11851 n->nd_value = nd_value;
11856static rb_node_lasgn_t *
11857rb_node_lasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc)
11859 rb_node_lasgn_t *n = NODE_NEWNODE(NODE_LASGN, rb_node_lasgn_t, loc);
11860 n->nd_vid = nd_vid;
11861 n->nd_value = nd_value;
11866static rb_node_dasgn_t *
11867rb_node_dasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc)
11869 rb_node_dasgn_t *n = NODE_NEWNODE(NODE_DASGN, rb_node_dasgn_t, loc);
11870 n->nd_vid = nd_vid;
11871 n->nd_value = nd_value;
11876static rb_node_iasgn_t *
11877rb_node_iasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc)
11879 rb_node_iasgn_t *n = NODE_NEWNODE(NODE_IASGN, rb_node_iasgn_t, loc);
11880 n->nd_vid = nd_vid;
11881 n->nd_value = nd_value;
11886static rb_node_cvasgn_t *
11887rb_node_cvasgn_new(struct parser_params *p, ID nd_vid, NODE *nd_value, const YYLTYPE *loc)
11889 rb_node_cvasgn_t *n = NODE_NEWNODE(NODE_CVASGN, rb_node_cvasgn_t, loc);
11890 n->nd_vid = nd_vid;
11891 n->nd_value = nd_value;
11896static rb_node_op_asgn1_t *
11897rb_node_op_asgn1_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *index, NODE *rvalue, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc)
11899 rb_node_op_asgn1_t *n = NODE_NEWNODE(NODE_OP_ASGN1, rb_node_op_asgn1_t, loc);
11900 n->nd_recv = nd_recv;
11901 n->nd_mid = nd_mid;
11902 n->nd_index = index;
11903 n->nd_rvalue = rvalue;
11904 n->call_operator_loc = *call_operator_loc;
11905 n->opening_loc = *opening_loc;
11906 n->closing_loc = *closing_loc;
11907 n->binary_operator_loc = *binary_operator_loc;
11912static rb_node_op_asgn2_t *
11913rb_node_op_asgn2_new(struct parser_params *p, NODE *nd_recv, NODE *nd_value, ID nd_vid, ID nd_mid, bool nd_aid, const YYLTYPE *loc, const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc)
11915 rb_node_op_asgn2_t *n = NODE_NEWNODE(NODE_OP_ASGN2, rb_node_op_asgn2_t, loc);
11916 n->nd_recv = nd_recv;
11917 n->nd_value = nd_value;
11918 n->nd_vid = nd_vid;
11919 n->nd_mid = nd_mid;
11920 n->nd_aid = nd_aid;
11921 n->call_operator_loc = *call_operator_loc;
11922 n->message_loc = *message_loc;
11923 n->binary_operator_loc = *binary_operator_loc;
11928static rb_node_op_asgn_or_t *
11929rb_node_op_asgn_or_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc)
11931 rb_node_op_asgn_or_t *n = NODE_NEWNODE(NODE_OP_ASGN_OR, rb_node_op_asgn_or_t, loc);
11932 n->nd_head = nd_head;
11933 n->nd_value = nd_value;
11938static rb_node_op_asgn_and_t *
11939rb_node_op_asgn_and_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, const YYLTYPE *loc)
11941 rb_node_op_asgn_and_t *n = NODE_NEWNODE(NODE_OP_ASGN_AND, rb_node_op_asgn_and_t, loc);
11942 n->nd_head = nd_head;
11943 n->nd_value = nd_value;
11948static rb_node_gvar_t *
11949rb_node_gvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11951 rb_node_gvar_t *n = NODE_NEWNODE(NODE_GVAR, rb_node_gvar_t, loc);
11952 n->nd_vid = nd_vid;
11957static rb_node_lvar_t *
11958rb_node_lvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11960 rb_node_lvar_t *n = NODE_NEWNODE(NODE_LVAR, rb_node_lvar_t, loc);
11961 n->nd_vid = nd_vid;
11966static rb_node_dvar_t *
11967rb_node_dvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11969 rb_node_dvar_t *n = NODE_NEWNODE(NODE_DVAR, rb_node_dvar_t, loc);
11970 n->nd_vid = nd_vid;
11975static rb_node_ivar_t *
11976rb_node_ivar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11978 rb_node_ivar_t *n = NODE_NEWNODE(NODE_IVAR, rb_node_ivar_t, loc);
11979 n->nd_vid = nd_vid;
11984static rb_node_const_t *
11985rb_node_const_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11987 rb_node_const_t *n = NODE_NEWNODE(NODE_CONST, rb_node_const_t, loc);
11988 n->nd_vid = nd_vid;
11993static rb_node_cvar_t *
11994rb_node_cvar_new(struct parser_params *p, ID nd_vid, const YYLTYPE *loc)
11996 rb_node_cvar_t *n = NODE_NEWNODE(NODE_CVAR, rb_node_cvar_t, loc);
11997 n->nd_vid = nd_vid;
12002static rb_node_nth_ref_t *
12003rb_node_nth_ref_new(struct parser_params *p, long nd_nth, const YYLTYPE *loc)
12005 rb_node_nth_ref_t *n = NODE_NEWNODE(NODE_NTH_REF, rb_node_nth_ref_t, loc);
12006 n->nd_nth = nd_nth;
12011static rb_node_back_ref_t *
12012rb_node_back_ref_new(struct parser_params *p, long nd_nth, const YYLTYPE *loc)
12014 rb_node_back_ref_t *n = NODE_NEWNODE(NODE_BACK_REF, rb_node_back_ref_t, loc);
12015 n->nd_nth = nd_nth;
12020static rb_node_integer_t *
12021rb_node_integer_new(struct parser_params *p, char* val, int base, const YYLTYPE *loc)
12023 rb_node_integer_t *n = NODE_NEWNODE(NODE_INTEGER, rb_node_integer_t, loc);
12031static rb_node_float_t *
12032rb_node_float_new(struct parser_params *p, char* val, const YYLTYPE *loc)
12034 rb_node_float_t *n = NODE_NEWNODE(NODE_FLOAT, rb_node_float_t, loc);
12041static rb_node_rational_t *
12042rb_node_rational_new(struct parser_params *p, char* val, int base, int seen_point, const YYLTYPE *loc)
12044 rb_node_rational_t *n = NODE_NEWNODE(NODE_RATIONAL, rb_node_rational_t, loc);
12048 n->seen_point = seen_point;
12053static rb_node_imaginary_t *
12054rb_node_imaginary_new(struct parser_params *p, char* val, int base, int seen_point, enum rb_numeric_type numeric_type, const YYLTYPE *loc)
12056 rb_node_imaginary_t *n = NODE_NEWNODE(NODE_IMAGINARY, rb_node_imaginary_t, loc);
12060 n->seen_point = seen_point;
12061 n->type = numeric_type;
12066static rb_node_str_t *
12067rb_node_str_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc)
12069 rb_node_str_t *n = NODE_NEWNODE(NODE_STR, rb_node_str_t, loc);
12070 n->string = string;
12075/* TODO; Use union for NODE_DSTR2 */
12076static rb_node_dstr_t *
12077rb_node_dstr_new0(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc)
12079 rb_node_dstr_t *n = NODE_NEWNODE(NODE_DSTR, rb_node_dstr_t, loc);
12080 n->string = string;
12081 n->as.nd_alen = nd_alen;
12082 n->nd_next = (rb_node_list_t *)nd_next;
12087static rb_node_dstr_t *
12088rb_node_dstr_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc)
12090 return rb_node_dstr_new0(p, string, 1, 0, loc);
12093static rb_node_xstr_t *
12094rb_node_xstr_new(struct parser_params *p, rb_parser_string_t *string, const YYLTYPE *loc)
12096 rb_node_xstr_t *n = NODE_NEWNODE(NODE_XSTR, rb_node_xstr_t, loc);
12097 n->string = string;
12102static rb_node_dxstr_t *
12103rb_node_dxstr_new(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc)
12105 rb_node_dxstr_t *n = NODE_NEWNODE(NODE_DXSTR, rb_node_dxstr_t, loc);
12106 n->string = string;
12107 n->as.nd_alen = nd_alen;
12108 n->nd_next = (rb_node_list_t *)nd_next;
12113static rb_node_sym_t *
12114rb_node_sym_new(struct parser_params *p, VALUE str, const YYLTYPE *loc)
12116 rb_node_sym_t *n = NODE_NEWNODE(NODE_SYM, rb_node_sym_t, loc);
12117 n->string = rb_str_to_parser_string(p, str);
12122static rb_node_dsym_t *
12123rb_node_dsym_new(struct parser_params *p, rb_parser_string_t *string, long nd_alen, NODE *nd_next, const YYLTYPE *loc)
12125 rb_node_dsym_t *n = NODE_NEWNODE(NODE_DSYM, rb_node_dsym_t, loc);
12126 n->string = string;
12127 n->as.nd_alen = nd_alen;
12128 n->nd_next = (rb_node_list_t *)nd_next;
12133static rb_node_evstr_t *
12134rb_node_evstr_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
12136 rb_node_evstr_t *n = NODE_NEWNODE(NODE_EVSTR, rb_node_evstr_t, loc);
12137 n->nd_body = nd_body;
12142static rb_node_regx_t *
12143rb_node_regx_new(struct parser_params *p, rb_parser_string_t *string, int options, const YYLTYPE *loc)
12145 rb_node_regx_t *n = NODE_NEWNODE(NODE_REGX, rb_node_regx_t, loc);
12146 n->string = string;
12147 n->options = options & RE_OPTION_MASK;
12152static rb_node_call_t *
12153rb_node_call_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc)
12155 rb_node_call_t *n = NODE_NEWNODE(NODE_CALL, rb_node_call_t, loc);
12156 n->nd_recv = nd_recv;
12157 n->nd_mid = nd_mid;
12158 n->nd_args = nd_args;
12163static rb_node_opcall_t *
12164rb_node_opcall_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc)
12166 rb_node_opcall_t *n = NODE_NEWNODE(NODE_OPCALL, rb_node_opcall_t, loc);
12167 n->nd_recv = nd_recv;
12168 n->nd_mid = nd_mid;
12169 n->nd_args = nd_args;
12174static rb_node_fcall_t *
12175rb_node_fcall_new(struct parser_params *p, ID nd_mid, NODE *nd_args, const YYLTYPE *loc)
12177 rb_node_fcall_t *n = NODE_NEWNODE(NODE_FCALL, rb_node_fcall_t, loc);
12178 n->nd_mid = nd_mid;
12179 n->nd_args = nd_args;
12184static rb_node_qcall_t *
12185rb_node_qcall_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc)
12187 rb_node_qcall_t *n = NODE_NEWNODE(NODE_QCALL, rb_node_qcall_t, loc);
12188 n->nd_recv = nd_recv;
12189 n->nd_mid = nd_mid;
12190 n->nd_args = nd_args;
12195static rb_node_vcall_t *
12196rb_node_vcall_new(struct parser_params *p, ID nd_mid, const YYLTYPE *loc)
12198 rb_node_vcall_t *n = NODE_NEWNODE(NODE_VCALL, rb_node_vcall_t, loc);
12199 n->nd_mid = nd_mid;
12204static rb_node_once_t *
12205rb_node_once_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
12207 rb_node_once_t *n = NODE_NEWNODE(NODE_ONCE, rb_node_once_t, loc);
12208 n->nd_body = nd_body;
12213static rb_node_args_t *
12214rb_node_args_new(struct parser_params *p, const YYLTYPE *loc)
12216 rb_node_args_t *n = NODE_NEWNODE(NODE_ARGS, rb_node_args_t, loc);
12217 MEMZERO(&n->nd_ainfo, struct rb_args_info, 1);
12222static rb_node_args_aux_t *
12223rb_node_args_aux_new(struct parser_params *p, ID nd_pid, int nd_plen, const YYLTYPE *loc)
12225 rb_node_args_aux_t *n = NODE_NEWNODE(NODE_ARGS_AUX, rb_node_args_aux_t, loc);
12226 n->nd_pid = nd_pid;
12227 n->nd_plen = nd_plen;
12233static rb_node_opt_arg_t *
12234rb_node_opt_arg_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
12236 rb_node_opt_arg_t *n = NODE_NEWNODE(NODE_OPT_ARG, rb_node_opt_arg_t, loc);
12237 n->nd_body = nd_body;
12243static rb_node_kw_arg_t *
12244rb_node_kw_arg_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
12246 rb_node_kw_arg_t *n = NODE_NEWNODE(NODE_KW_ARG, rb_node_kw_arg_t, loc);
12247 n->nd_body = nd_body;
12253static rb_node_postarg_t *
12254rb_node_postarg_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc)
12256 rb_node_postarg_t *n = NODE_NEWNODE(NODE_POSTARG, rb_node_postarg_t, loc);
12257 n->nd_1st = nd_1st;
12258 n->nd_2nd = nd_2nd;
12263static rb_node_argscat_t *
12264rb_node_argscat_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc)
12266 rb_node_argscat_t *n = NODE_NEWNODE(NODE_ARGSCAT, rb_node_argscat_t, loc);
12267 n->nd_head = nd_head;
12268 n->nd_body = nd_body;
12273static rb_node_argspush_t *
12274rb_node_argspush_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc)
12276 rb_node_argspush_t *n = NODE_NEWNODE(NODE_ARGSPUSH, rb_node_argspush_t, loc);
12277 n->nd_head = nd_head;
12278 n->nd_body = nd_body;
12283static rb_node_splat_t *
12284rb_node_splat_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc, const YYLTYPE *operator_loc)
12286 rb_node_splat_t *n = NODE_NEWNODE(NODE_SPLAT, rb_node_splat_t, loc);
12287 n->nd_head = nd_head;
12288 n->operator_loc = *operator_loc;
12293static rb_node_block_pass_t *
12294rb_node_block_pass_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *operator_loc)
12296 rb_node_block_pass_t *n = NODE_NEWNODE(NODE_BLOCK_PASS, rb_node_block_pass_t, loc);
12299 n->nd_body = nd_body;
12300 n->operator_loc = *operator_loc;
12305static rb_node_alias_t *
12306rb_node_alias_new(struct parser_params *p, NODE *nd_1st, NODE *nd_2nd, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
12308 rb_node_alias_t *n = NODE_NEWNODE(NODE_ALIAS, rb_node_alias_t, loc);
12309 n->nd_1st = nd_1st;
12310 n->nd_2nd = nd_2nd;
12311 n->keyword_loc = *keyword_loc;
12316static rb_node_valias_t *
12317rb_node_valias_new(struct parser_params *p, ID nd_alias, ID nd_orig, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
12319 rb_node_valias_t *n = NODE_NEWNODE(NODE_VALIAS, rb_node_valias_t, loc);
12320 n->nd_alias = nd_alias;
12321 n->nd_orig = nd_orig;
12322 n->keyword_loc = *keyword_loc;
12327static rb_node_undef_t *
12328rb_node_undef_new(struct parser_params *p, NODE *nd_undef, const YYLTYPE *loc)
12330 rb_node_undef_t *n = NODE_NEWNODE(NODE_UNDEF, rb_node_undef_t, loc);
12331 n->nd_undefs = rb_parser_ary_new_capa_for_node(p, 1);
12332 n->keyword_loc = NULL_LOC;
12333 rb_parser_ary_push_node(p, n->nd_undefs, nd_undef);
12338static rb_node_errinfo_t *
12339rb_node_errinfo_new(struct parser_params *p, const YYLTYPE *loc)
12341 rb_node_errinfo_t *n = NODE_NEWNODE(NODE_ERRINFO, rb_node_errinfo_t, loc);
12346static rb_node_defined_t *
12347rb_node_defined_new(struct parser_params *p, NODE *nd_head, const YYLTYPE *loc)
12349 rb_node_defined_t *n = NODE_NEWNODE(NODE_DEFINED, rb_node_defined_t, loc);
12350 n->nd_head = nd_head;
12355static rb_node_postexe_t *
12356rb_node_postexe_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc)
12358 rb_node_postexe_t *n = NODE_NEWNODE(NODE_POSTEXE, rb_node_postexe_t, loc);
12359 n->nd_body = nd_body;
12364static rb_node_attrasgn_t *
12365rb_node_attrasgn_new(struct parser_params *p, NODE *nd_recv, ID nd_mid, NODE *nd_args, const YYLTYPE *loc)
12367 rb_node_attrasgn_t *n = NODE_NEWNODE(NODE_ATTRASGN, rb_node_attrasgn_t, loc);
12368 n->nd_recv = nd_recv;
12369 n->nd_mid = nd_mid;
12370 n->nd_args = nd_args;
12375static rb_node_aryptn_t *
12376rb_node_aryptn_new(struct parser_params *p, NODE *pre_args, NODE *rest_arg, NODE *post_args, const YYLTYPE *loc)
12378 rb_node_aryptn_t *n = NODE_NEWNODE(NODE_ARYPTN, rb_node_aryptn_t, loc);
12380 n->pre_args = pre_args;
12381 n->rest_arg = rest_arg;
12382 n->post_args = post_args;
12387static rb_node_hshptn_t *
12388rb_node_hshptn_new(struct parser_params *p, NODE *nd_pconst, NODE *nd_pkwargs, NODE *nd_pkwrestarg, const YYLTYPE *loc)
12390 rb_node_hshptn_t *n = NODE_NEWNODE(NODE_HSHPTN, rb_node_hshptn_t, loc);
12391 n->nd_pconst = nd_pconst;
12392 n->nd_pkwargs = nd_pkwargs;
12393 n->nd_pkwrestarg = nd_pkwrestarg;
12398static rb_node_fndptn_t *
12399rb_node_fndptn_new(struct parser_params *p, NODE *pre_rest_arg, NODE *args, NODE *post_rest_arg, const YYLTYPE *loc)
12401 rb_node_fndptn_t *n = NODE_NEWNODE(NODE_FNDPTN, rb_node_fndptn_t, loc);
12403 n->pre_rest_arg = pre_rest_arg;
12405 n->post_rest_arg = post_rest_arg;
12410static rb_node_line_t *
12411rb_node_line_new(struct parser_params *p, const YYLTYPE *loc)
12413 rb_node_line_t *n = NODE_NEWNODE(NODE_LINE, rb_node_line_t, loc);
12418static rb_node_file_t *
12419rb_node_file_new(struct parser_params *p, VALUE str, const YYLTYPE *loc)
12421 rb_node_file_t *n = NODE_NEWNODE(NODE_FILE, rb_node_file_t, loc);
12422 n->path = rb_str_to_parser_string(p, str);
12427static rb_node_encoding_t *
12428rb_node_encoding_new(struct parser_params *p, const YYLTYPE *loc)
12430 rb_node_encoding_t *n = NODE_NEWNODE(NODE_ENCODING, rb_node_encoding_t, loc);
12436static rb_node_cdecl_t *
12437rb_node_cdecl_new(struct parser_params *p, ID nd_vid, NODE *nd_value, NODE *nd_else, enum rb_parser_shareability shareability, const YYLTYPE *loc)
12439 rb_node_cdecl_t *n = NODE_NEWNODE(NODE_CDECL, rb_node_cdecl_t, loc);
12440 n->nd_vid = nd_vid;
12441 n->nd_value = nd_value;
12442 n->nd_else = nd_else;
12443 n->shareability = shareability;
12448static rb_node_op_cdecl_t *
12449rb_node_op_cdecl_new(struct parser_params *p, NODE *nd_head, NODE *nd_value, ID nd_aid, enum rb_parser_shareability shareability, const YYLTYPE *loc)
12451 rb_node_op_cdecl_t *n = NODE_NEWNODE(NODE_OP_CDECL, rb_node_op_cdecl_t, loc);
12452 n->nd_head = nd_head;
12453 n->nd_value = nd_value;
12454 n->nd_aid = nd_aid;
12455 n->shareability = shareability;
12460static rb_node_error_t *
12461rb_node_error_new(struct parser_params *p, const YYLTYPE *loc)
12463 rb_node_error_t *n = NODE_NEWNODE(NODE_ERROR, rb_node_error_t, loc);
12468static rb_node_break_t *
12469rb_node_break_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
12471 rb_node_break_t *n = NODE_NEWNODE(NODE_BREAK, rb_node_break_t, loc);
12472 n->nd_stts = nd_stts;
12474 n->keyword_loc = *keyword_loc;
12479static rb_node_next_t *
12480rb_node_next_new(struct parser_params *p, NODE *nd_stts, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
12482 rb_node_next_t *n = NODE_NEWNODE(NODE_NEXT, rb_node_next_t, loc);
12483 n->nd_stts = nd_stts;
12485 n->keyword_loc = *keyword_loc;
12490static rb_node_redo_t *
12491rb_node_redo_new(struct parser_params *p, const YYLTYPE *loc, const YYLTYPE *keyword_loc)
12493 rb_node_redo_t *n = NODE_NEWNODE(NODE_REDO, rb_node_redo_t, loc);
12495 n->keyword_loc = *keyword_loc;
12500static rb_node_def_temp_t *
12501rb_node_def_temp_new(struct parser_params *p, const YYLTYPE *loc)
12503 rb_node_def_temp_t *n = NODE_NEWNODE((enum node_type)NODE_DEF_TEMP, rb_node_def_temp_t, loc);
12504 n->save.numparam_save = 0;
12505 n->save.max_numparam = 0;
12506 n->save.ctxt = p->ctxt;
12513static rb_node_def_temp_t *
12514def_head_save(struct parser_params *p, rb_node_def_temp_t *n)
12516 n->save.numparam_save = numparam_push(p);
12517 n->save.max_numparam = p->max_numparam;
12522static enum node_type
12523nodetype(NODE *node) /* for debug */
12525 return (enum node_type)nd_type(node);
12529nodeline(NODE *node)
12531 return nd_line(node);
12536newline_node(NODE *node)
12539 node = remove_begin(node);
12540 nd_set_fl_newline(node);
12546fixpos(NODE *node, NODE *orig)
12550 nd_set_line(node, nd_line(orig));
12554block_append(struct parser_params *p, NODE *head, NODE *tail)
12556 NODE *end, *h = head, *nd;
12558 if (tail == 0) return head;
12560 if (h == 0) return tail;
12561 switch (nd_type(h)) {
12563 h = end = NEW_BLOCK(head, &head->nd_loc);
12567 end = RNODE_BLOCK(h)->nd_end;
12571 nd = RNODE_BLOCK(end)->nd_head;
12572 switch (nd_type(nd)) {
12578 rb_warning0L(nd_line(tail), "statement not reached");
12585 if (!nd_type_p(tail, NODE_BLOCK)) {
12586 tail = NEW_BLOCK(tail, &tail->nd_loc);
12588 RNODE_BLOCK(end)->nd_next = tail;
12589 RNODE_BLOCK(h)->nd_end = RNODE_BLOCK(tail)->nd_end;
12590 nd_set_last_loc(head, nd_last_loc(tail));
12594/* append item to the list */
12596list_append(struct parser_params *p, NODE *list, NODE *item)
12600 if (list == 0) return NEW_LIST(item, &item->nd_loc);
12601 if (RNODE_LIST(list)->nd_next) {
12602 last = RNODE_LIST(RNODE_LIST(list)->nd_next)->as.nd_end;
12608 RNODE_LIST(list)->as.nd_alen += 1;
12609 RNODE_LIST(last)->nd_next = NEW_LIST(item, &item->nd_loc);
12610 RNODE_LIST(RNODE_LIST(list)->nd_next)->as.nd_end = RNODE_LIST(last)->nd_next;
12612 nd_set_last_loc(list, nd_last_loc(item));
12617/* concat two lists */
12619list_concat(NODE *head, NODE *tail)
12623 if (RNODE_LIST(head)->nd_next) {
12624 last = RNODE_LIST(RNODE_LIST(head)->nd_next)->as.nd_end;
12630 RNODE_LIST(head)->as.nd_alen += RNODE_LIST(tail)->as.nd_alen;
12631 RNODE_LIST(last)->nd_next = tail;
12632 if (RNODE_LIST(tail)->nd_next) {
12633 RNODE_LIST(RNODE_LIST(head)->nd_next)->as.nd_end = RNODE_LIST(RNODE_LIST(tail)->nd_next)->as.nd_end;
12636 RNODE_LIST(RNODE_LIST(head)->nd_next)->as.nd_end = tail;
12639 nd_set_last_loc(head, nd_last_loc(tail));
12645literal_concat0(struct parser_params *p, rb_parser_string_t *head, rb_parser_string_t *tail)
12647 if (!tail) return 1;
12648 if (!rb_parser_enc_compatible(p, head, tail)) {
12649 compile_error(p, "string literal encodings differ (%s / %s)",
12650 rb_enc_name(rb_parser_str_get_encoding(head)),
12651 rb_enc_name(rb_parser_str_get_encoding(tail)));
12652 rb_parser_str_resize(p, head, 0);
12653 rb_parser_str_resize(p, tail, 0);
12656 rb_parser_str_buf_append(p, head, tail);
12660static rb_parser_string_t *
12661string_literal_head(struct parser_params *p, enum node_type htype, NODE *head)
12663 if (htype != NODE_DSTR) return NULL;
12664 if (RNODE_DSTR(head)->nd_next) {
12665 head = RNODE_LIST(RNODE_LIST(RNODE_DSTR(head)->nd_next)->as.nd_end)->nd_head;
12666 if (!head || !nd_type_p(head, NODE_STR)) return NULL;
12668 rb_parser_string_t *lit = RNODE_DSTR(head)->string;
12674static rb_parser_string_t *
12675rb_parser_string_deep_copy(struct parser_params *p, const rb_parser_string_t *orig)
12677 rb_parser_string_t *copy;
12678 if (!orig) return NULL;
12679 copy = rb_parser_string_new(p, PARSER_STRING_PTR(orig), PARSER_STRING_LEN(orig));
12680 copy->coderange = orig->coderange;
12681 copy->enc = orig->enc;
12686/* concat two string literals */
12688literal_concat(struct parser_params *p, NODE *head, NODE *tail, const YYLTYPE *loc)
12690 enum node_type htype;
12691 rb_parser_string_t *lit;
12693 if (!head) return tail;
12694 if (!tail) return head;
12696 htype = nd_type(head);
12697 if (htype == NODE_EVSTR) {
12698 head = new_dstr(p, head, loc);
12701 if (p->heredoc_indent > 0) {
12704 head = str2dstr(p, head);
12706 return list_append(p, head, tail);
12711 switch (nd_type(tail)) {
12713 if ((lit = string_literal_head(p, htype, head)) != false) {
12717 lit = RNODE_DSTR(head)->string;
12719 if (htype == NODE_STR) {
12720 if (!literal_concat0(p, lit, RNODE_STR(tail)->string)) {
12722 rb_discard_node(p, head);
12723 rb_discard_node(p, tail);
12726 rb_discard_node(p, tail);
12729 list_append(p, head, tail);
12734 if (htype == NODE_STR) {
12735 if (!literal_concat0(p, RNODE_STR(head)->string, RNODE_DSTR(tail)->string))
12737 rb_parser_string_free(p, RNODE_DSTR(tail)->string);
12738 RNODE_DSTR(tail)->string = RNODE_STR(head)->string;
12739 RNODE_STR(head)->string = NULL;
12740 rb_discard_node(p, head);
12743 else if (!RNODE_DSTR(tail)->string) {
12745 RNODE_DSTR(head)->as.nd_alen += RNODE_DSTR(tail)->as.nd_alen - 1;
12746 if (!RNODE_DSTR(head)->nd_next) {
12747 RNODE_DSTR(head)->nd_next = RNODE_DSTR(tail)->nd_next;
12749 else if (RNODE_DSTR(tail)->nd_next) {
12750 RNODE_DSTR(RNODE_DSTR(RNODE_DSTR(head)->nd_next)->as.nd_end)->nd_next = RNODE_DSTR(tail)->nd_next;
12751 RNODE_DSTR(RNODE_DSTR(head)->nd_next)->as.nd_end = RNODE_DSTR(RNODE_DSTR(tail)->nd_next)->as.nd_end;
12753 rb_discard_node(p, tail);
12755 else if ((lit = string_literal_head(p, htype, head)) != false) {
12756 if (!literal_concat0(p, lit, RNODE_DSTR(tail)->string))
12758 rb_parser_string_free(p, RNODE_DSTR(tail)->string);
12759 RNODE_DSTR(tail)->string = 0;
12763 list_concat(head, NEW_LIST2(NEW_STR(RNODE_DSTR(tail)->string, loc), RNODE_DSTR(tail)->as.nd_alen, (NODE *)RNODE_DSTR(tail)->nd_next, loc));
12764 RNODE_DSTR(tail)->string = 0;
12769 if (htype == NODE_STR) {
12770 head = str2dstr(p, head);
12771 RNODE_DSTR(head)->as.nd_alen = 1;
12773 list_append(p, head, tail);
12780nd_copy_flag(NODE *new_node, NODE *old_node)
12782 if (nd_fl_newline(old_node)) nd_set_fl_newline(new_node);
12783 nd_set_line(new_node, nd_line(old_node));
12784 new_node->nd_loc = old_node->nd_loc;
12785 new_node->node_id = old_node->node_id;
12789str2dstr(struct parser_params *p, NODE *node)
12791 NODE *new_node = (NODE *)NODE_NEW_INTERNAL(NODE_DSTR, rb_node_dstr_t);
12792 nd_copy_flag(new_node, node);
12793 RNODE_DSTR(new_node)->string = RNODE_STR(node)->string;
12794 RNODE_DSTR(new_node)->as.nd_alen = 0;
12795 RNODE_DSTR(new_node)->nd_next = 0;
12796 RNODE_STR(node)->string = 0;
12802str2regx(struct parser_params *p, NODE *node, int options)
12804 NODE *new_node = (NODE *)NODE_NEW_INTERNAL(NODE_REGX, rb_node_regx_t);
12805 nd_copy_flag(new_node, node);
12806 RNODE_REGX(new_node)->string = RNODE_STR(node)->string;
12807 RNODE_REGX(new_node)->options = options;
12808 RNODE_STR(node)->string = 0;
12814evstr2dstr(struct parser_params *p, NODE *node)
12816 if (nd_type_p(node, NODE_EVSTR)) {
12817 node = new_dstr(p, node, &node->nd_loc);
12823new_evstr(struct parser_params *p, NODE *node, const YYLTYPE *loc)
12828 switch (nd_type(node)) {
12830 return str2dstr(p, node);
12837 return NEW_EVSTR(head, loc);
12841new_dstr(struct parser_params *p, NODE *node, const YYLTYPE *loc)
12843 NODE *dstr = NEW_DSTR(STRING_NEW0(), loc);
12844 return list_append(p, dstr, node);
12848call_bin_op(struct parser_params *p, NODE *recv, ID id, NODE *arg1,
12849 const YYLTYPE *op_loc, const YYLTYPE *loc)
12854 expr = NEW_OPCALL(recv, id, NEW_LIST(arg1, &arg1->nd_loc), loc);
12855 nd_set_line(expr, op_loc->beg_pos.lineno);
12860call_uni_op(struct parser_params *p, NODE *recv, ID id, const YYLTYPE *op_loc, const YYLTYPE *loc)
12864 opcall = NEW_OPCALL(recv, id, 0, loc);
12865 nd_set_line(opcall, op_loc->beg_pos.lineno);
12870new_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, const YYLTYPE *op_loc, const YYLTYPE *loc)
12872 NODE *qcall = NEW_QCALL(atype, recv, mid, args, loc);
12873 nd_set_line(qcall, op_loc->beg_pos.lineno);
12878new_command_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, NODE *block, const YYLTYPE *op_loc, const YYLTYPE *loc)
12881 if (block) block_dup_check(p, args, block);
12882 ret = new_qcall(p, atype, recv, mid, args, op_loc, loc);
12883 if (block) ret = method_add_block(p, ret, block, loc);
12888#define nd_once_body(node) (nd_type_p((node), NODE_ONCE) ? RNODE_ONCE(node)->nd_body : node)
12891last_expr_once_body(NODE *node)
12893 if (!node) return 0;
12894 return nd_once_body(node);
12898match_op(struct parser_params *p, NODE *node1, NODE *node2, const YYLTYPE *op_loc, const YYLTYPE *loc)
12901 int line = op_loc->beg_pos.lineno;
12906 if ((n = last_expr_once_body(node1)) != 0) {
12907 switch (nd_type(n)) {
12910 NODE *match = NEW_MATCH2(node1, node2, loc);
12911 nd_set_line(match, line);
12917 const VALUE lit = rb_node_regx_string_val(n);
12919 NODE *match = NEW_MATCH2(node1, node2, loc);
12920 RNODE_MATCH2(match)->nd_args = reg_named_capture_assign(p, lit, loc, assignable);
12921 nd_set_line(match, line);
12928 if ((n = last_expr_once_body(node2)) != 0) {
12931 switch (nd_type(n)) {
12933 match3 = NEW_MATCH3(node2, node1, loc);
12938 n = NEW_CALL(node1, tMATCH, NEW_LIST(node2, &node2->nd_loc), loc);
12939 nd_set_line(n, line);
12943# if WARN_PAST_SCOPE
12945past_dvar_p(struct parser_params *p, ID id)
12947 struct vtable *past = p->lvtbl->past;
12949 if (vtable_included(past, id)) return 1;
12957numparam_nested_p(struct parser_params *p)
12959 struct local_vars *local = p->lvtbl;
12960 NODE *outer = local->numparam.outer;
12961 NODE *inner = local->numparam.inner;
12962 if (outer || inner) {
12963 NODE *used = outer ? outer : inner;
12964 compile_error(p, "numbered parameter is already used in\n"
12965 "%s:%d: %s block here",
12966 p->ruby_sourcefile, nd_line(used),
12967 outer ? "outer" : "inner");
12968 parser_show_error_line(p, &used->nd_loc);
12975numparam_used_p(struct parser_params *p)
12977 NODE *numparam = p->lvtbl->numparam.current;
12979 compile_error(p, "numbered parameter is already used in\n"
12980 "%s:%d: current block here",
12981 p->ruby_sourcefile, nd_line(numparam));
12982 parser_show_error_line(p, &numparam->nd_loc);
12989it_used_p(struct parser_params *p)
12991 NODE *it = p->lvtbl->it;
12993 compile_error(p, "'it' is already used in\n"
12994 "%s:%d: current block here",
12995 p->ruby_sourcefile, nd_line(it));
12996 parser_show_error_line(p, &it->nd_loc);
13003gettable(struct parser_params *p, ID id, const YYLTYPE *loc)
13009 return NEW_SELF(loc);
13011 return NEW_NIL(loc);
13013 return NEW_TRUE(loc);
13014 case keyword_false:
13015 return NEW_FALSE(loc);
13016 case keyword__FILE__:
13018 VALUE file = p->ruby_sourcefile_string;
13020 file = rb_str_new(0, 0);
13021 node = NEW_FILE(file, loc);
13024 case keyword__LINE__:
13025 return NEW_LINE(loc);
13026 case keyword__ENCODING__:
13027 return NEW_ENCODING(loc);
13030 switch (id_type(id)) {
13032 if (dyna_in_block(p) && dvar_defined_ref(p, id, &vidp)) {
13033 if (NUMPARAM_ID_P(id) && (numparam_nested_p(p) || it_used_p(p))) return 0;
13034 if (vidp) *vidp |= LVAR_USED;
13035 node = NEW_DVAR(id, loc);
13038 if (local_id_ref(p, id, &vidp)) {
13039 if (vidp) *vidp |= LVAR_USED;
13040 node = NEW_LVAR(id, loc);
13043 if (dyna_in_block(p) && NUMPARAM_ID_P(id) &&
13044 parser_numbered_param(p, NUMPARAM_ID_TO_IDX(id))) {
13045 if (numparam_nested_p(p) || it_used_p(p)) return 0;
13046 node = NEW_DVAR(id, loc);
13047 struct local_vars *local = p->lvtbl;
13048 if (!local->numparam.current) local->numparam.current = node;
13051# if WARN_PAST_SCOPE
13052 if (!p->ctxt.in_defined && RTEST(ruby_verbose) && past_dvar_p(p, id)) {
13053 rb_warning1("possible reference to past scope - %"PRIsWARN, rb_id2str(id));
13056 /* method call without arguments */
13057 if (dyna_in_block(p) && id == rb_intern("it") && !(DVARS_TERMINAL_P(p->lvtbl->args) || DVARS_TERMINAL_P(p->lvtbl->args->prev))) {
13058 if (numparam_used_p(p)) return 0;
13059 if (p->max_numparam == ORDINAL_PARAM) {
13060 compile_error(p, "ordinary parameter is defined");
13064 p->it_id = internal_id(p);
13065 vtable_add(p->lvtbl->args, p->it_id);
13067 NODE *node = NEW_DVAR(p->it_id, loc);
13068 if (!p->lvtbl->it) p->lvtbl->it = node;
13071 return NEW_VCALL(id, loc);
13073 return NEW_GVAR(id, loc);
13075 return NEW_IVAR(id, loc);
13077 return NEW_CONST(id, loc);
13079 return NEW_CVAR(id, loc);
13081 compile_error(p, "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
13085static rb_node_opt_arg_t *
13086opt_arg_append(rb_node_opt_arg_t *opt_list, rb_node_opt_arg_t *opt)
13088 rb_node_opt_arg_t *opts = opt_list;
13089 RNODE(opts)->nd_loc.end_pos = RNODE(opt)->nd_loc.end_pos;
13091 while (opts->nd_next) {
13092 opts = opts->nd_next;
13093 RNODE(opts)->nd_loc.end_pos = RNODE(opt)->nd_loc.end_pos;
13095 opts->nd_next = opt;
13100static rb_node_kw_arg_t *
13101kwd_append(rb_node_kw_arg_t *kwlist, rb_node_kw_arg_t *kw)
13104 /* Assume rb_node_kw_arg_t and rb_node_opt_arg_t has same structure */
13105 opt_arg_append(RNODE_OPT_ARG(kwlist), RNODE_OPT_ARG(kw));
13111new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc)
13115 if (nd_type_p(n, NODE_BEGIN)) {
13116 n = RNODE_BEGIN(n)->nd_body;
13118 else if (nd_type_p(n, NODE_BLOCK) && RNODE_BLOCK(n)->nd_end == n) {
13119 n = RNODE_BLOCK(n)->nd_head;
13125 return NEW_DEFINED(n, loc);
13129str_to_sym_node(struct parser_params *p, NODE *node, const YYLTYPE *loc)
13132 rb_parser_string_t *str = RNODE_STR(node)->string;
13133 if (rb_parser_enc_str_coderange(p, str) == RB_PARSER_ENC_CODERANGE_BROKEN) {
13134 yyerror1(loc, "invalid symbol");
13138 lit = rb_str_new_parser_string(str);
13140 return NEW_SYM(lit, loc);
13144symbol_append(struct parser_params *p, NODE *symbols, NODE *symbol)
13146 enum node_type type = nd_type(symbol);
13149 nd_set_type(symbol, NODE_DSYM);
13152 symbol = str_to_sym_node(p, symbol, &RNODE(symbol)->nd_loc);
13155 compile_error(p, "unexpected node as symbol: %s", parser_node_name(type));
13157 return list_append(p, symbols, symbol);
13161new_regexp(struct parser_params *p, NODE *node, int options, const YYLTYPE *loc)
13163 struct RNode_LIST *list;
13167 /* Check string is valid regex */
13168 rb_parser_string_t *str = STRING_NEW0();
13169 reg_compile(p, str, options);
13170 node = NEW_REGX(str, options, loc);
13173 switch (nd_type(node)) {
13176 /* Check string is valid regex */
13177 reg_compile(p, RNODE_STR(node)->string, options);
13178 node = str2regx(p, node, options);
13182 node = NEW_DSTR0(STRING_NEW0(), 1, NEW_LIST(node, loc), loc);
13185 nd_set_type(node, NODE_DREGX);
13186 nd_set_loc(node, loc);
13187 rb_node_dregx_t *const dreg = RNODE_DREGX(node);
13188 dreg->as.nd_cflag = options & RE_OPTION_MASK;
13189 if (dreg->string) reg_fragment_check(p, dreg->string, options);
13191 for (list = dreg->nd_next; list; list = RNODE_LIST(list->nd_next)) {
13192 NODE *frag = list->nd_head;
13193 enum node_type type = nd_type(frag);
13194 if (type == NODE_STR || (type == NODE_DSTR && !RNODE_DSTR(frag)->nd_next)) {
13195 rb_parser_string_t *tail = RNODE_STR(frag)->string;
13196 if (reg_fragment_check(p, tail, options) && prev && RNODE_DREGX(prev)->string) {
13197 rb_parser_string_t *lit = prev == node ? dreg->string : RNODE_STR(RNODE_LIST(prev)->nd_head)->string;
13198 if (!literal_concat0(p, lit, tail)) {
13199 return NEW_NIL(loc); /* dummy node on error */
13201 rb_parser_str_resize(p, tail, 0);
13202 RNODE_LIST(prev)->nd_next = list->nd_next;
13203 rb_discard_node(p, list->nd_head);
13204 rb_discard_node(p, (NODE *)list);
13205 list = RNODE_LIST(prev);
13208 prev = (NODE *)list;
13215 if (!dreg->nd_next) {
13216 /* Check string is valid regex */
13217 reg_compile(p, dreg->string, options);
13219 if (options & RE_OPTION_ONCE) {
13220 node = NEW_ONCE(node, loc);
13227static rb_node_kw_arg_t *
13228new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc)
13231 return NEW_KW_ARG((k), loc);
13235new_xstring(struct parser_params *p, NODE *node, const YYLTYPE *loc)
13238 NODE *xstr = NEW_XSTR(STRING_NEW0(), loc);
13241 switch (nd_type(node)) {
13243 nd_set_type(node, NODE_XSTR);
13244 nd_set_loc(node, loc);
13247 nd_set_type(node, NODE_DXSTR);
13248 nd_set_loc(node, loc);
13251 node = NEW_DXSTR(0, 1, NEW_LIST(node, loc), loc);
13258struct st_hash_type literal_type = {
13263static int nd_type_st_key_enable_p(NODE *node);
13266check_literal_when(struct parser_params *p, NODE *arg, const YYLTYPE *loc)
13268 /* See https://bugs.ruby-lang.org/issues/20331 for discussion about what is warned. */
13269 if (!arg || !p->case_labels) return;
13270 if (!nd_type_st_key_enable_p(arg)) return;
13272 if (p->case_labels == CHECK_LITERAL_WHEN) {
13273 p->case_labels = st_init_table(&literal_type);
13277 if (st_lookup(p->case_labels, (st_data_t)arg, &line)) {
13278 rb_warning2("'when' clause on line %d duplicates 'when' clause on line %d and is ignored",
13279 WARN_I((int)nd_line(arg)), WARN_I((int)line));
13283 st_insert(p->case_labels, (st_data_t)arg, (st_data_t)p->ruby_sourceline);
13288id_is_var(struct parser_params *p, ID id)
13290 if (is_notop_id(id)) {
13291 switch (id & ID_SCOPE_MASK) {
13292 case ID_GLOBAL: case ID_INSTANCE: case ID_CONST: case ID_CLASS:
13295 if (dyna_in_block(p)) {
13296 if (NUMPARAM_ID_P(id) || dvar_defined(p, id)) return 1;
13298 if (local_id(p, id)) return 1;
13299 /* method call without arguments */
13303 compile_error(p, "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
13308static inline enum lex_state_e
13309parser_set_lex_state(struct parser_params *p, enum lex_state_e ls, int line)
13312 ls = rb_parser_trace_lex_state(p, p->lex.state, ls, line);
13314 return p->lex.state = ls;
13319flush_debug_buffer(struct parser_params *p, VALUE out, VALUE str)
13321 VALUE mesg = p->debug_buffer;
13323 if (!NIL_P(mesg) && RSTRING_LEN(mesg)) {
13324 p->debug_buffer = Qnil;
13325 rb_io_puts(1, &mesg, out);
13327 if (!NIL_P(str) && RSTRING_LEN(str)) {
13328 rb_io_write(p->debug_output, str);
13332static const char rb_parser_lex_state_names[][8] = {
13333 "BEG", "END", "ENDARG", "ENDFN", "ARG",
13334 "CMDARG", "MID", "FNAME", "DOT", "CLASS",
13335 "LABEL", "LABELED","FITEM",
13339append_lex_state_name(struct parser_params *p, enum lex_state_e state, VALUE buf)
13342 unsigned int mask = 1;
13343 static const char none[] = "NONE";
13345 for (i = 0; i < EXPR_MAX_STATE; ++i, mask <<= 1) {
13346 if ((unsigned)state & mask) {
13348 rb_str_cat(buf, "|", 1);
13351 rb_str_cat_cstr(buf, rb_parser_lex_state_names[i]);
13355 rb_str_cat(buf, none, sizeof(none)-1);
13361rb_parser_trace_lex_state(struct parser_params *p, enum lex_state_e from,
13362 enum lex_state_e to, int line)
13365 mesg = rb_str_new_cstr("lex_state: ");
13366 append_lex_state_name(p, from, mesg);
13367 rb_str_cat_cstr(mesg, " -> ");
13368 append_lex_state_name(p, to, mesg);
13369 rb_str_catf(mesg, " at line %d\n", line);
13370 flush_debug_buffer(p, p->debug_output, mesg);
13375rb_parser_lex_state_name(struct parser_params *p, enum lex_state_e state)
13377 return rb_str_to_interned_str(append_lex_state_name(p, state, rb_str_new(0, 0)));
13381append_bitstack_value(struct parser_params *p, stack_type stack, VALUE mesg)
13384 rb_str_cat_cstr(mesg, "0");
13387 stack_type mask = (stack_type)1U << (CHAR_BIT * sizeof(stack_type) - 1);
13388 for (; mask && !(stack & mask); mask >>= 1) continue;
13389 for (; mask; mask >>= 1) rb_str_cat(mesg, stack & mask ? "1" : "0", 1);
13394rb_parser_show_bitstack(struct parser_params *p, stack_type stack,
13395 const char *name, int line)
13397 VALUE mesg = rb_sprintf("%s: ", name);
13398 append_bitstack_value(p, stack, mesg);
13399 rb_str_catf(mesg, " at line %d\n", line);
13400 flush_debug_buffer(p, p->debug_output, mesg);
13404rb_parser_fatal(struct parser_params *p, const char *fmt, ...)
13407 VALUE mesg = rb_str_new_cstr("internal parser error: ");
13410 rb_str_vcatf(mesg, fmt, ap);
13412 yyerror0(RSTRING_PTR(mesg));
13415 mesg = rb_str_new(0, 0);
13416 append_lex_state_name(p, p->lex.state, mesg);
13417 compile_error(p, "lex.state: %"PRIsVALUE, mesg);
13418 rb_str_resize(mesg, 0);
13419 append_bitstack_value(p, p->cond_stack, mesg);
13420 compile_error(p, "cond_stack: %"PRIsVALUE, mesg);
13421 rb_str_resize(mesg, 0);
13422 append_bitstack_value(p, p->cmdarg_stack, mesg);
13423 compile_error(p, "cmdarg_stack: %"PRIsVALUE, mesg);
13424 if (p->debug_output == rb_ractor_stdout())
13425 p->debug_output = rb_ractor_stderr();
13430rb_parser_set_pos(YYLTYPE *yylloc, int sourceline, int beg_pos, int end_pos)
13432 yylloc->beg_pos.lineno = sourceline;
13433 yylloc->beg_pos.column = beg_pos;
13434 yylloc->end_pos.lineno = sourceline;
13435 yylloc->end_pos.column = end_pos;
13440rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_heredoc_t *here, YYLTYPE *yylloc)
13442 int sourceline = here->sourceline;
13443 int beg_pos = (int)here->offset - here->quote
13444 - (rb_strlen_lit("<<-") - !(here->func & STR_FUNC_INDENT));
13445 int end_pos = (int)here->offset + here->length + here->quote;
13447 return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos);
13451rb_parser_set_location_of_delayed_token(struct parser_params *p, YYLTYPE *yylloc)
13453 yylloc->beg_pos.lineno = p->delayed.beg_line;
13454 yylloc->beg_pos.column = p->delayed.beg_col;
13455 yylloc->end_pos.lineno = p->delayed.end_line;
13456 yylloc->end_pos.column = p->delayed.end_col;
13462rb_parser_set_location_of_heredoc_end(struct parser_params *p, YYLTYPE *yylloc)
13464 int sourceline = p->ruby_sourceline;
13465 int beg_pos = (int)(p->lex.ptok - p->lex.pbeg);
13466 int end_pos = (int)(p->lex.pend - p->lex.pbeg);
13467 return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos);
13471rb_parser_set_location_of_dummy_end(struct parser_params *p, YYLTYPE *yylloc)
13473 yylloc->end_pos = yylloc->beg_pos;
13479rb_parser_set_location_of_none(struct parser_params *p, YYLTYPE *yylloc)
13481 int sourceline = p->ruby_sourceline;
13482 int beg_pos = (int)(p->lex.ptok - p->lex.pbeg);
13483 int end_pos = (int)(p->lex.ptok - p->lex.pbeg);
13484 return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos);
13488rb_parser_set_location(struct parser_params *p, YYLTYPE *yylloc)
13490 int sourceline = p->ruby_sourceline;
13491 int beg_pos = (int)(p->lex.ptok - p->lex.pbeg);
13492 int end_pos = (int)(p->lex.pcur - p->lex.pbeg);
13493 return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos);
13495#endif /* !RIPPER */
13498assignable0(struct parser_params *p, ID id, const char **err)
13500 if (!id) return -1;
13503 *err = "Can't change the value of self";
13506 *err = "Can't assign to nil";
13509 *err = "Can't assign to true";
13511 case keyword_false:
13512 *err = "Can't assign to false";
13514 case keyword__FILE__:
13515 *err = "Can't assign to __FILE__";
13517 case keyword__LINE__:
13518 *err = "Can't assign to __LINE__";
13520 case keyword__ENCODING__:
13521 *err = "Can't assign to __ENCODING__";
13524 switch (id_type(id)) {
13526 if (dyna_in_block(p)) {
13527 if (p->max_numparam > NO_PARAM && NUMPARAM_ID_P(id)) {
13528 compile_error(p, "Can't assign to numbered parameter _%d",
13529 NUMPARAM_ID_TO_IDX(id));
13532 if (dvar_curr(p, id)) return NODE_DASGN;
13533 if (dvar_defined(p, id)) return NODE_DASGN;
13534 if (local_id(p, id)) return NODE_LASGN;
13539 if (!local_id(p, id)) local_var(p, id);
13543 case ID_GLOBAL: return NODE_GASGN;
13544 case ID_INSTANCE: return NODE_IASGN;
13546 if (!p->ctxt.in_def) return NODE_CDECL;
13547 *err = "dynamic constant assignment";
13549 case ID_CLASS: return NODE_CVASGN;
13551 compile_error(p, "identifier %"PRIsVALUE" is not valid to set", rb_id2str(id));
13557assignable(struct parser_params *p, ID id, NODE *val, const YYLTYPE *loc)
13559 const char *err = 0;
13560 int node_type = assignable0(p, id, &err);
13561 switch (node_type) {
13562 case NODE_DASGN: return NEW_DASGN(id, val, loc);
13563 case NODE_LASGN: return NEW_LASGN(id, val, loc);
13564 case NODE_GASGN: return NEW_GASGN(id, val, loc);
13565 case NODE_IASGN: return NEW_IASGN(id, val, loc);
13566 case NODE_CDECL: return NEW_CDECL(id, val, 0, p->ctxt.shareable_constant_value, loc);
13567 case NODE_CVASGN: return NEW_CVASGN(id, val, loc);
13571 if (err) yyerror1(loc, err);
13573 if (err) set_value(assign_error(p, err, p->s_lvalue));
13575 return NEW_ERROR(loc);
13579is_private_local_id(struct parser_params *p, ID name)
13582 if (name == idUScore) return 1;
13583 if (!is_local_id(name)) return 0;
13584 s = rb_id2str(name);
13586 return RSTRING_PTR(s)[0] == '_';
13590shadowing_lvar_0(struct parser_params *p, ID name)
13592 if (dyna_in_block(p)) {
13593 if (dvar_curr(p, name)) {
13594 if (is_private_local_id(p, name)) return 1;
13595 yyerror0("duplicated argument name");
13597 else if (dvar_defined(p, name) || local_id(p, name)) {
13598 vtable_add(p->lvtbl->vars, name);
13599 if (p->lvtbl->used) {
13600 vtable_add(p->lvtbl->used, (ID)p->ruby_sourceline | LVAR_USED);
13606 if (local_id(p, name)) {
13607 if (is_private_local_id(p, name)) return 1;
13608 yyerror0("duplicated argument name");
13615shadowing_lvar(struct parser_params *p, ID name)
13617 shadowing_lvar_0(p, name);
13622new_bv(struct parser_params *p, ID name)
13625 if (!is_local_id(name)) {
13626 compile_error(p, "invalid local variable - %"PRIsVALUE,
13630 if (!shadowing_lvar_0(p, name)) return;
13633 if (dvar_defined_ref(p, name, &vidp)) {
13634 if (vidp) *vidp |= LVAR_USED;
13639aryset_check(struct parser_params *p, NODE *args)
13641 NODE *block = 0, *kwds = 0;
13642 if (args && nd_type_p(args, NODE_BLOCK_PASS)) {
13643 block = RNODE_BLOCK_PASS(args)->nd_body;
13644 args = RNODE_BLOCK_PASS(args)->nd_head;
13646 if (args && nd_type_p(args, NODE_ARGSCAT)) {
13647 args = RNODE_ARGSCAT(args)->nd_body;
13649 if (args && nd_type_p(args, NODE_ARGSPUSH)) {
13650 kwds = RNODE_ARGSPUSH(args)->nd_body;
13653 for (NODE *next = args; next && nd_type_p(next, NODE_LIST);
13654 next = RNODE_LIST(next)->nd_next) {
13655 kwds = RNODE_LIST(next)->nd_head;
13658 if (kwds && nd_type_p(kwds, NODE_HASH) && !RNODE_HASH(kwds)->nd_brace) {
13659 yyerror1(&kwds->nd_loc, "keyword arg given in index assignment");
13662 yyerror1(&block->nd_loc, "block arg given in index assignment");
13667aryset(struct parser_params *p, NODE *recv, NODE *idx, const YYLTYPE *loc)
13669 aryset_check(p, idx);
13670 return NEW_ATTRASGN(recv, tASET, idx, loc);
13674block_dup_check(struct parser_params *p, NODE *node1, NODE *node2)
13676 if (node2 && node1 && nd_type_p(node1, NODE_BLOCK_PASS)) {
13677 compile_error(p, "both block arg and actual block given");
13682attrset(struct parser_params *p, NODE *recv, ID atype, ID id, const YYLTYPE *loc)
13684 if (!CALL_Q_P(atype)) id = rb_id_attrset(id);
13685 return NEW_ATTRASGN(recv, id, 0, loc);
13689rb_backref_error(struct parser_params *p, NODE *node)
13692# define ERR(...) (compile_error(p, __VA_ARGS__), Qtrue)
13694# define ERR(...) rb_sprintf(__VA_ARGS__)
13696 switch (nd_type(node)) {
13698 return ERR("Can't set variable $%ld", RNODE_NTH_REF(node)->nd_nth);
13699 case NODE_BACK_REF:
13700 return ERR("Can't set variable $%c", (int)RNODE_BACK_REF(node)->nd_nth);
13703 UNREACHABLE_RETURN(Qfalse); /* only called on syntax error */
13707arg_append(struct parser_params *p, NODE *node1, NODE *node2, const YYLTYPE *loc)
13709 if (!node1) return NEW_LIST(node2, &node2->nd_loc);
13710 switch (nd_type(node1)) {
13712 return list_append(p, node1, node2);
13713 case NODE_BLOCK_PASS:
13714 RNODE_BLOCK_PASS(node1)->nd_head = arg_append(p, RNODE_BLOCK_PASS(node1)->nd_head, node2, loc);
13715 node1->nd_loc.end_pos = RNODE_BLOCK_PASS(node1)->nd_head->nd_loc.end_pos;
13717 case NODE_ARGSPUSH:
13718 RNODE_ARGSPUSH(node1)->nd_body = list_append(p, NEW_LIST(RNODE_ARGSPUSH(node1)->nd_body, &RNODE_ARGSPUSH(node1)->nd_body->nd_loc), node2);
13719 node1->nd_loc.end_pos = RNODE_ARGSPUSH(node1)->nd_body->nd_loc.end_pos;
13720 nd_set_type(node1, NODE_ARGSCAT);
13723 if (!nd_type_p(RNODE_ARGSCAT(node1)->nd_body, NODE_LIST)) break;
13724 RNODE_ARGSCAT(node1)->nd_body = list_append(p, RNODE_ARGSCAT(node1)->nd_body, node2);
13725 node1->nd_loc.end_pos = RNODE_ARGSCAT(node1)->nd_body->nd_loc.end_pos;
13728 return NEW_ARGSPUSH(node1, node2, loc);
13732arg_concat(struct parser_params *p, NODE *node1, NODE *node2, const YYLTYPE *loc)
13734 if (!node2) return node1;
13735 switch (nd_type(node1)) {
13736 case NODE_BLOCK_PASS:
13737 if (RNODE_BLOCK_PASS(node1)->nd_head)
13738 RNODE_BLOCK_PASS(node1)->nd_head = arg_concat(p, RNODE_BLOCK_PASS(node1)->nd_head, node2, loc);
13740 RNODE_LIST(node1)->nd_head = NEW_LIST(node2, loc);
13742 case NODE_ARGSPUSH:
13743 if (!nd_type_p(node2, NODE_LIST)) break;
13744 RNODE_ARGSPUSH(node1)->nd_body = list_concat(NEW_LIST(RNODE_ARGSPUSH(node1)->nd_body, loc), node2);
13745 nd_set_type(node1, NODE_ARGSCAT);
13748 if (!nd_type_p(node2, NODE_LIST) ||
13749 !nd_type_p(RNODE_ARGSCAT(node1)->nd_body, NODE_LIST)) break;
13750 RNODE_ARGSCAT(node1)->nd_body = list_concat(RNODE_ARGSCAT(node1)->nd_body, node2);
13753 return NEW_ARGSCAT(node1, node2, loc);
13757last_arg_append(struct parser_params *p, NODE *args, NODE *last_arg, const YYLTYPE *loc)
13760 if ((n1 = splat_array(args)) != 0) {
13761 return list_append(p, n1, last_arg);
13763 return arg_append(p, args, last_arg, loc);
13767rest_arg_append(struct parser_params *p, NODE *args, NODE *rest_arg, const YYLTYPE *loc)
13770 if ((nd_type_p(rest_arg, NODE_LIST)) && (n1 = splat_array(args)) != 0) {
13771 return list_concat(n1, rest_arg);
13773 return arg_concat(p, args, rest_arg, loc);
13777splat_array(NODE* node)
13779 if (nd_type_p(node, NODE_SPLAT)) node = RNODE_SPLAT(node)->nd_head;
13780 if (nd_type_p(node, NODE_LIST)) return node;
13785mark_lvar_used(struct parser_params *p, NODE *rhs)
13789 switch (nd_type(rhs)) {
13791 if (local_id_ref(p, RNODE_LASGN(rhs)->nd_vid, &vidp)) {
13792 if (vidp) *vidp |= LVAR_USED;
13796 if (dvar_defined_ref(p, RNODE_DASGN(rhs)->nd_vid, &vidp)) {
13797 if (vidp) *vidp |= LVAR_USED;
13802 for (rhs = rhs->nd_head; rhs; rhs = rhs->nd_next) {
13803 mark_lvar_used(p, rhs->nd_head);
13810static int is_static_content(NODE *node);
13813node_assign(struct parser_params *p, NODE *lhs, NODE *rhs, struct lex_context ctxt, const YYLTYPE *loc)
13815 if (!lhs) return 0;
13817 switch (nd_type(lhs)) {
13825 set_nd_value(p, lhs, rhs);
13826 nd_set_loc(lhs, loc);
13829 case NODE_ATTRASGN:
13830 RNODE_ATTRASGN(lhs)->nd_args = arg_append(p, RNODE_ATTRASGN(lhs)->nd_args, rhs, loc);
13831 nd_set_loc(lhs, loc);
13835 /* should not happen */
13843value_expr_check(struct parser_params *p, NODE *node)
13845 NODE *void_node = 0, *vn;
13848 rb_warning0("empty expression");
13851 switch (nd_type(node)) {
13853 vn = RNODE_ENSURE(node)->nd_head;
13854 node = RNODE_ENSURE(node)->nd_ensr;
13855 /* nd_ensr should not be NULL, check it out next */
13856 if (vn && (vn = value_expr_check(p, vn))) {
13862 /* void only if all children are void */
13863 vn = RNODE_RESCUE(node)->nd_head;
13864 if (!vn || !(vn = value_expr_check(p, vn))) return NULL;
13865 if (!void_node) void_node = vn;
13866 for (NODE *r = RNODE_RESCUE(node)->nd_resq; r; r = RNODE_RESBODY(r)->nd_next) {
13867 if (!nd_type_p(r, NODE_RESBODY)) {
13868 compile_error(p, "unexpected node");
13871 if (!(vn = value_expr_check(p, RNODE_RESBODY(r)->nd_body))) {
13875 if (!void_node) void_node = vn;
13877 node = RNODE_RESCUE(node)->nd_else;
13878 if (!node) return void_node;
13889 if (!RNODE_CASE3(node)->nd_body || !nd_type_p(RNODE_CASE3(node)->nd_body, NODE_IN)) {
13890 compile_error(p, "unexpected node");
13893 if (RNODE_IN(RNODE_CASE3(node)->nd_body)->nd_body) {
13896 /* single line pattern matching with "=>" operator */
13900 while (RNODE_BLOCK(node)->nd_next) {
13901 node = RNODE_BLOCK(node)->nd_next;
13903 node = RNODE_BLOCK(node)->nd_head;
13907 node = RNODE_BEGIN(node)->nd_body;
13912 if (!RNODE_IF(node)->nd_body) {
13915 else if (!RNODE_IF(node)->nd_else) {
13918 vn = value_expr_check(p, RNODE_IF(node)->nd_body);
13919 if (!vn) return NULL;
13920 if (!void_node) void_node = vn;
13921 node = RNODE_IF(node)->nd_else;
13926 node = RNODE_AND(node)->nd_1st;
13932 mark_lvar_used(p, node);
13943 /* return the first found node */
13944 return void_node ? void_node : node;
13948value_expr_gen(struct parser_params *p, NODE *node)
13950 NODE *void_node = value_expr_check(p, node);
13952 yyerror1(&void_node->nd_loc, "void value expression");
13953 /* or "control never reach"? */
13960void_expr(struct parser_params *p, NODE *node)
13962 const char *useless = 0;
13964 if (!RTEST(ruby_verbose)) return;
13966 if (!node || !(node = nd_once_body(node))) return;
13967 switch (nd_type(node)) {
13969 switch (RNODE_OPCALL(node)->nd_mid) {
13988 useless = rb_id2name(RNODE_OPCALL(node)->nd_mid);
13999 case NODE_BACK_REF:
14000 useless = "a variable";
14003 useless = "a constant";
14008 case NODE_ENCODING:
14011 case NODE_RATIONAL:
14012 case NODE_IMAGINARY:
14017 useless = "a literal";
14042 useless = "defined?";
14047 rb_warn1L(nd_line(node), "possibly useless use of %s in void context", WARN_S(useless));
14051/* warns useless use of block and returns the last statement node */
14053void_stmts(struct parser_params *p, NODE *node)
14055 NODE *const n = node;
14056 if (!RTEST(ruby_verbose)) return n;
14057 if (!node) return n;
14058 if (!nd_type_p(node, NODE_BLOCK)) return n;
14060 while (RNODE_BLOCK(node)->nd_next) {
14061 void_expr(p, RNODE_BLOCK(node)->nd_head);
14062 node = RNODE_BLOCK(node)->nd_next;
14064 return RNODE_BLOCK(node)->nd_head;
14068remove_begin(NODE *node)
14070 NODE **n = &node, *n1 = node;
14071 while (n1 && nd_type_p(n1, NODE_BEGIN) && RNODE_BEGIN(n1)->nd_body) {
14072 *n = n1 = RNODE_BEGIN(n1)->nd_body;
14078reduce_nodes(struct parser_params *p, NODE **body)
14080 NODE *node = *body;
14083 *body = NEW_NIL(&NULL_LOC);
14086#define subnodes(type, n1, n2) \
14087 ((!type(node)->n1) ? (type(node)->n2 ? (body = &type(node)->n2, 1) : 0) : \
14088 (!type(node)->n2) ? (body = &type(node)->n1, 1) : \
14089 (reduce_nodes(p, &type(node)->n1), body = &type(node)->n2, 1))
14092 int newline = (int)nd_fl_newline(node);
14093 switch (nd_type(node)) {
14099 *body = node = RNODE_BEGIN(node)->nd_body;
14100 if (newline && node) nd_set_fl_newline(node);
14103 body = &RNODE_BLOCK(RNODE_BLOCK(node)->nd_end)->nd_head;
14107 if (subnodes(RNODE_IF, nd_body, nd_else)) break;
14110 body = &RNODE_CASE(node)->nd_body;
14113 if (!subnodes(RNODE_WHEN, nd_body, nd_next)) goto end;
14116 body = &RNODE_ENSURE(node)->nd_head;
14119 newline = 0; // RESBODY should not be a NEWLINE
14120 if (RNODE_RESCUE(node)->nd_else) {
14121 body = &RNODE_RESCUE(node)->nd_resq;
14124 if (!subnodes(RNODE_RESCUE, nd_head, nd_resq)) goto end;
14130 if (newline && node) nd_set_fl_newline(node);
14137is_static_content(NODE *node)
14139 if (!node) return 1;
14140 switch (nd_type(node)) {
14142 if (!(node = RNODE_HASH(node)->nd_head)) break;
14145 if (!is_static_content(RNODE_LIST(node)->nd_head)) return 0;
14146 } while ((node = RNODE_LIST(node)->nd_next) != 0);
14151 case NODE_ENCODING:
14154 case NODE_RATIONAL:
14155 case NODE_IMAGINARY:
14169assign_in_cond(struct parser_params *p, NODE *node)
14171 switch (nd_type(node)) {
14185 if (!get_nd_value(p, node)) return 1;
14186 if (is_static_content(get_nd_value(p, node))) {
14187 /* reports always */
14188 rb_warn0L(nd_line(get_nd_value(p, node)), "found '= literal' in conditional, should be ==");
14199#define SWITCH_BY_COND_TYPE(t, w, arg) do { \
14201 case COND_IN_OP: break; \
14202 case COND_IN_COND: rb_##w##0(arg "literal in condition"); break; \
14203 case COND_IN_FF: rb_##w##0(arg "literal in flip-flop"); break; \
14207static NODE *cond0(struct parser_params*,NODE*,enum cond_type,const YYLTYPE*,bool);
14210range_op(struct parser_params *p, NODE *node, const YYLTYPE *loc)
14212 enum node_type type;
14214 if (node == 0) return 0;
14216 type = nd_type(node);
14218 if (type == NODE_INTEGER) {
14219 if (!e_option_supplied(p)) rb_warn0L(nd_line(node), "integer literal in flip-flop");
14220 ID lineno = rb_intern("$.");
14221 return NEW_CALL(node, tEQ, NEW_LIST(NEW_GVAR(lineno, loc), loc), loc);
14223 return cond0(p, node, COND_IN_FF, loc, true);
14227cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *loc, bool top)
14229 if (node == 0) return 0;
14230 if (!(node = nd_once_body(node))) return 0;
14231 assign_in_cond(p, node);
14233 switch (nd_type(node)) {
14235 RNODE_BEGIN(node)->nd_body = cond0(p, RNODE_BEGIN(node)->nd_body, type, loc, top);
14242 SWITCH_BY_COND_TYPE(type, warn, "string ");
14246 if (!e_option_supplied(p)) SWITCH_BY_COND_TYPE(type, warn, "regex ");
14247 nd_set_type(node, NODE_MATCH);
14251 if (!e_option_supplied(p)) SWITCH_BY_COND_TYPE(type, warning, "regex ");
14253 return NEW_MATCH2(node, NEW_GVAR(idLASTLINE, loc), loc);
14257 NODE *end = RNODE_BLOCK(node)->nd_end;
14258 NODE **expr = &RNODE_BLOCK(end)->nd_head;
14259 if (top) top = node == end;
14260 *expr = cond0(p, *expr, type, loc, top);
14266 RNODE_AND(node)->nd_1st = cond0(p, RNODE_AND(node)->nd_1st, COND_IN_COND, loc, true);
14267 RNODE_AND(node)->nd_2nd = cond0(p, RNODE_AND(node)->nd_2nd, COND_IN_COND, loc, true);
14273 RNODE_DOT2(node)->nd_beg = range_op(p, RNODE_DOT2(node)->nd_beg, loc);
14274 RNODE_DOT2(node)->nd_end = range_op(p, RNODE_DOT2(node)->nd_end, loc);
14275 switch (nd_type(node)) {
14277 nd_set_type(node,NODE_FLIP2);
14278 rb_node_flip2_t *flip2 = RNODE_FLIP2(node); /* for debug info */
14282 nd_set_type(node, NODE_FLIP3);
14283 rb_node_flip3_t *flip3 = RNODE_FLIP3(node); /* for debug info */
14291 SWITCH_BY_COND_TYPE(type, warning, "symbol ");
14295 SWITCH_BY_COND_TYPE(type, warning, "");
14298 case NODE_ENCODING:
14299 SWITCH_BY_COND_TYPE(type, warning, "");
14304 case NODE_RATIONAL:
14305 case NODE_IMAGINARY:
14306 SWITCH_BY_COND_TYPE(type, warning, "");
14316cond(struct parser_params *p, NODE *node, const YYLTYPE *loc)
14318 if (node == 0) return 0;
14319 return cond0(p, node, COND_IN_COND, loc, true);
14323method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc)
14325 if (node == 0) return 0;
14326 return cond0(p, node, COND_IN_OP, loc, true);
14330new_nil_at(struct parser_params *p, const rb_code_position_t *pos)
14332 YYLTYPE loc = {*pos, *pos};
14333 return NEW_NIL(&loc);
14337new_if(struct parser_params *p, NODE *cc, NODE *left, NODE *right, const YYLTYPE *loc)
14339 if (!cc) return right;
14340 cc = cond0(p, cc, COND_IN_COND, loc, true);
14341 return newline_node(NEW_IF(cc, left, right, loc));
14345new_unless(struct parser_params *p, NODE *cc, NODE *left, NODE *right, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc, const YYLTYPE *end_keyword_loc)
14347 if (!cc) return right;
14348 cc = cond0(p, cc, COND_IN_COND, loc, true);
14349 return newline_node(NEW_UNLESS(cc, left, right, loc, keyword_loc, then_keyword_loc, end_keyword_loc));
14352#define NEW_AND_OR(type, f, s, loc, op_loc) (type == NODE_AND ? NEW_AND(f,s,loc,op_loc) : NEW_OR(f,s,loc,op_loc))
14355logop(struct parser_params *p, ID id, NODE *left, NODE *right,
14356 const YYLTYPE *op_loc, const YYLTYPE *loc)
14358 enum node_type type = id == idAND || id == idANDOP ? NODE_AND : NODE_OR;
14361 if (left && nd_type_p(left, type)) {
14362 NODE *node = left, *second;
14363 while ((second = RNODE_AND(node)->nd_2nd) != 0 && nd_type_p(second, type)) {
14366 RNODE_AND(node)->nd_2nd = NEW_AND_OR(type, second, right, loc, op_loc);
14367 nd_set_line(RNODE_AND(node)->nd_2nd, op_loc->beg_pos.lineno);
14368 left->nd_loc.end_pos = loc->end_pos;
14371 op = NEW_AND_OR(type, left, right, loc, op_loc);
14372 nd_set_line(op, op_loc->beg_pos.lineno);
14379no_blockarg(struct parser_params *p, NODE *node)
14381 if (nd_type_p(node, NODE_BLOCK_PASS)) {
14382 compile_error(p, "block argument should not be given");
14387ret_args(struct parser_params *p, NODE *node)
14390 no_blockarg(p, node);
14391 if (nd_type_p(node, NODE_LIST) && !RNODE_LIST(node)->nd_next) {
14392 node = RNODE_LIST(node)->nd_head;
14399new_yield(struct parser_params *p, NODE *node, const YYLTYPE *loc)
14401 if (node) no_blockarg(p, node);
14403 return NEW_YIELD(node, loc);
14407negate_lit(struct parser_params *p, NODE* node)
14409 switch (nd_type(node)) {
14411 RNODE_INTEGER(node)->minus = TRUE;
14414 RNODE_FLOAT(node)->minus = TRUE;
14416 case NODE_RATIONAL:
14417 RNODE_RATIONAL(node)->minus = TRUE;
14419 case NODE_IMAGINARY:
14420 RNODE_IMAGINARY(node)->minus = TRUE;
14427arg_blk_pass(NODE *node1, rb_node_block_pass_t *node2)
14430 if (!node1) return (NODE *)node2;
14431 node2->nd_head = node1;
14432 nd_set_first_lineno(node2, nd_first_lineno(node1));
14433 nd_set_first_column(node2, nd_first_column(node1));
14434 return (NODE *)node2;
14440args_info_empty_p(struct rb_args_info *args)
14442 if (args->pre_args_num) return false;
14443 if (args->post_args_num) return false;
14444 if (args->rest_arg) return false;
14445 if (args->opt_args) return false;
14446 if (args->block_arg) return false;
14447 if (args->kw_args) return false;
14448 if (args->kw_rest_arg) return false;
14452static rb_node_args_t *
14453new_args(struct parser_params *p, rb_node_args_aux_t *pre_args, rb_node_opt_arg_t *opt_args, ID rest_arg, rb_node_args_aux_t *post_args, rb_node_args_t *tail, const YYLTYPE *loc)
14455 struct rb_args_info *args = &tail->nd_ainfo;
14457 if (args->forwarding) {
14459 yyerror1(&RNODE(tail)->nd_loc, "... after rest argument");
14462 rest_arg = idFWD_REST;
14465 args->pre_args_num = pre_args ? pre_args->nd_plen : 0;
14466 args->pre_init = pre_args ? pre_args->nd_next : 0;
14468 args->post_args_num = post_args ? post_args->nd_plen : 0;
14469 args->post_init = post_args ? post_args->nd_next : 0;
14470 args->first_post_arg = post_args ? post_args->nd_pid : 0;
14472 args->rest_arg = rest_arg;
14474 args->opt_args = opt_args;
14476#ifdef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
14477 args->ruby2_keywords = args->forwarding;
14479 args->ruby2_keywords = 0;
14482 nd_set_loc(RNODE(tail), loc);
14487static rb_node_args_t *
14488new_args_tail(struct parser_params *p, rb_node_kw_arg_t *kw_args, ID kw_rest_arg, ID block, const YYLTYPE *kw_rest_loc)
14490 rb_node_args_t *node = NEW_ARGS(&NULL_LOC);
14491 struct rb_args_info *args = &node->nd_ainfo;
14492 if (p->error_p) return node;
14494 args->block_arg = block;
14495 args->kw_args = kw_args;
14499 * def foo(k1: 1, kr1:, k2: 2, **krest, &b)
14500 * variable order: k1, kr1, k2, &b, internal_id, krest
14502 * variable order: kr1, k1, k2, internal_id, krest, &b
14504 ID kw_bits = internal_id(p), *required_kw_vars, *kw_vars;
14505 struct vtable *vtargs = p->lvtbl->args;
14506 rb_node_kw_arg_t *kwn = kw_args;
14508 if (block) block = vtargs->tbl[vtargs->pos-1];
14509 vtable_pop(vtargs, !!block + !!kw_rest_arg);
14510 required_kw_vars = kw_vars = &vtargs->tbl[vtargs->pos];
14512 if (!NODE_REQUIRED_KEYWORD_P(get_nd_value(p, kwn->nd_body)))
14514 --required_kw_vars;
14515 kwn = kwn->nd_next;
14518 for (kwn = kw_args; kwn; kwn = kwn->nd_next) {
14519 ID vid = get_nd_vid(p, kwn->nd_body);
14520 if (NODE_REQUIRED_KEYWORD_P(get_nd_value(p, kwn->nd_body))) {
14521 *required_kw_vars++ = vid;
14528 arg_var(p, kw_bits);
14529 if (kw_rest_arg) arg_var(p, kw_rest_arg);
14530 if (block) arg_var(p, block);
14532 args->kw_rest_arg = NEW_DVAR(kw_rest_arg, kw_rest_loc);
14534 else if (kw_rest_arg == idNil) {
14535 args->no_kwarg = 1;
14537 else if (kw_rest_arg) {
14538 args->kw_rest_arg = NEW_DVAR(kw_rest_arg, kw_rest_loc);
14544static rb_node_args_t *
14545args_with_numbered(struct parser_params *p, rb_node_args_t *args, int max_numparam, ID it_id)
14547 if (max_numparam > NO_PARAM || it_id) {
14549 YYLTYPE loc = RUBY_INIT_YYLLOC();
14550 args = new_args_tail(p, 0, 0, 0, 0);
14551 nd_set_loc(RNODE(args), &loc);
14553 args->nd_ainfo.pre_args_num = it_id ? 1 : max_numparam;
14559new_array_pattern(struct parser_params *p, NODE *constant, NODE *pre_arg, NODE *aryptn, const YYLTYPE *loc)
14561 RNODE_ARYPTN(aryptn)->nd_pconst = constant;
14564 NODE *pre_args = NEW_LIST(pre_arg, loc);
14565 if (RNODE_ARYPTN(aryptn)->pre_args) {
14566 RNODE_ARYPTN(aryptn)->pre_args = list_concat(pre_args, RNODE_ARYPTN(aryptn)->pre_args);
14569 RNODE_ARYPTN(aryptn)->pre_args = pre_args;
14576new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, NODE *rest_arg, NODE *post_args, const YYLTYPE *loc)
14579 rest_arg = rest_arg ? rest_arg : NODE_SPECIAL_NO_NAME_REST;
14584 NODE *node = NEW_ARYPTN(pre_args, rest_arg, post_args, loc);
14590new_find_pattern(struct parser_params *p, NODE *constant, NODE *fndptn, const YYLTYPE *loc)
14592 RNODE_FNDPTN(fndptn)->nd_pconst = constant;
14598new_find_pattern_tail(struct parser_params *p, NODE *pre_rest_arg, NODE *args, NODE *post_rest_arg, const YYLTYPE *loc)
14600 pre_rest_arg = pre_rest_arg ? pre_rest_arg : NODE_SPECIAL_NO_NAME_REST;
14601 post_rest_arg = post_rest_arg ? post_rest_arg : NODE_SPECIAL_NO_NAME_REST;
14602 NODE *node = NEW_FNDPTN(pre_rest_arg, args, post_rest_arg, loc);
14608new_hash_pattern(struct parser_params *p, NODE *constant, NODE *hshptn, const YYLTYPE *loc)
14610 RNODE_HSHPTN(hshptn)->nd_pconst = constant;
14615new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc)
14617 NODE *node, *kw_rest_arg_node;
14619 if (kw_rest_arg == idNil) {
14620 kw_rest_arg_node = NODE_SPECIAL_NO_REST_KEYWORD;
14622 else if (kw_rest_arg) {
14623 kw_rest_arg_node = assignable(p, kw_rest_arg, 0, loc);
14626 kw_rest_arg_node = NULL;
14629 node = NEW_HSHPTN(0, kw_args, kw_rest_arg_node, loc);
14635dsym_node(struct parser_params *p, NODE *node, const YYLTYPE *loc)
14638 return NEW_SYM(STR_NEW0(), loc);
14641 switch (nd_type(node)) {
14643 nd_set_type(node, NODE_DSYM);
14644 nd_set_loc(node, loc);
14647 node = str_to_sym_node(p, node, loc);
14650 node = NEW_DSYM(0, 1, NEW_LIST(node, loc), loc);
14657nd_type_st_key_enable_p(NODE *node)
14659 switch (nd_type(node)) {
14662 case NODE_RATIONAL:
14663 case NODE_IMAGINARY:
14669 case NODE_ENCODING:
14677nd_value(struct parser_params *p, NODE *node)
14679 switch (nd_type(node)) {
14681 return rb_node_str_string_val(node);
14683 return rb_node_integer_literal_val(node);
14685 return rb_node_float_literal_val(node);
14686 case NODE_RATIONAL:
14687 return rb_node_rational_literal_val(node);
14688 case NODE_IMAGINARY:
14689 return rb_node_imaginary_literal_val(node);
14691 return rb_node_sym_string_val(node);
14693 return rb_node_regx_string_val(node);
14695 return rb_node_line_lineno_val(node);
14696 case NODE_ENCODING:
14697 return rb_node_encoding_val(node);
14699 return rb_node_file_path_val(node);
14701 rb_bug("unexpected node: %s", ruby_node_name(nd_type(node)));
14702 UNREACHABLE_RETURN(0);
14707warn_duplicate_keys(struct parser_params *p, NODE *hash)
14709 /* See https://bugs.ruby-lang.org/issues/20331 for discussion about what is warned. */
14710 p->warn_duplicate_keys_table = st_init_table_with_size(&literal_type, RNODE_LIST(hash)->as.nd_alen / 2);
14711 while (hash && RNODE_LIST(hash)->nd_next) {
14712 NODE *head = RNODE_LIST(hash)->nd_head;
14713 NODE *value = RNODE_LIST(hash)->nd_next;
14714 NODE *next = RNODE_LIST(value)->nd_next;
14718 /* keyword splat, e.g. {k: 1, **z, k: 2} */
14723 if (nd_type_st_key_enable_p(head)) {
14724 key = (st_data_t)head;
14726 if (st_delete(p->warn_duplicate_keys_table, &key, &data)) {
14727 rb_warn2L(nd_line((NODE *)data),
14728 "key %+"PRIsWARN" is duplicated and overwritten on line %d",
14729 nd_value(p, head), WARN_I(nd_line(head)));
14731 st_insert(p->warn_duplicate_keys_table, (st_data_t)key, (st_data_t)hash);
14735 st_free_table(p->warn_duplicate_keys_table);
14736 p->warn_duplicate_keys_table = NULL;
14740new_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc)
14742 if (hash) warn_duplicate_keys(p, hash);
14743 return NEW_HASH(hash, loc);
14747error_duplicate_pattern_variable(struct parser_params *p, ID id, const YYLTYPE *loc)
14749 if (is_private_local_id(p, id)) {
14752 if (st_is_member(p->pvtbl, id)) {
14753 yyerror1(loc, "duplicated variable name");
14756 st_insert(p->pvtbl, (st_data_t)id, 0);
14761error_duplicate_pattern_key(struct parser_params *p, VALUE key, const YYLTYPE *loc)
14764 p->pktbl = st_init_numtable();
14766 else if (st_is_member(p->pktbl, key)) {
14767 yyerror1(loc, "duplicated key name");
14770 st_insert(p->pktbl, (st_data_t)key, 0);
14774new_unique_key_hash(struct parser_params *p, NODE *hash, const YYLTYPE *loc)
14776 return NEW_HASH(hash, loc);
14780new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context ctxt, const YYLTYPE *loc)
14785 ID vid = get_nd_vid(p, lhs);
14786 YYLTYPE lhs_loc = lhs->nd_loc;
14788 set_nd_value(p, lhs, rhs);
14789 nd_set_loc(lhs, loc);
14790 asgn = NEW_OP_ASGN_OR(gettable(p, vid, &lhs_loc), lhs, loc);
14792 else if (op == tANDOP) {
14793 set_nd_value(p, lhs, rhs);
14794 nd_set_loc(lhs, loc);
14795 asgn = NEW_OP_ASGN_AND(gettable(p, vid, &lhs_loc), lhs, loc);
14799 rhs = NEW_CALL(gettable(p, vid, &lhs_loc), op, NEW_LIST(rhs, &rhs->nd_loc), loc);
14800 set_nd_value(p, asgn, rhs);
14801 nd_set_loc(asgn, loc);
14805 asgn = NEW_ERROR(loc);
14811new_ary_op_assign(struct parser_params *p, NODE *ary,
14812 NODE *args, ID op, NODE *rhs, const YYLTYPE *args_loc, const YYLTYPE *loc,
14813 const YYLTYPE *call_operator_loc, const YYLTYPE *opening_loc, const YYLTYPE *closing_loc, const YYLTYPE *binary_operator_loc)
14817 aryset_check(p, args);
14818 args = make_list(args, args_loc);
14819 asgn = NEW_OP_ASGN1(ary, op, args, rhs, loc, call_operator_loc, opening_loc, closing_loc, binary_operator_loc);
14825new_attr_op_assign(struct parser_params *p, NODE *lhs,
14826 ID atype, ID attr, ID op, NODE *rhs, const YYLTYPE *loc,
14827 const YYLTYPE *call_operator_loc, const YYLTYPE *message_loc, const YYLTYPE *binary_operator_loc)
14831 asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, loc, call_operator_loc, message_loc, binary_operator_loc);
14837new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context ctxt, const YYLTYPE *loc)
14842 asgn = NEW_OP_CDECL(lhs, op, rhs, ctxt.shareable_constant_value, loc);
14845 asgn = NEW_ERROR(loc);
14852const_decl(struct parser_params *p, NODE *path, const YYLTYPE *loc)
14854 if (p->ctxt.in_def) {
14856 yyerror1(loc, "dynamic constant assignment");
14858 set_value(assign_error(p, "dynamic constant assignment", p->s_lvalue));
14861 return NEW_CDECL(0, 0, (path), p->ctxt.shareable_constant_value, loc);
14866assign_error(struct parser_params *p, const char *mesg, VALUE a)
14868 a = dispatch2(assign_error, ERR_MESG(), a);
14875new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_else, NODE *ensure, const YYLTYPE *loc)
14877 NODE *result = head;
14879 NODE *tmp = rescue_else ? rescue_else : rescue;
14880 YYLTYPE rescue_loc = code_loc_gen(&head->nd_loc, &tmp->nd_loc);
14882 result = NEW_RESCUE(head, rescue, rescue_else, &rescue_loc);
14883 nd_set_line(result, rescue->nd_loc.beg_pos.lineno);
14886 result = NEW_ENSURE(result, ensure, loc);
14888 fixpos(result, head);
14893warn_unused_var(struct parser_params *p, struct local_vars *local)
14897 if (!local->used) return;
14898 cnt = local->used->pos;
14899 if (cnt != local->vars->pos) {
14900 rb_parser_fatal(p, "local->used->pos != local->vars->pos");
14903 ID *v = local->vars->tbl;
14904 ID *u = local->used->tbl;
14905 for (int i = 0; i < cnt; ++i) {
14906 if (!v[i] || (u[i] & LVAR_USED)) continue;
14907 if (is_private_local_id(p, v[i])) continue;
14908 rb_warn1L((int)u[i], "assigned but unused variable - %"PRIsWARN, rb_id2str(v[i]));
14914local_push(struct parser_params *p, int toplevel_scope)
14916 struct local_vars *local;
14917 int inherits_dvars = toplevel_scope && compile_for_eval;
14918 int warn_unused_vars = RTEST(ruby_verbose);
14920 local = ALLOC(struct local_vars);
14921 local->prev = p->lvtbl;
14922 local->args = vtable_alloc(0);
14923 local->vars = vtable_alloc(inherits_dvars ? DVARS_INHERIT : DVARS_TOPSCOPE);
14925 if (toplevel_scope && compile_for_eval) warn_unused_vars = 0;
14926 if (toplevel_scope && e_option_supplied(p)) warn_unused_vars = 0;
14928 local->numparam.outer = 0;
14929 local->numparam.inner = 0;
14930 local->numparam.current = 0;
14932 local->used = warn_unused_vars ? vtable_alloc(0) : 0;
14934# if WARN_PAST_SCOPE
14943vtable_chain_free(struct parser_params *p, struct vtable *table)
14945 while (!DVARS_TERMINAL_P(table)) {
14946 struct vtable *cur_table = table;
14947 table = cur_table->prev;
14948 vtable_free(cur_table);
14953local_free(struct parser_params *p, struct local_vars *local)
14955 vtable_chain_free(p, local->used);
14957# if WARN_PAST_SCOPE
14958 vtable_chain_free(p, local->past);
14961 vtable_chain_free(p, local->args);
14962 vtable_chain_free(p, local->vars);
14964 ruby_sized_xfree(local, sizeof(struct local_vars));
14968local_pop(struct parser_params *p)
14970 struct local_vars *local = p->lvtbl->prev;
14971 if (p->lvtbl->used) {
14972 warn_unused_var(p, p->lvtbl);
14975 local_free(p, p->lvtbl);
14982static rb_ast_id_table_t *
14983local_tbl(struct parser_params *p)
14985 int cnt_args = vtable_size(p->lvtbl->args);
14986 int cnt_vars = vtable_size(p->lvtbl->vars);
14987 int cnt = cnt_args + cnt_vars;
14989 rb_ast_id_table_t *tbl;
14991 if (cnt <= 0) return 0;
14992 tbl = rb_ast_new_local_table(p->ast, cnt);
14993 MEMCPY(tbl->ids, p->lvtbl->args->tbl, ID, cnt_args);
14994 /* remove IDs duplicated to warn shadowing */
14995 for (i = 0, j = cnt_args; i < cnt_vars; ++i) {
14996 ID id = p->lvtbl->vars->tbl[i];
14997 if (!vtable_included(p->lvtbl->args, id)) {
14998 tbl->ids[j++] = id;
15002 tbl = rb_ast_resize_latest_local_table(p->ast, j);
15009numparam_name(struct parser_params *p, ID id)
15011 if (!NUMPARAM_ID_P(id)) return;
15012 compile_error(p, "_%d is reserved for numbered parameter",
15013 NUMPARAM_ID_TO_IDX(id));
15017arg_var(struct parser_params *p, ID id)
15019 numparam_name(p, id);
15020 vtable_add(p->lvtbl->args, id);
15024local_var(struct parser_params *p, ID id)
15026 numparam_name(p, id);
15027 vtable_add(p->lvtbl->vars, id);
15028 if (p->lvtbl->used) {
15029 vtable_add(p->lvtbl->used, (ID)p->ruby_sourceline);
15035rb_parser_local_defined(struct parser_params *p, ID id, const struct rb_iseq_struct *iseq)
15037 return rb_local_defined(id, iseq);
15042local_id_ref(struct parser_params *p, ID id, ID **vidrefp)
15044 struct vtable *vars, *args, *used;
15046 vars = p->lvtbl->vars;
15047 args = p->lvtbl->args;
15048 used = p->lvtbl->used;
15050 while (vars && !DVARS_TERMINAL_P(vars->prev)) {
15053 if (used) used = used->prev;
15056 if (vars && vars->prev == DVARS_INHERIT) {
15057 return rb_parser_local_defined(p, id, p->parent_iseq);
15059 else if (vtable_included(args, id)) {
15063 int i = vtable_included(vars, id);
15064 if (i && used && vidrefp) *vidrefp = &used->tbl[i-1];
15070local_id(struct parser_params *p, ID id)
15072 return local_id_ref(p, id, NULL);
15076check_forwarding_args(struct parser_params *p)
15078 if (local_id(p, idFWD_ALL)) return TRUE;
15079 compile_error(p, "unexpected ...");
15084add_forwarding_args(struct parser_params *p)
15086 arg_var(p, idFWD_REST);
15087#ifndef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
15088 arg_var(p, idFWD_KWREST);
15090 arg_var(p, idFWD_BLOCK);
15091 arg_var(p, idFWD_ALL);
15095forwarding_arg_check(struct parser_params *p, ID arg, ID all, const char *var)
15097 bool conflict = false;
15099 struct vtable *vars, *args;
15101 vars = p->lvtbl->vars;
15102 args = p->lvtbl->args;
15104 while (vars && !DVARS_TERMINAL_P(vars->prev)) {
15105 conflict |= (vtable_included(args, arg) && !(all && vtable_included(args, all)));
15110 bool found = false;
15111 if (vars && vars->prev == DVARS_INHERIT && !found) {
15112 found = (rb_parser_local_defined(p, arg, p->parent_iseq) &&
15113 !(all && rb_parser_local_defined(p, all, p->parent_iseq)));
15116 found = (vtable_included(args, arg) &&
15117 !(all && vtable_included(args, all)));
15121 compile_error(p, "no anonymous %s parameter", var);
15123 else if (conflict) {
15124 compile_error(p, "anonymous %s parameter is also used within block", var);
15129new_args_forward_call(struct parser_params *p, NODE *leading, const YYLTYPE *loc, const YYLTYPE *argsloc)
15131 NODE *rest = NEW_LVAR(idFWD_REST, loc);
15132#ifndef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
15133 NODE *kwrest = list_append(p, NEW_LIST(0, loc), NEW_LVAR(idFWD_KWREST, loc));
15135 rb_node_block_pass_t *block = NEW_BLOCK_PASS(NEW_LVAR(idFWD_BLOCK, loc), argsloc, &NULL_LOC);
15136 NODE *args = leading ? rest_arg_append(p, leading, rest, argsloc) : NEW_SPLAT(rest, loc, &NULL_LOC);
15137 block->forwarding = TRUE;
15138#ifndef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
15139 args = arg_append(p, args, new_hash(p, kwrest, loc), argsloc);
15141 return arg_blk_pass(args, block);
15145numparam_push(struct parser_params *p)
15147 struct local_vars *local = p->lvtbl;
15148 NODE *inner = local->numparam.inner;
15149 if (!local->numparam.outer) {
15150 local->numparam.outer = local->numparam.current;
15152 local->numparam.inner = 0;
15153 local->numparam.current = 0;
15159numparam_pop(struct parser_params *p, NODE *prev_inner)
15161 struct local_vars *local = p->lvtbl;
15163 /* prefer first one */
15164 local->numparam.inner = prev_inner;
15166 else if (local->numparam.current) {
15167 /* current and inner are exclusive */
15168 local->numparam.inner = local->numparam.current;
15170 if (p->max_numparam > NO_PARAM) {
15171 /* current and outer are exclusive */
15172 local->numparam.current = local->numparam.outer;
15173 local->numparam.outer = 0;
15176 /* no numbered parameter */
15177 local->numparam.current = 0;
15182static const struct vtable *
15183dyna_push(struct parser_params *p)
15185 p->lvtbl->args = vtable_alloc(p->lvtbl->args);
15186 p->lvtbl->vars = vtable_alloc(p->lvtbl->vars);
15187 if (p->lvtbl->used) {
15188 p->lvtbl->used = vtable_alloc(p->lvtbl->used);
15190 return p->lvtbl->args;
15194dyna_pop_vtable(struct parser_params *p, struct vtable **vtblp)
15196 struct vtable *tmp = *vtblp;
15197 *vtblp = tmp->prev;
15198# if WARN_PAST_SCOPE
15199 if (p->past_scope_enabled) {
15200 tmp->prev = p->lvtbl->past;
15201 p->lvtbl->past = tmp;
15209dyna_pop_1(struct parser_params *p)
15211 struct vtable *tmp;
15213 if ((tmp = p->lvtbl->used) != 0) {
15214 warn_unused_var(p, p->lvtbl);
15215 p->lvtbl->used = p->lvtbl->used->prev;
15218 dyna_pop_vtable(p, &p->lvtbl->args);
15219 dyna_pop_vtable(p, &p->lvtbl->vars);
15223dyna_pop(struct parser_params *p, const struct vtable *lvargs)
15225 while (p->lvtbl->args != lvargs) {
15227 if (!p->lvtbl->args) {
15228 struct local_vars *local = p->lvtbl->prev;
15229 ruby_sized_xfree(p->lvtbl, sizeof(*p->lvtbl));
15237dyna_in_block(struct parser_params *p)
15239 return !DVARS_TERMINAL_P(p->lvtbl->vars) && p->lvtbl->vars->prev != DVARS_TOPSCOPE;
15244dvar_defined_ref(struct parser_params *p, ID id, ID **vidrefp)
15246 struct vtable *vars, *args, *used;
15249 args = p->lvtbl->args;
15250 vars = p->lvtbl->vars;
15251 used = p->lvtbl->used;
15253 while (!DVARS_TERMINAL_P(vars)) {
15254 if (vtable_included(args, id)) {
15257 if ((i = vtable_included(vars, id)) != 0) {
15258 if (used && vidrefp) *vidrefp = &used->tbl[i-1];
15263 if (!vidrefp) used = 0;
15264 if (used) used = used->prev;
15267 if (vars == DVARS_INHERIT && !NUMPARAM_ID_P(id)) {
15268 return rb_dvar_defined(id, p->parent_iseq);
15276dvar_defined(struct parser_params *p, ID id)
15278 return dvar_defined_ref(p, id, NULL);
15282dvar_curr(struct parser_params *p, ID id)
15284 return (vtable_included(p->lvtbl->args, id) ||
15285 vtable_included(p->lvtbl->vars, id));
15289reg_fragment_enc_error(struct parser_params* p, rb_parser_string_t *str, int c)
15292 "regexp encoding option '%c' differs from source encoding '%s'",
15293 c, rb_enc_name(rb_parser_str_get_encoding(str)));
15297static rb_encoding *
15298find_enc(struct parser_params* p, const char *name)
15300 int idx = rb_enc_find_index(name);
15302 rb_bug("unknown encoding name: %s", name);
15305 return rb_enc_from_index(idx);
15308static rb_encoding *
15309kcode_to_enc(struct parser_params* p, int kcode)
15314 case ENC_ASCII8BIT:
15315 enc = rb_ascii8bit_encoding();
15318 enc = find_enc(p, "EUC-JP");
15320 case ENC_Windows_31J:
15321 enc = find_enc(p, "Windows-31J");
15324 enc = rb_utf8_encoding();
15335rb_reg_fragment_setenc(struct parser_params* p, rb_parser_string_t *str, int options)
15337 int c = RE_OPTION_ENCODING_IDX(options);
15343 char_to_option_kcode(c, &opt, &idx);
15344 enc = kcode_to_enc(p, idx);
15345 if (enc != rb_parser_str_get_encoding(str) &&
15346 !rb_parser_is_ascii_string(p, str)) {
15349 rb_parser_string_set_encoding(str, enc);
15351 else if (RE_OPTION_ENCODING_NONE(options)) {
15352 if (!PARSER_ENCODING_IS_ASCII8BIT(p, str) &&
15353 !rb_parser_is_ascii_string(p, str)) {
15357 rb_parser_enc_associate(p, str, rb_ascii8bit_encoding());
15359 else if (rb_is_usascii_enc(p->enc)) {
15360 if (!rb_parser_is_ascii_string(p, str)) {
15361 /* raise in re.c */
15362 rb_parser_enc_associate(p, str, rb_usascii_encoding());
15365 rb_parser_enc_associate(p, str, rb_ascii8bit_encoding());
15376reg_fragment_setenc(struct parser_params* p, rb_parser_string_t *str, int options)
15378 int c = rb_reg_fragment_setenc(p, str, options);
15379 if (c) reg_fragment_enc_error(p, str, c);
15383reg_fragment_error(struct parser_params* p, VALUE err)
15385 compile_error(p, "%"PRIsVALUE, err);
15390rb_parser_reg_fragment_check(struct parser_params* p, rb_parser_string_t *str, int options, rb_parser_reg_fragment_error_func error)
15393 reg_fragment_setenc(p, str, options);
15395 str2 = rb_str_new_parser_string(str);
15396 err = rb_reg_check_preprocess(str2);
15398 err = rb_obj_as_string(err);
15406#ifndef UNIVERSAL_PARSER
15408 struct parser_params* parser;
15411 const YYLTYPE *loc;
15412 rb_parser_assignable_func assignable;
15413} reg_named_capture_assign_t;
15416reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
15417 int back_num, int *back_refs, OnigRegex regex, void *arg0)
15419 reg_named_capture_assign_t *arg = (reg_named_capture_assign_t*)arg0;
15420 struct parser_params* p = arg->parser;
15421 rb_encoding *enc = arg->enc;
15422 long len = name_end - name;
15423 const char *s = (const char *)name;
15425 return rb_reg_named_capture_assign_iter_impl(p, s, len, enc, &arg->succ_block, arg->loc, arg->assignable);
15429reg_named_capture_assign(struct parser_params* p, VALUE regexp, const YYLTYPE *loc, rb_parser_assignable_func assignable)
15431 reg_named_capture_assign_t arg;
15434 arg.enc = rb_enc_get(regexp);
15435 arg.succ_block = 0;
15437 arg.assignable = assignable;
15438 onig_foreach_name(RREGEXP_PTR(regexp), reg_named_capture_assign_iter, &arg);
15440 if (!arg.succ_block) return 0;
15441 return RNODE_BLOCK(arg.succ_block)->nd_next;
15447rb_parser_assignable(struct parser_params *p, ID id, NODE *val, const YYLTYPE *loc)
15449 return assignable(p, id, val, loc);
15453rb_reg_named_capture_assign_iter_impl(struct parser_params *p, const char *s, long len,
15454 rb_encoding *enc, NODE **succ_block, const rb_code_location_t *loc, rb_parser_assignable_func assignable)
15459 if (!len) return ST_CONTINUE;
15460 if (!VALID_SYMNAME_P(s, len, enc, ID_LOCAL))
15461 return ST_CONTINUE;
15463 var = intern_cstr(s, len, enc);
15464 if (len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len)) {
15465 if (!lvar_defined(p, var)) return ST_CONTINUE;
15467 node = node_assign(p, assignable(p, var, 0, loc), NEW_SYM(rb_id2str(var), loc), NO_LEX_CTXT, loc);
15468 succ = *succ_block;
15469 if (!succ) succ = NEW_ERROR(loc);
15470 succ = block_append(p, succ, node);
15471 *succ_block = succ;
15472 return ST_CONTINUE;
15477parser_reg_compile(struct parser_params* p, rb_parser_string_t *str, int options)
15480 reg_fragment_setenc(p, str, options);
15481 str2 = rb_str_new_parser_string(str);
15482 return rb_parser_reg_compile(p, str2, options);
15487rb_parser_reg_compile(struct parser_params* p, VALUE str, int options)
15489 return rb_reg_compile(str, options & RE_OPTION_MASK, p->ruby_sourcefile, p->ruby_sourceline);
15494reg_compile(struct parser_params* p, rb_parser_string_t *str, int options)
15499 err = rb_errinfo();
15500 re = parser_reg_compile(p, str, options);
15502 VALUE m = rb_attr_get(rb_errinfo(), idMesg);
15503 rb_set_errinfo(err);
15504 reg_fragment_error(p, m);
15512rb_ruby_parser_set_options(struct parser_params *p, int print, int loop, int chomp, int split)
15514 p->do_print = print;
15516 p->do_chomp = chomp;
15517 p->do_split = split;
15521parser_append_options(struct parser_params *p, NODE *node)
15523 static const YYLTYPE default_location = {{1, 0}, {1, 0}};
15524 const YYLTYPE *const LOC = &default_location;
15527 NODE *print = (NODE *)NEW_FCALL(rb_intern("print"),
15528 NEW_LIST(NEW_GVAR(idLASTLINE, LOC), LOC),
15530 node = block_append(p, node, print);
15534 NODE *irs = NEW_LIST(NEW_GVAR(rb_intern("$/"), LOC), LOC);
15537 ID ifs = rb_intern("$;");
15538 ID fields = rb_intern("$F");
15539 NODE *args = NEW_LIST(NEW_GVAR(ifs, LOC), LOC);
15540 NODE *split = NEW_GASGN(fields,
15541 NEW_CALL(NEW_GVAR(idLASTLINE, LOC),
15542 rb_intern("split"), args, LOC),
15544 node = block_append(p, split, node);
15547 NODE *chomp = NEW_SYM(rb_str_new_cstr("chomp"), LOC);
15548 chomp = list_append(p, NEW_LIST(chomp, LOC), NEW_TRUE(LOC));
15549 irs = list_append(p, irs, NEW_HASH(chomp, LOC));
15552 node = NEW_WHILE((NODE *)NEW_FCALL(idGets, irs, LOC), node, 1, LOC, &NULL_LOC, &NULL_LOC);
15561 /* just to suppress unused-function warnings */
15567internal_id(struct parser_params *p)
15569 return rb_make_temporary_id(vtable_size(p->lvtbl->args) + vtable_size(p->lvtbl->vars));
15571#endif /* !RIPPER */
15574parser_initialize(struct parser_params *p)
15576 /* note: we rely on TypedData_Make_Struct to set most fields to 0 */
15577 p->command_start = TRUE;
15578 p->ruby_sourcefile_string = Qnil;
15579 p->lex.lpar_beg = -1; /* make lambda_beginning_p() == FALSE at first */
15580 string_buffer_init(p);
15582 p->delayed.token = NULL;
15583 p->frozen_string_literal = -1; /* not specified */
15585 p->error_buffer = Qfalse;
15586 p->end_expect_token_locations = NULL;
15591 p->parsing_thread = Qnil;
15593 p->s_lvalue = Qnil;
15594 p->s_value_stack = rb_ary_new();
15596 p->debug_buffer = Qnil;
15597 p->debug_output = rb_ractor_stdout();
15598 p->enc = rb_utf8_encoding();
15603#define rb_ruby_parser_mark ripper_parser_mark
15604#define rb_ruby_parser_free ripper_parser_free
15605#define rb_ruby_parser_memsize ripper_parser_memsize
15609rb_ruby_parser_mark(void *ptr)
15611 struct parser_params *p = (struct parser_params*)ptr;
15613 rb_gc_mark(p->ruby_sourcefile_string);
15615 rb_gc_mark(p->error_buffer);
15617 rb_gc_mark(p->value);
15618 rb_gc_mark(p->result);
15619 rb_gc_mark(p->parsing_thread);
15620 rb_gc_mark(p->s_value);
15621 rb_gc_mark(p->s_lvalue);
15622 rb_gc_mark(p->s_value_stack);
15624 rb_gc_mark(p->debug_buffer);
15625 rb_gc_mark(p->debug_output);
15629rb_ruby_parser_free(void *ptr)
15631 struct parser_params *p = (struct parser_params*)ptr;
15632 struct local_vars *local, *prev;
15635 rb_ast_free(p->ast);
15638 if (p->warn_duplicate_keys_table) {
15639 st_free_table(p->warn_duplicate_keys_table);
15644 rb_parser_ary_free(p, p->tokens);
15649 ruby_sized_xfree(p->tokenbuf, p->toksiz);
15652 for (local = p->lvtbl; local; local = prev) {
15653 prev = local->prev;
15654 local_free(p, local);
15658 token_info *ptinfo;
15659 while ((ptinfo = p->token_info) != 0) {
15660 p->token_info = ptinfo->next;
15664 string_buffer_free(p);
15667 st_free_table(p->pvtbl);
15670 if (CASE_LABELS_ENABLED_P(p->case_labels)) {
15671 st_free_table(p->case_labels);
15674 xfree(p->lex.strterm);
15675 p->lex.strterm = 0;
15681rb_ruby_parser_memsize(const void *ptr)
15683 struct parser_params *p = (struct parser_params*)ptr;
15684 struct local_vars *local;
15685 size_t size = sizeof(*p);
15688 for (local = p->lvtbl; local; local = local->prev) {
15689 size += sizeof(*local);
15690 if (local->vars) size += local->vars->capa * sizeof(ID);
15696#undef rb_reserved_word
15698const struct kwtable *
15699rb_reserved_word(const char *str, unsigned int len)
15701 return reserved_word(str, len);
15704#ifdef UNIVERSAL_PARSER
15706rb_ruby_parser_allocate(const rb_parser_config_t *config)
15708 /* parser_initialize expects fields to be set to 0 */
15709 rb_parser_t *p = (rb_parser_t *)config->calloc(1, sizeof(rb_parser_t));
15710 p->config = config;
15715rb_ruby_parser_new(const rb_parser_config_t *config)
15717 /* parser_initialize expects fields to be set to 0 */
15718 rb_parser_t *p = rb_ruby_parser_allocate(config);
15719 parser_initialize(p);
15724rb_ruby_parser_allocate(void)
15726 /* parser_initialize expects fields to be set to 0 */
15727 rb_parser_t *p = (rb_parser_t *)ruby_xcalloc(1, sizeof(rb_parser_t));
15732rb_ruby_parser_new(void)
15734 /* parser_initialize expects fields to be set to 0 */
15735 rb_parser_t *p = rb_ruby_parser_allocate();
15736 parser_initialize(p);
15742rb_ruby_parser_set_context(rb_parser_t *p, const struct rb_iseq_struct *base, int main)
15744 p->error_buffer = main ? Qfalse : Qnil;
15745 p->parent_iseq = base;
15750rb_ruby_parser_set_script_lines(rb_parser_t *p)
15752 p->debug_lines = rb_parser_ary_new_capa_for_script_line(p, 10);
15756rb_ruby_parser_error_tolerant(rb_parser_t *p)
15758 p->error_tolerant = 1;
15762rb_ruby_parser_keep_tokens(rb_parser_t *p)
15764 p->keep_tokens = 1;
15765 p->tokens = rb_parser_ary_new_capa_for_ast_token(p, 10);
15769rb_ruby_parser_encoding(rb_parser_t *p)
15775rb_ruby_parser_end_seen_p(rb_parser_t *p)
15777 return p->ruby__end__seen;
15781rb_ruby_parser_set_yydebug(rb_parser_t *p, int flag)
15786#endif /* !RIPPER */
15790rb_ruby_parser_get_yydebug(rb_parser_t *p)
15796rb_ruby_parser_set_value(rb_parser_t *p, VALUE value)
15802rb_ruby_parser_error_p(rb_parser_t *p)
15808rb_ruby_parser_debug_output(rb_parser_t *p)
15810 return p->debug_output;
15814rb_ruby_parser_set_debug_output(rb_parser_t *p, VALUE output)
15816 p->debug_output = output;
15820rb_ruby_parser_parsing_thread(rb_parser_t *p)
15822 return p->parsing_thread;
15826rb_ruby_parser_set_parsing_thread(rb_parser_t *p, VALUE parsing_thread)
15828 p->parsing_thread = parsing_thread;
15832rb_ruby_parser_ripper_initialize(rb_parser_t *p, rb_parser_lex_gets_func *gets, rb_parser_input_data input, VALUE sourcefile_string, const char *sourcefile, int sourceline)
15834 p->lex.gets = gets;
15835 p->lex.input = input;
15837 p->ruby_sourcefile_string = sourcefile_string;
15838 p->ruby_sourcefile = sourcefile;
15839 p->ruby_sourceline = sourceline;
15843rb_ruby_parser_result(rb_parser_t *p)
15849rb_ruby_parser_enc(rb_parser_t *p)
15855rb_ruby_parser_ruby_sourcefile_string(rb_parser_t *p)
15857 return p->ruby_sourcefile_string;
15861rb_ruby_parser_ruby_sourceline(rb_parser_t *p)
15863 return p->ruby_sourceline;
15867rb_ruby_parser_lex_state(rb_parser_t *p)
15869 return p->lex.state;
15873rb_ruby_ripper_parse0(rb_parser_t *p)
15876 p->ast = rb_ast_new();
15877 ripper_yyparse((void*)p);
15878 rb_ast_free(p->ast);
15881 p->eval_tree_begin = 0;
15885rb_ruby_ripper_dedent_string(rb_parser_t *p, rb_parser_string_t *string, int width)
15887 return dedent_string(p, string, width);
15891rb_ruby_ripper_initialized_p(rb_parser_t *p)
15893 return p->lex.input != 0;
15897rb_ruby_ripper_parser_initialize(rb_parser_t *p)
15899 parser_initialize(p);
15903rb_ruby_ripper_column(rb_parser_t *p)
15905 return p->lex.ptok - p->lex.pbeg;
15909rb_ruby_ripper_token_len(rb_parser_t *p)
15911 return p->lex.pcur - p->lex.ptok;
15914rb_parser_string_t *
15915rb_ruby_ripper_lex_lastline(rb_parser_t *p)
15917 return p->lex.lastline;
15921rb_ruby_ripper_lex_state_name(struct parser_params *p, int state)
15923 return rb_parser_lex_state_name(p, (enum lex_state_e)state);
15926#ifdef UNIVERSAL_PARSER
15928rb_ripper_parser_params_allocate(const rb_parser_config_t *config)
15930 rb_parser_t *p = (rb_parser_t *)config->calloc(1, sizeof(rb_parser_t));
15931 p->config = config;
15936struct parser_params*
15937rb_ruby_ripper_parser_allocate(void)
15939 return (struct parser_params *)ruby_xcalloc(1, sizeof(struct parser_params));
15945rb_parser_printf(struct parser_params *p, const char *fmt, ...)
15948 VALUE mesg = p->debug_buffer;
15950 if (NIL_P(mesg)) p->debug_buffer = mesg = rb_str_new(0, 0);
15952 rb_str_vcatf(mesg, fmt, ap);
15954 if (char_at_end(p, mesg, 0) == '\n') {
15955 rb_io_write(p->debug_output, mesg);
15956 p->debug_buffer = Qnil;
15961parser_compile_error(struct parser_params *p, const rb_code_location_t *loc, const char *fmt, ...)
15964 int lineno, column;
15967 lineno = loc->end_pos.lineno;
15968 column = loc->end_pos.column;
15971 lineno = p->ruby_sourceline;
15972 column = rb_long2int(p->lex.pcur - p->lex.pbeg);
15975 rb_io_flush(p->debug_output);
15979 rb_syntax_error_append(p->error_buffer,
15980 p->ruby_sourcefile_string,
15987count_char(const char *str, int c)
15990 while (str[n] == c) ++n;
15995 * strip enclosing double-quotes, same as the default yytnamerr except
15996 * for that single-quotes matching back-quotes do not stop stripping.
15998 * "\"`class' keyword\"" => "`class' keyword"
16001rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr)
16003 if (*yystr == '"') {
16004 size_t yyn = 0, bquote = 0;
16005 const char *yyp = yystr;
16011 bquote = count_char(yyp+1, '\'') + 1;
16012 if (yyres) memcpy(&yyres[yyn], yyp, bquote);
16018 if (bquote && count_char(yyp+1, '\'') + 1 == bquote) {
16019 if (yyres) memcpy(yyres + yyn, yyp, bquote);
16025 if (yyp[1] && yyp[1] != '\'' && yyp[2] == '\'') {
16026 if (yyres) memcpy(yyres + yyn, yyp, 3);
16031 goto do_not_strip_quotes;
16035 goto do_not_strip_quotes;
16038 if (*++yyp != '\\')
16039 goto do_not_strip_quotes;
16040 /* Fall through. */
16054 do_not_strip_quotes: ;
16057 if (!yyres) return strlen(yystr);
16059 return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres);
16064#define validate(x) (void)(x)
16067ripper_dispatch0(struct parser_params *p, ID mid)
16069 return rb_funcall(p->value, mid, 0);
16073ripper_dispatch1(struct parser_params *p, ID mid, VALUE a)
16076 return rb_funcall(p->value, mid, 1, a);
16080ripper_dispatch2(struct parser_params *p, ID mid, VALUE a, VALUE b)
16084 return rb_funcall(p->value, mid, 2, a, b);
16088ripper_dispatch3(struct parser_params *p, ID mid, VALUE a, VALUE b, VALUE c)
16093 return rb_funcall(p->value, mid, 3, a, b, c);
16097ripper_dispatch4(struct parser_params *p, ID mid, VALUE a, VALUE b, VALUE c, VALUE d)
16103 return rb_funcall(p->value, mid, 4, a, b, c, d);
16107ripper_dispatch5(struct parser_params *p, ID mid, VALUE a, VALUE b, VALUE c, VALUE d, VALUE e)
16114 return rb_funcall(p->value, mid, 5, a, b, c, d, e);
16118ripper_dispatch7(struct parser_params *p, ID mid, VALUE a, VALUE b, VALUE c, VALUE d, VALUE e, VALUE f, VALUE g)
16127 return rb_funcall(p->value, mid, 7, a, b, c, d, e, f, g);
16131ripper_error(struct parser_params *p)
16137ripper_value(struct parser_params *p)
16139 (void)yystpcpy; /* may not used in newer bison */
16148 * c-file-style: "ruby"