Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ruby/parse.y
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
11553 lines (10674 sloc)
251 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
parse.y - | |
$Author$ | |
created at: Fri May 28 18:02:42 JST 1993 | |
Copyright (C) 1993-2007 Yukihiro Matsumoto | |
**********************************************************************/ | |
%{ | |
#if !YYPURE | |
# error needs pure parser | |
#endif | |
#ifndef PARSER_DEBUG | |
#define PARSER_DEBUG 0 | |
#endif | |
#define YYDEBUG 1 | |
#define YYERROR_VERBOSE 1 | |
#define YYSTACK_USE_ALLOCA 0 | |
#include "ruby/ruby.h" | |
#include "ruby/st.h" | |
#include "ruby/encoding.h" | |
#include "internal.h" | |
#include "node.h" | |
#include "parse.h" | |
#include "symbol.h" | |
#include "regenc.h" | |
#include <stdio.h> | |
#include <errno.h> | |
#include <ctype.h> | |
#include "probes.h" | |
#ifndef WARN_PAST_SCOPE | |
# define WARN_PAST_SCOPE 0 | |
#endif | |
#define TAB_WIDTH 8 | |
#define YYMALLOC(size) rb_parser_malloc(parser, (size)) | |
#define YYREALLOC(ptr, size) rb_parser_realloc(parser, (ptr), (size)) | |
#define YYCALLOC(nelem, size) rb_parser_calloc(parser, (nelem), (size)) | |
#define YYFREE(ptr) rb_parser_free(parser, (ptr)) | |
#define YYFPRINTF rb_parser_printf | |
#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL | |
# define YY_LOCATION_PRINT(File, Loc) \ | |
rb_parser_printf(parser, "%d.%d-%d.%d", \ | |
(Loc).first_line, (Loc).first_column, \ | |
(Loc).last_line, (Loc).last_column) | |
#endif | |
#undef malloc | |
#undef realloc | |
#undef calloc | |
#undef free | |
#define malloc YYMALLOC | |
#define realloc YYREALLOC | |
#define calloc YYCALLOC | |
#define free YYFREE | |
enum lex_state_bits { | |
EXPR_BEG_bit, /* ignore newline, +/- is a sign. */ | |
EXPR_END_bit, /* newline significant, +/- is an operator. */ | |
EXPR_ENDARG_bit, /* ditto, and unbound braces. */ | |
EXPR_ENDFN_bit, /* ditto, and unbound braces. */ | |
EXPR_ARG_bit, /* newline significant, +/- is an operator. */ | |
EXPR_CMDARG_bit, /* newline significant, +/- is an operator. */ | |
EXPR_MID_bit, /* newline significant, +/- is an operator. */ | |
EXPR_FNAME_bit, /* ignore newline, no reserved words. */ | |
EXPR_DOT_bit, /* right after `.' or `::', no reserved words. */ | |
EXPR_CLASS_bit, /* immediate after `class', no here document. */ | |
EXPR_LABEL_bit, /* flag bit, label is allowed. */ | |
EXPR_LABELED_bit, /* flag bit, just after a label. */ | |
EXPR_MAX_STATE | |
}; | |
/* examine combinations */ | |
enum lex_state_e { | |
#define DEF_EXPR(n) EXPR_##n = (1 << EXPR_##n##_bit) | |
DEF_EXPR(BEG), | |
DEF_EXPR(END), | |
DEF_EXPR(ENDARG), | |
DEF_EXPR(ENDFN), | |
DEF_EXPR(ARG), | |
DEF_EXPR(CMDARG), | |
DEF_EXPR(MID), | |
DEF_EXPR(FNAME), | |
DEF_EXPR(DOT), | |
DEF_EXPR(CLASS), | |
DEF_EXPR(LABEL), | |
DEF_EXPR(LABELED), | |
EXPR_VALUE = EXPR_BEG, | |
EXPR_BEG_ANY = (EXPR_BEG | EXPR_MID | EXPR_CLASS), | |
EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG), | |
EXPR_END_ANY = (EXPR_END | EXPR_ENDARG | EXPR_ENDFN) | |
}; | |
#define IS_lex_state_for(x, ls) ((x) & (ls)) | |
#define IS_lex_state_all_for(x, ls) (((x) & (ls)) == (ls)) | |
#define IS_lex_state(ls) IS_lex_state_for(lex_state, (ls)) | |
#define IS_lex_state_all(ls) IS_lex_state_all_for(lex_state, (ls)) | |
# define SET_LEX_STATE(ls) \ | |
(lex_state = (yydebug ? trace_lex_state(lex_state, (ls), __LINE__) : \ | |
(enum lex_state_e)(ls))) | |
static enum lex_state_e trace_lex_state(enum lex_state_e from, enum lex_state_e to, int line); | |
typedef VALUE stack_type; | |
static void show_bitstack(stack_type, const char *, int); | |
# define SHOW_BITSTACK(stack, name) (yydebug ? show_bitstack(stack, name, __LINE__) : (void)0) | |
# define BITSTACK_PUSH(stack, n) (((stack) = ((stack)<<1)|((n)&1)), SHOW_BITSTACK(stack, #stack"(push)")) | |
# define BITSTACK_POP(stack) (((stack) = (stack) >> 1), SHOW_BITSTACK(stack, #stack"(pop)")) | |
# define BITSTACK_LEXPOP(stack) (((stack) = ((stack) >> 1) | ((stack) & 1)), SHOW_BITSTACK(stack, #stack"(lexpop)")) | |
# define BITSTACK_SET_P(stack) (SHOW_BITSTACK(stack, #stack), (stack)&1) | |
# define BITSTACK_SET(stack, n) ((stack)=(n), SHOW_BITSTACK(stack, #stack"(set)")) | |
#define COND_PUSH(n) BITSTACK_PUSH(cond_stack, (n)) | |
#define COND_POP() BITSTACK_POP(cond_stack) | |
#define COND_LEXPOP() BITSTACK_LEXPOP(cond_stack) | |
#define COND_P() BITSTACK_SET_P(cond_stack) | |
#define COND_SET(n) BITSTACK_SET(cond_stack, (n)) | |
#define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, (n)) | |
#define CMDARG_POP() BITSTACK_POP(cmdarg_stack) | |
#define CMDARG_LEXPOP() BITSTACK_LEXPOP(cmdarg_stack) | |
#define CMDARG_P() BITSTACK_SET_P(cmdarg_stack) | |
#define CMDARG_SET(n) BITSTACK_SET(cmdarg_stack, (n)) | |
struct vtable { | |
ID *tbl; | |
int pos; | |
int capa; | |
struct vtable *prev; | |
}; | |
struct local_vars { | |
struct vtable *args; | |
struct vtable *vars; | |
struct vtable *used; | |
# if WARN_PAST_SCOPE | |
struct vtable *past; | |
# endif | |
struct local_vars *prev; | |
stack_type cmdargs; | |
}; | |
#define DVARS_INHERIT ((void*)1) | |
#define DVARS_TOPSCOPE NULL | |
#define DVARS_SPECIAL_P(tbl) (!POINTER_P(tbl)) | |
#define POINTER_P(val) ((VALUE)(val) & ~(VALUE)3) | |
static int | |
vtable_size(const struct vtable *tbl) | |
{ | |
if (POINTER_P(tbl)) { | |
return tbl->pos; | |
} | |
else { | |
return 0; | |
} | |
} | |
#define VTBL_DEBUG 0 | |
static struct vtable * | |
vtable_alloc(struct vtable *prev) | |
{ | |
struct vtable *tbl = ALLOC(struct vtable); | |
tbl->pos = 0; | |
tbl->capa = 8; | |
tbl->tbl = ALLOC_N(ID, tbl->capa); | |
tbl->prev = prev; | |
if (VTBL_DEBUG) printf("vtable_alloc: %p\n", (void *)tbl); | |
return tbl; | |
} | |
static void | |
vtable_free(struct vtable *tbl) | |
{ | |
if (VTBL_DEBUG)printf("vtable_free: %p\n", (void *)tbl); | |
if (POINTER_P(tbl)) { | |
if (tbl->tbl) { | |
xfree(tbl->tbl); | |
} | |
xfree(tbl); | |
} | |
} | |
static void | |
vtable_add(struct vtable *tbl, ID id) | |
{ | |
if (!POINTER_P(tbl)) { | |
rb_bug("vtable_add: vtable is not allocated (%p)", (void *)tbl); | |
} | |
if (VTBL_DEBUG) printf("vtable_add: %p, %"PRIsVALUE"\n", (void *)tbl, rb_id2str(id)); | |
if (tbl->pos == tbl->capa) { | |
tbl->capa = tbl->capa * 2; | |
REALLOC_N(tbl->tbl, ID, tbl->capa); | |
} | |
tbl->tbl[tbl->pos++] = id; | |
} | |
#ifndef RIPPER | |
static void | |
vtable_pop(struct vtable *tbl, int n) | |
{ | |
if (tbl->pos < n) rb_bug("vtable_pop: unreachable"); | |
tbl->pos -= n; | |
} | |
#endif | |
static int | |
vtable_included(const struct vtable * tbl, ID id) | |
{ | |
int i; | |
if (POINTER_P(tbl)) { | |
for (i = 0; i < tbl->pos; i++) { | |
if (tbl->tbl[i] == id) { | |
return i+1; | |
} | |
} | |
} | |
return 0; | |
} | |
typedef struct token_info { | |
const char *token; | |
int linenum; | |
int column; | |
int nonspc; | |
struct token_info *next; | |
} token_info; | |
/* | |
Structure of Lexer Buffer: | |
lex_pbeg tokp lex_p lex_pend | |
| | | | | |
|-----------+--------------+------------| | |
|<------------>| | |
token | |
*/ | |
struct parser_params { | |
NODE *heap; | |
YYSTYPE *lval; | |
struct { | |
NODE *strterm; | |
VALUE (*gets)(struct parser_params*,VALUE); | |
VALUE input; | |
VALUE lastline; | |
VALUE nextline; | |
const char *pbeg; | |
const char *pcur; | |
const char *pend; | |
long gets_ptr; | |
enum lex_state_e state; | |
int paren_nest; | |
int lpar_beg; | |
int brace_nest; | |
} lex; | |
stack_type cond_stack; | |
stack_type cmdarg_stack; | |
int tokidx; | |
int toksiz; | |
int tokline; | |
int heredoc_end; | |
int heredoc_indent; | |
int heredoc_line_indent; | |
char *tokenbuf; | |
NODE *deferred_nodes; | |
struct local_vars *lvtbl; | |
int line_count; | |
int ruby_sourceline; /* current line no. */ | |
char *ruby_sourcefile; /* current source file */ | |
VALUE ruby_sourcefile_string; | |
rb_encoding *enc; | |
token_info *token_info; | |
VALUE compile_option; | |
VALUE debug_buffer; | |
ID cur_arg; | |
int last_cr_line; | |
unsigned int command_start:1; | |
unsigned int eofp: 1; | |
unsigned int ruby__end__seen: 1; | |
unsigned int yydebug: 1; | |
unsigned int has_shebang: 1; | |
unsigned int in_defined: 1; | |
unsigned int compile_for_eval: 1; | |
unsigned int in_kwarg: 1; | |
unsigned int in_single: 1; | |
unsigned int in_def: 1; | |
unsigned int token_seen: 1; | |
unsigned int token_info_enabled: 1; | |
# if WARN_PAST_SCOPE | |
unsigned int past_scope_enabled: 1; | |
# endif | |
unsigned int error_p: 1; | |
#ifndef RIPPER | |
/* Ruby core only */ | |
NODE *eval_tree_begin; | |
NODE *eval_tree; | |
VALUE debug_lines; | |
VALUE coverage; | |
#else | |
/* Ripper only */ | |
const char *tokp; | |
VALUE delayed; | |
int delayed_line; | |
int delayed_col; | |
VALUE value; | |
VALUE result; | |
VALUE parsing_thread; | |
#endif | |
}; | |
#ifdef RIPPER | |
#define intern_cstr(n,l,en) rb_intern3(n,l,en) | |
#else | |
#define intern_cstr(n,l,en) rb_intern3(n,l,en) | |
#endif | |
#define STR_NEW(p,n) rb_enc_str_new((p),(n),current_enc) | |
#define STR_NEW0() rb_enc_str_new(0,0,current_enc) | |
#define STR_NEW2(p) rb_enc_str_new((p),strlen(p),current_enc) | |
#define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),current_enc) | |
#define TOK_INTERN() intern_cstr(tok(), toklen(), current_enc) | |
static int parser_yyerror(struct parser_params*, const char*); | |
#define yyerror(msg) parser_yyerror(parser, (msg)) | |
#define lex_strterm (parser->lex.strterm) | |
#define lex_state (parser->lex.state) | |
#define cond_stack (parser->cond_stack) | |
#define cmdarg_stack (parser->cmdarg_stack) | |
#define paren_nest (parser->lex.paren_nest) | |
#define lpar_beg (parser->lex.lpar_beg) | |
#define brace_nest (parser->lex.brace_nest) | |
#define in_single (parser->in_single) | |
#define in_def (parser->in_def) | |
#define compile_for_eval (parser->compile_for_eval) | |
#define in_defined (parser->in_defined) | |
#define tokenbuf (parser->tokenbuf) | |
#define tokidx (parser->tokidx) | |
#define toksiz (parser->toksiz) | |
#define tokline (parser->tokline) | |
#define lex_input (parser->lex.input) | |
#define lex_lastline (parser->lex.lastline) | |
#define lex_nextline (parser->lex.nextline) | |
#define lex_pbeg (parser->lex.pbeg) | |
#define lex_p (parser->lex.pcur) | |
#define lex_pend (parser->lex.pend) | |
#define heredoc_end (parser->heredoc_end) | |
#define heredoc_indent (parser->heredoc_indent) | |
#define heredoc_line_indent (parser->heredoc_line_indent) | |
#define command_start (parser->command_start) | |
#define deferred_nodes (parser->deferred_nodes) | |
#define lex_gets_ptr (parser->lex.gets_ptr) | |
#define lex_gets (parser->lex.gets) | |
#define lvtbl (parser->lvtbl) | |
#define ruby__end__seen (parser->ruby__end__seen) | |
#define ruby_sourceline (parser->ruby_sourceline) | |
#define ruby_sourcefile (parser->ruby_sourcefile) | |
#define ruby_sourcefile_string (parser->ruby_sourcefile_string) | |
#define current_enc (parser->enc) | |
#define current_arg (parser->cur_arg) | |
#define yydebug (parser->yydebug) | |
#ifdef RIPPER | |
#else | |
#define ruby_eval_tree (parser->eval_tree) | |
#define ruby_eval_tree_begin (parser->eval_tree_begin) | |
#define ruby_debug_lines (parser->debug_lines) | |
#define ruby_coverage (parser->coverage) | |
#endif | |
#define CALL_Q_P(q) ((q) == tANDDOT) | |
#define NODE_CALL_Q(q) (CALL_Q_P(q) ? NODE_QCALL : NODE_CALL) | |
#define NEW_QCALL(q,r,m,a) NEW_NODE(NODE_CALL_Q(q),r,m,a) | |
static int yylex(YYSTYPE*, struct parser_params*); | |
#ifndef RIPPER | |
#define yyparse ruby_yyparse | |
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE); | |
#define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3)) | |
static NODE *cond_gen(struct parser_params*,NODE*); | |
#define cond(node) cond_gen(parser, (node)) | |
static NODE *new_if_gen(struct parser_params*,NODE*,NODE*,NODE*); | |
#define new_if(cc,left,right) new_if_gen(parser, (cc), (left), (right)) | |
#define new_unless(cc,left,right) new_if_gen(parser, (cc), (right), (left)) | |
static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*); | |
#define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2)) | |
static NODE *newline_node(NODE*); | |
static void fixpos(NODE*,NODE*); | |
static int value_expr_gen(struct parser_params*,NODE*); | |
static void void_expr_gen(struct parser_params*,NODE*); | |
static NODE *remove_begin(NODE*); | |
static NODE *remove_begin_all(NODE*); | |
#define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node)) | |
#define void_expr0(node) void_expr_gen(parser, (node)) | |
#define void_expr(node) void_expr0((node) = remove_begin(node)) | |
static void void_stmts_gen(struct parser_params*,NODE*); | |
#define void_stmts(node) void_stmts_gen(parser, (node)) | |
static void reduce_nodes_gen(struct parser_params*,NODE**); | |
#define reduce_nodes(n) reduce_nodes_gen(parser,(n)) | |
static void block_dup_check_gen(struct parser_params*,NODE*,NODE*); | |
#define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2)) | |
static NODE *block_append_gen(struct parser_params*,NODE*,NODE*); | |
#define block_append(h,t) block_append_gen(parser,(h),(t)) | |
static NODE *list_append_gen(struct parser_params*,NODE*,NODE*); | |
#define list_append(l,i) list_append_gen(parser,(l),(i)) | |
static NODE *list_concat(NODE*,NODE*); | |
static NODE *arg_append_gen(struct parser_params*,NODE*,NODE*); | |
#define arg_append(h,t) arg_append_gen(parser,(h),(t)) | |
static NODE *arg_concat_gen(struct parser_params*,NODE*,NODE*); | |
#define arg_concat(h,t) arg_concat_gen(parser,(h),(t)) | |
static NODE *literal_concat_gen(struct parser_params*,NODE*,NODE*); | |
#define literal_concat(h,t) literal_concat_gen(parser,(h),(t)) | |
static int literal_concat0(struct parser_params *, VALUE, VALUE); | |
static NODE *new_evstr_gen(struct parser_params*,NODE*); | |
#define new_evstr(n) new_evstr_gen(parser,(n)) | |
static NODE *evstr2dstr_gen(struct parser_params*,NODE*); | |
#define evstr2dstr(n) evstr2dstr_gen(parser,(n)) | |
static NODE *splat_array(NODE*); | |
static NODE *call_bin_op_gen(struct parser_params*,NODE*,ID,NODE*); | |
#define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1)) | |
static NODE *call_uni_op_gen(struct parser_params*,NODE*,ID); | |
#define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id)) | |
static NODE *new_args_gen(struct parser_params*,NODE*,NODE*,ID,NODE*,NODE*); | |
#define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t)) | |
static NODE *new_args_tail_gen(struct parser_params*,NODE*,ID,ID); | |
#define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b)) | |
#define new_kw_arg(k) ((k) ? NEW_KW_ARG(0, (k)) : 0) | |
static VALUE negate_lit(VALUE); | |
static NODE *ret_args_gen(struct parser_params*,NODE*); | |
#define ret_args(node) ret_args_gen(parser, (node)) | |
static NODE *arg_blk_pass(NODE*,NODE*); | |
static NODE *new_yield_gen(struct parser_params*,NODE*); | |
#define new_yield(node) new_yield_gen(parser, (node)) | |
static NODE *dsym_node_gen(struct parser_params*,NODE*); | |
#define dsym_node(node) dsym_node_gen(parser, (node)) | |
static NODE *gettable_gen(struct parser_params*,ID); | |
#define gettable(id) gettable_gen(parser,(id)) | |
static NODE *assignable_gen(struct parser_params*,ID,NODE*); | |
#define assignable(id,node) assignable_gen(parser, (id), (node)) | |
static NODE *aryset_gen(struct parser_params*,NODE*,NODE*); | |
#define aryset(node1,node2) aryset_gen(parser, (node1), (node2)) | |
static NODE *attrset_gen(struct parser_params*,NODE*,ID,ID); | |
#define attrset(node,q,id) attrset_gen(parser, (node), (q), (id)) | |
static void rb_backref_error_gen(struct parser_params*,NODE*); | |
#define rb_backref_error(n) rb_backref_error_gen(parser,(n)) | |
static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*); | |
#define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2)) | |
static NODE *new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs); | |
static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs); | |
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) | |
static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs); | |
#define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs)) | |
static NODE *kwd_append(NODE*, NODE*); | |
static NODE *new_hash_gen(struct parser_params *parser, NODE *hash); | |
#define new_hash(hash) new_hash_gen(parser, (hash)) | |
#define new_defined(expr) NEW_DEFINED(remove_begin_all(expr)) | |
static NODE *match_op_gen(struct parser_params*,NODE*,NODE*); | |
#define match_op(node1,node2) match_op_gen(parser, (node1), (node2)) | |
static ID *local_tbl_gen(struct parser_params*); | |
#define local_tbl() local_tbl_gen(parser) | |
static void fixup_nodes(NODE **); | |
static VALUE reg_compile_gen(struct parser_params*, VALUE, int); | |
#define reg_compile(str,options) reg_compile_gen(parser, (str), (options)) | |
static void reg_fragment_setenc_gen(struct parser_params*, VALUE, int); | |
#define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options)) | |
static int reg_fragment_check_gen(struct parser_params*, VALUE, int); | |
#define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options)) | |
static NODE *reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *match); | |
#define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match)) | |
static void parser_heredoc_dedent(struct parser_params*,NODE*); | |
# define heredoc_dedent(str) parser_heredoc_dedent(parser, (str)) | |
#define get_id(id) (id) | |
#define get_value(val) (val) | |
#else | |
#define NODE_RIPPER NODE_CDECL | |
static inline VALUE | |
ripper_new_yylval(ID a, VALUE b, VALUE c) | |
{ | |
return (VALUE)NEW_CDECL(a, b, c); | |
} | |
static inline int | |
ripper_is_node_yylval(VALUE n) | |
{ | |
return RB_TYPE_P(n, T_NODE) && nd_type(RNODE(n)) == NODE_RIPPER; | |
} | |
#define value_expr(node) ((void)(node)) | |
#define remove_begin(node) (node) | |
#define rb_dvar_defined(id) 0 | |
#define rb_local_defined(id) 0 | |
static ID ripper_get_id(VALUE); | |
#define get_id(id) ripper_get_id(id) | |
static VALUE ripper_get_value(VALUE); | |
#define get_value(val) ripper_get_value(val) | |
static VALUE assignable_gen(struct parser_params*,VALUE); | |
#define assignable(lhs,node) assignable_gen(parser, (lhs)) | |
static int id_is_var_gen(struct parser_params *parser, ID id); | |
#define id_is_var(id) id_is_var_gen(parser, (id)) | |
#define node_assign(node1, node2) dispatch2(assign, (node1), (node2)) | |
static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs); | |
static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs); | |
#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) | |
#endif /* !RIPPER */ | |
#define new_op_assign(lhs, op, rhs) new_op_assign_gen(parser, (lhs), (op), (rhs)) | |
RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg); | |
static ID formal_argument_gen(struct parser_params*, ID); | |
#define formal_argument(id) formal_argument_gen(parser, (id)) | |
static ID shadowing_lvar_gen(struct parser_params*,ID); | |
#define shadowing_lvar(name) shadowing_lvar_gen(parser, (name)) | |
static void new_bv_gen(struct parser_params*,ID); | |
#define new_bv(id) new_bv_gen(parser, (id)) | |
static void local_push_gen(struct parser_params*,int); | |
#define local_push(top) local_push_gen(parser,(top)) | |
static void local_pop_gen(struct parser_params*); | |
#define local_pop() local_pop_gen(parser) | |
static void local_var_gen(struct parser_params*, ID); | |
#define local_var(id) local_var_gen(parser, (id)) | |
static void arg_var_gen(struct parser_params*, ID); | |
#define arg_var(id) arg_var_gen(parser, (id)) | |
static int local_id_gen(struct parser_params*, ID); | |
#define local_id(id) local_id_gen(parser, (id)) | |
static ID internal_id_gen(struct parser_params*); | |
#define internal_id() internal_id_gen(parser) | |
static const struct vtable *dyna_push_gen(struct parser_params *); | |
#define dyna_push() dyna_push_gen(parser) | |
static void dyna_pop_gen(struct parser_params*, const struct vtable *); | |
#define dyna_pop(node) dyna_pop_gen(parser, (node)) | |
static int dyna_in_block_gen(struct parser_params*); | |
#define dyna_in_block() dyna_in_block_gen(parser) | |
#define dyna_var(id) local_var(id) | |
static int dvar_defined_gen(struct parser_params*,ID,int); | |
#define dvar_defined(id) dvar_defined_gen(parser, (id), 0) | |
#define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1) | |
static int dvar_curr_gen(struct parser_params*,ID); | |
#define dvar_curr(id) dvar_curr_gen(parser, (id)) | |
static int lvar_defined_gen(struct parser_params*, ID); | |
#define lvar_defined(id) lvar_defined_gen(parser, (id)) | |
#define RE_OPTION_ONCE (1<<16) | |
#define RE_OPTION_ENCODING_SHIFT 8 | |
#define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT) | |
#define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff) | |
#define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE) | |
#define RE_OPTION_MASK 0xff | |
#define RE_OPTION_ARG_ENCODING_NONE 32 | |
#define NODE_STRTERM NODE_ZARRAY /* nothing to gc */ | |
#define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */ | |
#define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1)) | |
#define nd_func u1.id | |
#if SIZEOF_SHORT == 2 | |
#define nd_term(node) ((signed short)(node)->u2.id) | |
#else | |
#define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2) | |
#endif | |
#define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2) | |
#define nd_nest u3.cnt | |
/****** Ripper *******/ | |
#ifdef RIPPER | |
#define RIPPER_VERSION "0.1.0" | |
static inline VALUE intern_sym(const char *name); | |
#include "eventids1.c" | |
#include "eventids2.c" | |
static VALUE ripper_dispatch0(struct parser_params*,ID); | |
static VALUE ripper_dispatch1(struct parser_params*,ID,VALUE); | |
static VALUE ripper_dispatch2(struct parser_params*,ID,VALUE,VALUE); | |
static VALUE ripper_dispatch3(struct parser_params*,ID,VALUE,VALUE,VALUE); | |
static VALUE ripper_dispatch4(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE); | |
static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE); | |
static VALUE ripper_dispatch7(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE); | |
static void ripper_error_gen(struct parser_params *parser); | |
#define ripper_error() ripper_error_gen(parser) | |
#define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n)) | |
#define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a)) | |
#define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b)) | |
#define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c)) | |
#define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d)) | |
#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e)) | |
#define dispatch7(n,a,b,c,d,e,f,g) ripper_dispatch7(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e), (f), (g)) | |
#define yyparse ripper_yyparse | |
#define ripper_intern(s) ID2SYM(rb_intern(s)) | |
static VALUE ripper_id2sym(ID); | |
#ifdef __GNUC__ | |
#define ripper_id2sym(id) (rb_ispunct((int)(id)) ? \ | |
ID2SYM(id) : ripper_id2sym(id)) | |
#endif | |
#define arg_new() dispatch0(args_new) | |
#define arg_add(l,a) dispatch2(args_add, (l), (a)) | |
#define arg_add_star(l,a) dispatch2(args_add_star, (l), (a)) | |
#define arg_add_block(l,b) dispatch2(args_add_block, (l), (b)) | |
#define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b))) | |
#define bare_assoc(v) dispatch1(bare_assoc_hash, (v)) | |
#define arg_add_assocs(l,b) arg_add((l), bare_assoc(b)) | |
#define args2mrhs(a) dispatch1(mrhs_new_from_args, (a)) | |
#define mrhs_new() dispatch0(mrhs_new) | |
#define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a)) | |
#define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a)) | |
#define mlhs_new() dispatch0(mlhs_new) | |
#define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a)) | |
#define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a)) | |
#define params_new(pars, opts, rest, pars2, kws, kwrest, blk) \ | |
dispatch7(params, (pars), (opts), (rest), (pars2), (kws), (kwrest), (blk)) | |
#define blockvar_new(p,v) dispatch2(block_var, (p), (v)) | |
#define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a)) | |
#define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a)) | |
#define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a))) | |
#define method_arg(m,a) dispatch2(method_add_arg,(m),(a)) | |
#define method_add_block(m,b) dispatch2(method_add_block, (m), (b)) | |
#define escape_Qundef(x) ((x)==Qundef ? Qnil : (x)) | |
static inline VALUE | |
new_args_gen(struct parser_params *parser, VALUE f, VALUE o, VALUE r, VALUE p, VALUE tail) | |
{ | |
NODE *t = (NODE *)tail; | |
VALUE k = t->u1.value, kr = t->u2.value, b = t->u3.value; | |
return params_new(f, o, r, p, k, kr, escape_Qundef(b)); | |
} | |
#define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t)) | |
static inline VALUE | |
new_args_tail_gen(struct parser_params *parser, VALUE k, VALUE kr, VALUE b) | |
{ | |
return (VALUE)MEMO_NEW(k, kr, b); | |
} | |
#define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b)) | |
#define new_defined(expr) dispatch1(defined, (expr)) | |
static void parser_heredoc_dedent(struct parser_params*,VALUE); | |
# define heredoc_dedent(str) parser_heredoc_dedent(parser, (str)) | |
#define FIXME 0 | |
#endif /* RIPPER */ | |
#ifndef RIPPER | |
# define Qnone 0 | |
# define ifndef_ripper(x) (x) | |
#else | |
# define Qnone Qnil | |
# define ifndef_ripper(x) | |
#endif | |
# define rb_warn0(fmt) WARN_CALL(WARN_ARGS(fmt, 1)) | |
# define rb_warn1(fmt,a) WARN_CALL(WARN_ARGS(fmt, 2), (a)) | |
# define rb_warn2(fmt,a,b) WARN_CALL(WARN_ARGS(fmt, 3), (a), (b)) | |
# define rb_warn3(fmt,a,b,c) WARN_CALL(WARN_ARGS(fmt, 4), (a), (b), (c)) | |
# define rb_warn4(fmt,a,b,c,d) WARN_CALL(WARN_ARGS(fmt, 5), (a), (b), (c), (d)) | |
# define rb_warning0(fmt) WARNING_CALL(WARNING_ARGS(fmt, 1)) | |
# define rb_warning1(fmt,a) WARNING_CALL(WARNING_ARGS(fmt, 2), (a)) | |
# define rb_warning2(fmt,a,b) WARNING_CALL(WARNING_ARGS(fmt, 3), (a), (b)) | |
# define rb_warning3(fmt,a,b,c) WARNING_CALL(WARNING_ARGS(fmt, 4), (a), (b), (c)) | |
# define rb_warning4(fmt,a,b,c,d) WARNING_CALL(WARNING_ARGS(fmt, 5), (a), (b), (c), (d)) | |
# define rb_warn0L(l,fmt) WARN_CALL(WARN_ARGS_L(l, fmt, 1)) | |
# define rb_warn1L(l,fmt,a) WARN_CALL(WARN_ARGS_L(l, fmt, 2), (a)) | |
# define rb_warn2L(l,fmt,a,b) WARN_CALL(WARN_ARGS_L(l, fmt, 3), (a), (b)) | |
# define rb_warn3L(l,fmt,a,b,c) WARN_CALL(WARN_ARGS_L(l, fmt, 4), (a), (b), (c)) | |
# define rb_warn4L(l,fmt,a,b,c,d) WARN_CALL(WARN_ARGS_L(l, fmt, 5), (a), (b), (c), (d)) | |
# define rb_warning0L(l,fmt) WARNING_CALL(WARNING_ARGS_L(l, fmt, 1)) | |
# define rb_warning1L(l,fmt,a) WARNING_CALL(WARNING_ARGS_L(l, fmt, 2), (a)) | |
# define rb_warning2L(l,fmt,a,b) WARNING_CALL(WARNING_ARGS_L(l, fmt, 3), (a), (b)) | |
# define rb_warning3L(l,fmt,a,b,c) WARNING_CALL(WARNING_ARGS_L(l, fmt, 4), (a), (b), (c)) | |
# define rb_warning4L(l,fmt,a,b,c,d) WARNING_CALL(WARNING_ARGS_L(l, fmt, 5), (a), (b), (c), (d)) | |
#ifdef RIPPER | |
static ID id_warn, id_warning; | |
# define WARN_S(s) STR_NEW2(s) | |
# define WARN_I(i) INT2NUM(i) | |
# define PRIsWARN "s" | |
# define WARN_ARGS(fmt,n) parser->value, id_warn, n, rb_usascii_str_new_lit(fmt) | |
# define WARN_ARGS_L(l,fmt,n) WARN_ARGS(fmt,n) | |
# define WARN_CALL rb_funcall | |
# define WARNING_ARGS(fmt,n) parser->value, id_warning, n, rb_usascii_str_new_lit(fmt) | |
# define WARNING_ARGS_L(l, fmt,n) WARNING_ARGS(fmt,n) | |
# define WARNING_CALL rb_funcall | |
static void ripper_compile_error(struct parser_params*, const char *fmt, ...); | |
# define rb_compile_error ripper_compile_error | |
# define compile_error ripper_compile_error | |
# define PARSER_ARG parser, | |
#else | |
# define WARN_S(s) s | |
# define WARN_I(i) i | |
# define PRIsWARN PRIsVALUE | |
# define WARN_ARGS(fmt,n) WARN_ARGS_L(ruby_sourceline,fmt,n) | |
# define WARN_ARGS_L(l,fmt,n) ruby_sourcefile, (l), (fmt) | |
# define WARN_CALL rb_compile_warn | |
# define WARNING_ARGS(fmt,n) WARN_ARGS(fmt,n) | |
# define WARNING_ARGS_L(l,fmt,n) WARN_ARGS_L(l,fmt,n) | |
# define WARNING_CALL rb_compile_warning | |
# define rb_compile_error rb_compile_error_str | |
# define compile_error (parser->error_p = 1),rb_compile_error_str | |
# define PARSER_ARG ruby_sourcefile_string, ruby_sourceline, (void *)current_enc, | |
#endif | |
/* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150, | |
for instance). This is too low for Ruby to parse some files, such as | |
date/format.rb, therefore bump the value up to at least Bison's default. */ | |
#ifdef OLD_YACC | |
#ifndef YYMAXDEPTH | |
#define YYMAXDEPTH 10000 | |
#endif | |
#endif | |
static void token_info_push(struct parser_params*, const char *token, size_t len); | |
static void token_info_pop(struct parser_params*, const char *token, size_t len); | |
#define token_info_push(token) token_info_push(parser, (token), rb_strlen_lit(token)) | |
#define token_info_pop(token) token_info_pop(parser, (token), rb_strlen_lit(token)) | |
%} | |
%pure-parser | |
%lex-param {struct parser_params *parser} | |
%parse-param {struct parser_params *parser} | |
%union { | |
VALUE val; | |
NODE *node; | |
ID id; | |
int num; | |
const struct vtable *vars; | |
} | |
/*%%%*/ | |
%token | |
/*% | |
%token <val> | |
%*/ | |
keyword_class | |
keyword_module | |
keyword_def | |
keyword_undef | |
keyword_begin | |
keyword_rescue | |
keyword_ensure | |
keyword_end | |
keyword_if | |
keyword_unless | |
keyword_then | |
keyword_elsif | |
keyword_else | |
keyword_case | |
keyword_when | |
keyword_while | |
keyword_until | |
keyword_for | |
keyword_break | |
keyword_next | |
keyword_redo | |
keyword_retry | |
keyword_in | |
keyword_do | |
keyword_do_cond | |
keyword_do_block | |
keyword_do_LAMBDA | |
keyword_return | |
keyword_yield | |
keyword_super | |
keyword_self | |
keyword_nil | |
keyword_true | |
keyword_false | |
keyword_and | |
keyword_or | |
keyword_not | |
modifier_if | |
modifier_unless | |
modifier_while | |
modifier_until | |
modifier_rescue | |
keyword_alias | |
keyword_defined | |
keyword_BEGIN | |
keyword_END | |
keyword__LINE__ | |
keyword__FILE__ | |
keyword__ENCODING__ | |
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL | |
%token <node> tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR | |
%token <node> tNTH_REF tBACK_REF | |
%token <num> tREGEXP_END | |
%type <node> singleton strings string string1 xstring regexp | |
%type <node> string_contents xstring_contents regexp_contents string_content | |
%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word | |
%type <node> literal numeric simple_numeric dsym cpath | |
%type <node> top_compstmt top_stmts top_stmt | |
%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call | |
%type <node> expr_value arg_value primary_value fcall | |
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure | |
%type <node> args call_args opt_call_args | |
%type <node> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail | |
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs | |
%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command | |
%type <node> f_block_optarg f_block_opt | |
%type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs | |
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var | |
%type <node> block_param opt_block_param block_param_def f_opt | |
%type <node> f_kwarg f_kw f_block_kwarg f_block_kw | |
%type <node> bv_decls opt_bv_decl bvar | |
%type <node> lambda f_larglist lambda_body | |
%type <node> brace_block cmd_brace_block do_block lhs none fitem | |
%type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post mlhs_inner | |
%type <id> fsym keyword_variable user_variable sym symbol operation operation2 operation3 | |
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg | |
%type <id> f_kwrest f_label f_arg_asgn call_op call_op2 | |
/*%%%*/ | |
/*% | |
%type <val> program reswords then do dot_or_colon | |
%*/ | |
%token END_OF_INPUT 0 "end-of-input" | |
%token tUPLUS RUBY_TOKEN(UPLUS) "unary+" | |
%token tUMINUS RUBY_TOKEN(UMINUS) "unary-" | |
%token tPOW RUBY_TOKEN(POW) "**" | |
%token tCMP RUBY_TOKEN(CMP) "<=>" | |
%token tEQ RUBY_TOKEN(EQ) "==" | |
%token tEQQ RUBY_TOKEN(EQQ) "===" | |
%token tNEQ RUBY_TOKEN(NEQ) "!=" | |
%token tGEQ RUBY_TOKEN(GEQ) ">=" | |
%token tLEQ RUBY_TOKEN(LEQ) "<=" | |
%token tANDOP RUBY_TOKEN(ANDOP) "&&" | |
%token tOROP RUBY_TOKEN(OROP) "||" | |
%token tMATCH RUBY_TOKEN(MATCH) "=~" | |
%token tNMATCH RUBY_TOKEN(NMATCH) "!~" | |
%token tDOT2 RUBY_TOKEN(DOT2) ".." | |
%token tDOT3 RUBY_TOKEN(DOT3) "..." | |
%token tAREF RUBY_TOKEN(AREF) "[]" | |
%token tASET RUBY_TOKEN(ASET) "[]=" | |
%token tLSHFT RUBY_TOKEN(LSHFT) "<<" | |
%token tRSHFT RUBY_TOKEN(RSHFT) ">>" | |
%token tANDDOT RUBY_TOKEN(ANDDOT) "&." | |
%token tCOLON2 "::" | |
%token tCOLON3 ":: at EXPR_BEG" | |
%token <id> tOP_ASGN /* +=, -= etc. */ | |
%token tASSOC "=>" | |
%token tLPAREN "(" | |
%token tLPAREN_ARG "( arg" | |
%token tRPAREN ")" | |
%token tLBRACK "[" | |
%token tLBRACE "{" | |
%token tLBRACE_ARG "{ arg" | |
%token tSTAR "*" | |
%token tDSTAR "**arg" | |
%token tAMPER "&" | |
%token tLAMBDA "->" | |
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG | |
%token tSTRING_DBEG tSTRING_DEND tSTRING_DVAR tSTRING_END tLAMBEG tLABEL_END | |
/* | |
* precedence table | |
*/ | |
%nonassoc tLOWEST | |
%nonassoc tLBRACE_ARG | |
%nonassoc modifier_if modifier_unless modifier_while modifier_until | |
%left keyword_or keyword_and | |
%right keyword_not | |
%nonassoc keyword_defined | |
%right '=' tOP_ASGN | |
%left modifier_rescue | |
%right '?' ':' | |
%nonassoc tDOT2 tDOT3 | |
%left tOROP | |
%left tANDOP | |
%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH | |
%left '>' tGEQ '<' tLEQ | |
%left '|' '^' | |
%left '&' | |
%left tLSHFT tRSHFT | |
%left '+' '-' | |
%left '*' '/' '%' | |
%right tUMINUS_NUM tUMINUS | |
%right tPOW | |
%right '!' '~' tUPLUS | |
%token tLAST_TOKEN | |
%% | |
program : { | |
SET_LEX_STATE(EXPR_BEG); | |
/*%%%*/ | |
local_push(compile_for_eval || rb_parse_in_main()); | |
/*% | |
local_push(0); | |
%*/ | |
} | |
top_compstmt | |
{ | |
/*%%%*/ | |
if ($2 && !compile_for_eval) { | |
/* last expression should not be void */ | |
if (nd_type($2) != NODE_BLOCK) void_expr($2); | |
else { | |
NODE *node = $2; | |
while (node->nd_next) { | |
node = node->nd_next; | |
} | |
void_expr(node->nd_head); | |
} | |
} | |
ruby_eval_tree = NEW_SCOPE(0, block_append(ruby_eval_tree, $2)); | |
/*% | |
$$ = $2; | |
parser->result = dispatch1(program, $$); | |
%*/ | |
local_pop(); | |
} | |
; | |
top_compstmt : top_stmts opt_terms | |
{ | |
/*%%%*/ | |
void_stmts($1); | |
fixup_nodes(&deferred_nodes); | |
/*% | |
%*/ | |
$$ = $1; | |
} | |
; | |
top_stmts : none | |
{ | |
/*%%%*/ | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch2(stmts_add, dispatch0(stmts_new), | |
dispatch0(void_stmt)); | |
%*/ | |
} | |
| top_stmt | |
{ | |
/*%%%*/ | |
$$ = newline_node($1); | |
/*% | |
$$ = dispatch2(stmts_add, dispatch0(stmts_new), $1); | |
%*/ | |
} | |
| top_stmts terms top_stmt | |
{ | |
/*%%%*/ | |
$$ = block_append($1, newline_node($3)); | |
/*% | |
$$ = dispatch2(stmts_add, $1, $3); | |
%*/ | |
} | |
| error top_stmt | |
{ | |
$$ = remove_begin($2); | |
} | |
; | |
top_stmt : stmt | |
| keyword_BEGIN | |
{ | |
/*%%%*/ | |
/* local_push(0); */ | |
/*% | |
%*/ | |
} | |
'{' top_compstmt '}' | |
{ | |
/*%%%*/ | |
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin, | |
$4); | |
/* NEW_PREEXE($4)); */ | |
/* local_pop(); */ | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(BEGIN, $4); | |
%*/ | |
} | |
; | |
bodystmt : compstmt | |
opt_rescue | |
opt_else | |
opt_ensure | |
{ | |
/*%%%*/ | |
$$ = $1; | |
if ($2) { | |
$$ = NEW_RESCUE($1, $2, $3); | |
} | |
else if ($3) { | |
rb_warn0("else without rescue is useless"); | |
$$ = block_append($$, $3); | |
} | |
if ($4) { | |
if ($$) { | |
$$ = NEW_ENSURE($$, $4); | |
} | |
else { | |
$$ = block_append($4, NEW_NIL()); | |
} | |
} | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch4(bodystmt, | |
escape_Qundef($1), | |
escape_Qundef($2), | |
escape_Qundef($3), | |
escape_Qundef($4)); | |
%*/ | |
} | |
; | |
compstmt : stmts opt_terms | |
{ | |
/*%%%*/ | |
void_stmts($1); | |
fixup_nodes(&deferred_nodes); | |
/*% | |
%*/ | |
$$ = $1; | |
} | |
; | |
stmts : none | |
{ | |
/*%%%*/ | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch2(stmts_add, dispatch0(stmts_new), | |
dispatch0(void_stmt)); | |
%*/ | |
} | |
| stmt_or_begin | |
{ | |
/*%%%*/ | |
$$ = newline_node($1); | |
/*% | |
$$ = dispatch2(stmts_add, dispatch0(stmts_new), $1); | |
%*/ | |
} | |
| stmts terms stmt_or_begin | |
{ | |
/*%%%*/ | |
$$ = block_append($1, newline_node($3)); | |
/*% | |
$$ = dispatch2(stmts_add, $1, $3); | |
%*/ | |
} | |
| error stmt | |
{ | |
$$ = remove_begin($2); | |
} | |
; | |
stmt_or_begin : stmt | |
{ | |
$$ = $1; | |
} | |
| keyword_BEGIN | |
{ | |
yyerror("BEGIN is permitted only at toplevel"); | |
/*%%%*/ | |
/* local_push(0); */ | |
/*% | |
%*/ | |
} | |
'{' top_compstmt '}' | |
{ | |
/*%%%*/ | |
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin, | |
$4); | |
/* NEW_PREEXE($4)); */ | |
/* local_pop(); */ | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(BEGIN, $4); | |
%*/ | |
} | |
stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME);} fitem | |
{ | |
/*%%%*/ | |
$$ = NEW_ALIAS($2, $4); | |
/*% | |
$$ = dispatch2(alias, $2, $4); | |
%*/ | |
} | |
| keyword_alias tGVAR tGVAR | |
{ | |
/*%%%*/ | |
$$ = NEW_VALIAS($2, $3); | |
/*% | |
$$ = dispatch2(var_alias, $2, $3); | |
%*/ | |
} | |
| keyword_alias tGVAR tBACK_REF | |
{ | |
/*%%%*/ | |
char buf[2]; | |
buf[0] = '$'; | |
buf[1] = (char)$3->nd_nth; | |
$$ = NEW_VALIAS($2, rb_intern2(buf, 2)); | |
/*% | |
$$ = dispatch2(var_alias, $2, $3); | |
%*/ | |
} | |
| keyword_alias tGVAR tNTH_REF | |
{ | |
/*%%%*/ | |
yyerror("can't make alias for the number variables"); | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch2(var_alias, $2, $3); | |
$$ = dispatch1(alias_error, $$); | |
ripper_error(); | |
%*/ | |
} | |
| keyword_undef undef_list | |
{ | |
/*%%%*/ | |
$$ = $2; | |
/*% | |
$$ = dispatch1(undef, $2); | |
%*/ | |
} | |
| stmt modifier_if expr_value | |
{ | |
/*%%%*/ | |
$$ = new_if($3, remove_begin($1), 0); | |
fixpos($$, $3); | |
/*% | |
$$ = dispatch2(if_mod, $3, $1); | |
%*/ | |
} | |
| stmt modifier_unless expr_value | |
{ | |
/*%%%*/ | |
$$ = new_unless($3, remove_begin($1), 0); | |
fixpos($$, $3); | |
/*% | |
$$ = dispatch2(unless_mod, $3, $1); | |
%*/ | |
} | |
| stmt modifier_while expr_value | |
{ | |
/*%%%*/ | |
if ($1 && nd_type($1) == NODE_BEGIN) { | |
$$ = NEW_WHILE(cond($3), $1->nd_body, 0); | |
} | |
else { | |
$$ = NEW_WHILE(cond($3), $1, 1); | |
} | |
/*% | |
$$ = dispatch2(while_mod, $3, $1); | |
%*/ | |
} | |
| stmt modifier_until expr_value | |
{ | |
/*%%%*/ | |
if ($1 && nd_type($1) == NODE_BEGIN) { | |
$$ = NEW_UNTIL(cond($3), $1->nd_body, 0); | |
} | |
else { | |
$$ = NEW_UNTIL(cond($3), $1, 1); | |
} | |
/*% | |
$$ = dispatch2(until_mod, $3, $1); | |
%*/ | |
} | |
| stmt modifier_rescue stmt | |
{ | |
/*%%%*/ | |
NODE *resq = NEW_RESBODY(0, remove_begin($3), 0); | |
$$ = NEW_RESCUE(remove_begin($1), resq, 0); | |
/*% | |
$$ = dispatch2(rescue_mod, $1, $3); | |
%*/ | |
} | |
| keyword_END '{' compstmt '}' | |
{ | |
if (in_def || in_single) { | |
rb_warn0("END in method; use at_exit"); | |
} | |
/*%%%*/ | |
$$ = NEW_POSTEXE(NEW_NODE( | |
NODE_SCOPE, 0 /* tbl */, $3 /* body */, 0 /* args */)); | |
/*% | |
$$ = dispatch1(END, $3); | |
%*/ | |
} | |
| command_asgn | |
| mlhs '=' command_call | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$1->nd_value = $3; | |
$$ = $1; | |
/*% | |
$$ = dispatch2(massign, $1, $3); | |
%*/ | |
} | |
| var_lhs tOP_ASGN command_call | |
{ | |
value_expr($3); | |
$$ = new_op_assign($1, $2, $3); | |
} | |
| primary_value '[' opt_call_args rbracket tOP_ASGN command_call | |
{ | |
/*%%%*/ | |
NODE *args; | |
value_expr($6); | |
if (!$3) $3 = NEW_ZARRAY(); | |
args = arg_concat($3, $6); | |
if ($5 == tOROP) { | |
$5 = 0; | |
} | |
else if ($5 == tANDOP) { | |
$5 = 1; | |
} | |
$$ = NEW_OP_ASGN1($1, $5, args); | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch2(aref_field, $1, escape_Qundef($3)); | |
$$ = dispatch3(opassign, $$, $5, $6); | |
%*/ | |
} | |
| primary_value call_op tIDENTIFIER tOP_ASGN command_call | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, $2, $3, $4, $5); | |
} | |
| primary_value call_op tCONSTANT tOP_ASGN command_call | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, $2, $3, $4, $5); | |
} | |
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_call | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON2($1, $3); | |
$$ = new_const_op_assign($$, $4, $5); | |
/*% | |
$$ = dispatch2(const_path_field, $1, $3); | |
$$ = dispatch3(opassign, $$, $4, $5); | |
%*/ | |
} | |
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, idCOLON2, $3, $4, $5); | |
} | |
| backref tOP_ASGN command_call | |
{ | |
/*%%%*/ | |
rb_backref_error($1); | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch2(assign, dispatch1(var_field, $1), $3); | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
%*/ | |
} | |
| lhs '=' mrhs | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$$ = node_assign($1, $3); | |
/*% | |
$$ = dispatch2(assign, $1, $3); | |
%*/ | |
} | |
| mlhs '=' mrhs_arg | |
{ | |
/*%%%*/ | |
$1->nd_value = $3; | |
$$ = $1; | |
/*% | |
$$ = dispatch2(massign, $1, $3); | |
%*/ | |
} | |
| expr | |
; | |
command_asgn : lhs '=' command_call | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$$ = node_assign($1, $3); | |
/*% | |
$$ = dispatch2(assign, $1, $3); | |
%*/ | |
} | |
| lhs '=' command_asgn | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$$ = node_assign($1, $3); | |
/*% | |
$$ = dispatch2(assign, $1, $3); | |
%*/ | |
} | |
; | |
expr : command_call | |
| expr keyword_and expr | |
{ | |
/*%%%*/ | |
$$ = logop(NODE_AND, $1, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ripper_intern("and"), $3); | |
%*/ | |
} | |
| expr keyword_or expr | |
{ | |
/*%%%*/ | |
$$ = logop(NODE_OR, $1, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ripper_intern("or"), $3); | |
%*/ | |
} | |
| keyword_not opt_nl expr | |
{ | |
/*%%%*/ | |
$$ = call_uni_op(cond($3), '!'); | |
/*% | |
$$ = dispatch2(unary, ripper_intern("not"), $3); | |
%*/ | |
} | |
| '!' command_call | |
{ | |
/*%%%*/ | |
$$ = call_uni_op(cond($2), '!'); | |
/*% | |
$$ = dispatch2(unary, ripper_id2sym('!'), $2); | |
%*/ | |
} | |
| arg | |
; | |
expr_value : expr | |
{ | |
/*%%%*/ | |
value_expr($1); | |
$$ = $1; | |
if (!$$) $$ = NEW_NIL(); | |
/*% | |
$$ = $1; | |
%*/ | |
} | |
; | |
command_call : command | |
| block_command | |
; | |
block_command : block_call | |
| block_call call_op2 operation2 command_args | |
{ | |
/*%%%*/ | |
$$ = NEW_QCALL($2, $1, $3, $4); | |
/*% | |
$$ = dispatch3(call, $1, $2, $3); | |
$$ = method_arg($$, $4); | |
%*/ | |
} | |
; | |
cmd_brace_block : tLBRACE_ARG | |
{ | |
$<vars>1 = dyna_push(); | |
/*%%%*/ | |
$<num>$ = ruby_sourceline; | |
/*% | |
%*/ | |
} | |
opt_block_param | |
compstmt | |
'}' | |
{ | |
/*%%%*/ | |
$$ = NEW_ITER($3,$4); | |
nd_set_line($$, $<num>2); | |
/*% | |
$$ = dispatch2(brace_block, escape_Qundef($3), $4); | |
%*/ | |
dyna_pop($<vars>1); | |
} | |
; | |
fcall : operation | |
{ | |
/*%%%*/ | |
$$ = NEW_FCALL($1, 0); | |
nd_set_line($$, tokline); | |
/*% | |
%*/ | |
} | |
; | |
command : fcall command_args %prec tLOWEST | |
{ | |
/*%%%*/ | |
$$ = $1; | |
$$->nd_args = $2; | |
/*% | |
$$ = dispatch2(command, $1, $2); | |
%*/ | |
} | |
| fcall command_args cmd_brace_block | |
{ | |
/*%%%*/ | |
block_dup_check($2,$3); | |
$1->nd_args = $2; | |
$3->nd_iter = $1; | |
$$ = $3; | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch2(command, $1, $2); | |
$$ = method_add_block($$, $3); | |
%*/ | |
} | |
| primary_value call_op operation2 command_args %prec tLOWEST | |
{ | |
/*%%%*/ | |
$$ = NEW_QCALL($2, $1, $3, $4); | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch4(command_call, $1, $2, $3, $4); | |
%*/ | |
} | |
| primary_value call_op operation2 command_args cmd_brace_block | |
{ | |
/*%%%*/ | |
block_dup_check($4,$5); | |
$5->nd_iter = NEW_QCALL($2, $1, $3, $4); | |
$$ = $5; | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch4(command_call, $1, $2, $3, $4); | |
$$ = method_add_block($$, $5); | |
%*/ | |
} | |
| primary_value tCOLON2 operation2 command_args %prec tLOWEST | |
{ | |
/*%%%*/ | |
$$ = NEW_CALL($1, $3, $4); | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch4(command_call, $1, ID2SYM(idCOLON2), $3, $4); | |
%*/ | |
} | |
| primary_value tCOLON2 operation2 command_args cmd_brace_block | |
{ | |
/*%%%*/ | |
block_dup_check($4,$5); | |
$5->nd_iter = NEW_CALL($1, $3, $4); | |
$$ = $5; | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch4(command_call, $1, ID2SYM(idCOLON2), $3, $4); | |
$$ = method_add_block($$, $5); | |
%*/ | |
} | |
| keyword_super command_args | |
{ | |
/*%%%*/ | |
$$ = NEW_SUPER($2); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch1(super, $2); | |
%*/ | |
} | |
| keyword_yield command_args | |
{ | |
/*%%%*/ | |
$$ = new_yield($2); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch1(yield, $2); | |
%*/ | |
} | |
| keyword_return call_args | |
{ | |
/*%%%*/ | |
$$ = NEW_RETURN(ret_args($2)); | |
/*% | |
$$ = dispatch1(return, $2); | |
%*/ | |
} | |
| keyword_break call_args | |
{ | |
/*%%%*/ | |
$$ = NEW_BREAK(ret_args($2)); | |
/*% | |
$$ = dispatch1(break, $2); | |
%*/ | |
} | |
| keyword_next call_args | |
{ | |
/*%%%*/ | |
$$ = NEW_NEXT(ret_args($2)); | |
/*% | |
$$ = dispatch1(next, $2); | |
%*/ | |
} | |
; | |
mlhs : mlhs_basic | |
| tLPAREN mlhs_inner rparen | |
{ | |
/*%%%*/ | |
$$ = $2; | |
/*% | |
$$ = dispatch1(mlhs_paren, $2); | |
%*/ | |
} | |
; | |
mlhs_inner : mlhs_basic | |
| tLPAREN mlhs_inner rparen | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(NEW_LIST($2), 0); | |
/*% | |
$$ = dispatch1(mlhs_paren, $2); | |
%*/ | |
} | |
; | |
mlhs_basic : mlhs_head | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN($1, 0); | |
/*% | |
$$ = $1; | |
%*/ | |
} | |
| mlhs_head mlhs_item | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(list_append($1,$2), 0); | |
/*% | |
$$ = mlhs_add($1, $2); | |
%*/ | |
} | |
| mlhs_head tSTAR mlhs_node | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN($1, $3); | |
/*% | |
$$ = mlhs_add_star($1, $3); | |
%*/ | |
} | |
| mlhs_head tSTAR mlhs_node ',' mlhs_post | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN($1, NEW_POSTARG($3,$5)); | |
/*% | |
$1 = mlhs_add_star($1, $3); | |
$$ = mlhs_add($1, $5); | |
%*/ | |
} | |
| mlhs_head tSTAR | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN($1, -1); | |
/*% | |
$$ = mlhs_add_star($1, Qnil); | |
%*/ | |
} | |
| mlhs_head tSTAR ',' mlhs_post | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN($1, NEW_POSTARG(-1, $4)); | |
/*% | |
$1 = mlhs_add_star($1, Qnil); | |
$$ = mlhs_add($1, $4); | |
%*/ | |
} | |
| tSTAR mlhs_node | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(0, $2); | |
/*% | |
$$ = mlhs_add_star(mlhs_new(), $2); | |
%*/ | |
} | |
| tSTAR mlhs_node ',' mlhs_post | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(0, NEW_POSTARG($2,$4)); | |
/*% | |
$2 = mlhs_add_star(mlhs_new(), $2); | |
$$ = mlhs_add($2, $4); | |
%*/ | |
} | |
| tSTAR | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(0, -1); | |
/*% | |
$$ = mlhs_add_star(mlhs_new(), Qnil); | |
%*/ | |
} | |
| tSTAR ',' mlhs_post | |
{ | |
/*%%%*/ | |
$$ = NEW_MASGN(0, NEW_POSTARG(-1, $3)); | |
/*% | |
$$ = mlhs_add_star(mlhs_new(), Qnil); | |
$$ = mlhs_add($$, $3); | |
%*/ | |
} | |
; | |
mlhs_item : mlhs_node | |
| tLPAREN mlhs_inner rparen | |
{ | |
/*%%%*/ | |
$$ = $2; | |
/*% | |
$$ = dispatch1(mlhs_paren, $2); | |
%*/ | |
} | |
; | |
mlhs_head : mlhs_item ',' | |
{ | |
/*%%%*/ | |
$$ = NEW_LIST($1); | |
/*% | |
$$ = mlhs_add(mlhs_new(), $1); | |
%*/ | |
} | |
| mlhs_head mlhs_item ',' | |
{ | |
/*%%%*/ | |
$$ = list_append($1, $2); | |
/*% | |
$$ = mlhs_add($1, $2); | |
%*/ | |
} | |
; | |
mlhs_post : mlhs_item | |
{ | |
/*%%%*/ | |
$$ = NEW_LIST($1); | |
/*% | |
$$ = mlhs_add(mlhs_new(), $1); | |
%*/ | |
} | |
| mlhs_post ',' mlhs_item | |
{ | |
/*%%%*/ | |
$$ = list_append($1, $3); | |
/*% | |
$$ = mlhs_add($1, $3); | |
%*/ | |
} | |
; | |
mlhs_node : user_variable | |
{ | |
$$ = assignable($1, 0); | |
} | |
| keyword_variable | |
{ | |
$$ = assignable($1, 0); | |
} | |
| primary_value '[' opt_call_args rbracket | |
{ | |
/*%%%*/ | |
$$ = aryset($1, $3); | |
/*% | |
$$ = dispatch2(aref_field, $1, escape_Qundef($3)); | |
%*/ | |
} | |
| primary_value call_op tIDENTIFIER | |
{ | |
/*%%%*/ | |
$$ = attrset($1, $2, $3); | |
/*% | |
$$ = dispatch3(field, $1, $2, $3); | |
%*/ | |
} | |
| primary_value tCOLON2 tIDENTIFIER | |
{ | |
/*%%%*/ | |
$$ = attrset($1, idCOLON2, $3); | |
/*% | |
$$ = dispatch2(const_path_field, $1, $3); | |
%*/ | |
} | |
| primary_value call_op tCONSTANT | |
{ | |
/*%%%*/ | |
$$ = attrset($1, $2, $3); | |
/*% | |
$$ = dispatch3(field, $1, $2, $3); | |
%*/ | |
} | |
| primary_value tCOLON2 tCONSTANT | |
{ | |
/*%%%*/ | |
if (in_def || in_single) | |
yyerror("dynamic constant assignment"); | |
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3)); | |
/*% | |
$$ = dispatch2(const_path_field, $1, $3); | |
if (in_def || in_single) { | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
} | |
%*/ | |
} | |
| tCOLON3 tCONSTANT | |
{ | |
/*%%%*/ | |
if (in_def || in_single) | |
yyerror("dynamic constant assignment"); | |
$$ = NEW_CDECL(0, 0, NEW_COLON3($2)); | |
/*% | |
$$ = dispatch1(top_const_field, $2); | |
if (in_def || in_single) { | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
} | |
%*/ | |
} | |
| backref | |
{ | |
/*%%%*/ | |
rb_backref_error($1); | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(var_field, $1); | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
%*/ | |
} | |
; | |
lhs : user_variable | |
{ | |
$$ = assignable($1, 0); | |
/*%%%*/ | |
if (!$$) $$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(var_field, $$); | |
%*/ | |
} | |
| keyword_variable | |
{ | |
$$ = assignable($1, 0); | |
/*%%%*/ | |
if (!$$) $$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(var_field, $$); | |
%*/ | |
} | |
| primary_value '[' opt_call_args rbracket | |
{ | |
/*%%%*/ | |
$$ = aryset($1, $3); | |
/*% | |
$$ = dispatch2(aref_field, $1, escape_Qundef($3)); | |
%*/ | |
} | |
| primary_value call_op tIDENTIFIER | |
{ | |
/*%%%*/ | |
$$ = attrset($1, $2, $3); | |
/*% | |
$$ = dispatch3(field, $1, $2, $3); | |
%*/ | |
} | |
| primary_value tCOLON2 tIDENTIFIER | |
{ | |
/*%%%*/ | |
$$ = attrset($1, idCOLON2, $3); | |
/*% | |
$$ = dispatch3(field, $1, ID2SYM(idCOLON2), $3); | |
%*/ | |
} | |
| primary_value call_op tCONSTANT | |
{ | |
/*%%%*/ | |
$$ = attrset($1, $2, $3); | |
/*% | |
$$ = dispatch3(field, $1, $2, $3); | |
%*/ | |
} | |
| primary_value tCOLON2 tCONSTANT | |
{ | |
/*%%%*/ | |
if (in_def || in_single) | |
yyerror("dynamic constant assignment"); | |
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3)); | |
/*% | |
$$ = dispatch2(const_path_field, $1, $3); | |
if (in_def || in_single) { | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
} | |
%*/ | |
} | |
| tCOLON3 tCONSTANT | |
{ | |
/*%%%*/ | |
if (in_def || in_single) | |
yyerror("dynamic constant assignment"); | |
$$ = NEW_CDECL(0, 0, NEW_COLON3($2)); | |
/*% | |
$$ = dispatch1(top_const_field, $2); | |
if (in_def || in_single) { | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
} | |
%*/ | |
} | |
| backref | |
{ | |
/*%%%*/ | |
rb_backref_error($1); | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(assign_error, $1); | |
ripper_error(); | |
%*/ | |
} | |
; | |
cname : tIDENTIFIER | |
{ | |
/*%%%*/ | |
yyerror("class/module name must be CONSTANT"); | |
/*% | |
$$ = dispatch1(class_name_error, $1); | |
ripper_error(); | |
%*/ | |
} | |
| tCONSTANT | |
; | |
cpath : tCOLON3 cname | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON3($2); | |
/*% | |
$$ = dispatch1(top_const_ref, $2); | |
%*/ | |
} | |
| cname | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON2(0, $$); | |
/*% | |
$$ = dispatch1(const_ref, $1); | |
%*/ | |
} | |
| primary_value tCOLON2 cname | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON2($1, $3); | |
/*% | |
$$ = dispatch2(const_path_ref, $1, $3); | |
%*/ | |
} | |
; | |
fname : tIDENTIFIER | |
| tCONSTANT | |
| tFID | |
| op | |
{ | |
SET_LEX_STATE(EXPR_ENDFN); | |
$$ = $1; | |
} | |
| reswords | |
{ | |
SET_LEX_STATE(EXPR_ENDFN); | |
/*%%%*/ | |
$$ = $<id>1; | |
/*% | |
$$ = $1; | |
%*/ | |
} | |
; | |
fsym : fname | |
| symbol | |
; | |
fitem : fsym | |
{ | |
/*%%%*/ | |
$$ = NEW_LIT(ID2SYM($1)); | |
/*% | |
$$ = dispatch1(symbol_literal, $1); | |
%*/ | |
} | |
| dsym | |
; | |
undef_list : fitem | |
{ | |
/*%%%*/ | |
$$ = NEW_UNDEF($1); | |
/*% | |
$$ = rb_ary_new3(1, $1); | |
%*/ | |
} | |
| undef_list ',' {SET_LEX_STATE(EXPR_FNAME);} fitem | |
{ | |
/*%%%*/ | |
$$ = block_append($1, NEW_UNDEF($4)); | |
/*% | |
rb_ary_push($1, $4); | |
%*/ | |
} | |
; | |
op : '|' { ifndef_ripper($$ = '|'); } | |
| '^' { ifndef_ripper($$ = '^'); } | |
| '&' { ifndef_ripper($$ = '&'); } | |
| tCMP { ifndef_ripper($$ = tCMP); } | |
| tEQ { ifndef_ripper($$ = tEQ); } | |
| tEQQ { ifndef_ripper($$ = tEQQ); } | |
| tMATCH { ifndef_ripper($$ = tMATCH); } | |
| tNMATCH { ifndef_ripper($$ = tNMATCH); } | |
| '>' { ifndef_ripper($$ = '>'); } | |
| tGEQ { ifndef_ripper($$ = tGEQ); } | |
| '<' { ifndef_ripper($$ = '<'); } | |
| tLEQ { ifndef_ripper($$ = tLEQ); } | |
| tNEQ { ifndef_ripper($$ = tNEQ); } | |
| tLSHFT { ifndef_ripper($$ = tLSHFT); } | |
| tRSHFT { ifndef_ripper($$ = tRSHFT); } | |
| '+' { ifndef_ripper($$ = '+'); } | |
| '-' { ifndef_ripper($$ = '-'); } | |
| '*' { ifndef_ripper($$ = '*'); } | |
| tSTAR { ifndef_ripper($$ = '*'); } | |
| '/' { ifndef_ripper($$ = '/'); } | |
| '%' { ifndef_ripper($$ = '%'); } | |
| tPOW { ifndef_ripper($$ = tPOW); } | |
| tDSTAR { ifndef_ripper($$ = tDSTAR); } | |
| '!' { ifndef_ripper($$ = '!'); } | |
| '~' { ifndef_ripper($$ = '~'); } | |
| tUPLUS { ifndef_ripper($$ = tUPLUS); } | |
| tUMINUS { ifndef_ripper($$ = tUMINUS); } | |
| tAREF { ifndef_ripper($$ = tAREF); } | |
| tASET { ifndef_ripper($$ = tASET); } | |
| '`' { ifndef_ripper($$ = '`'); } | |
; | |
reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__ | |
| keyword_BEGIN | keyword_END | |
| keyword_alias | keyword_and | keyword_begin | |
| keyword_break | keyword_case | keyword_class | keyword_def | |
| keyword_defined | keyword_do | keyword_else | keyword_elsif | |
| keyword_end | keyword_ensure | keyword_false | |
| keyword_for | keyword_in | keyword_module | keyword_next | |
| keyword_nil | keyword_not | keyword_or | keyword_redo | |
| keyword_rescue | keyword_retry | keyword_return | keyword_self | |
| keyword_super | keyword_then | keyword_true | keyword_undef | |
| keyword_when | keyword_yield | keyword_if | keyword_unless | |
| keyword_while | keyword_until | |
; | |
arg : lhs '=' arg | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$$ = node_assign($1, $3); | |
/*% | |
$$ = dispatch2(assign, $1, $3); | |
%*/ | |
} | |
| lhs '=' arg modifier_rescue arg | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0); | |
$$ = node_assign($1, $3); | |
/*% | |
$$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5)); | |
%*/ | |
} | |
| var_lhs tOP_ASGN arg | |
{ | |
value_expr($3); | |
$$ = new_op_assign($1, $2, $3); | |
} | |
| var_lhs tOP_ASGN arg modifier_rescue arg | |
{ | |
/*%%%*/ | |
value_expr($3); | |
$3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0); | |
/*% | |
$3 = dispatch2(rescue_mod, $3, $5); | |
%*/ | |
$$ = new_op_assign($1, $2, $3); | |
} | |
| primary_value '[' opt_call_args rbracket tOP_ASGN arg | |
{ | |
/*%%%*/ | |
NODE *args; | |
value_expr($6); | |
if (!$3) $3 = NEW_ZARRAY(); | |
if (nd_type($3) == NODE_BLOCK_PASS) { | |
args = NEW_ARGSCAT($3, $6); | |
} | |
else { | |
args = arg_concat($3, $6); | |
} | |
if ($5 == tOROP) { | |
$5 = 0; | |
} | |
else if ($5 == tANDOP) { | |
$5 = 1; | |
} | |
$$ = NEW_OP_ASGN1($1, $5, args); | |
fixpos($$, $1); | |
/*% | |
$1 = dispatch2(aref_field, $1, escape_Qundef($3)); | |
$$ = dispatch3(opassign, $1, $5, $6); | |
%*/ | |
} | |
| primary_value call_op tIDENTIFIER tOP_ASGN arg | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, $2, $3, $4, $5); | |
} | |
| primary_value call_op tCONSTANT tOP_ASGN arg | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, $2, $3, $4, $5); | |
} | |
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg | |
{ | |
value_expr($5); | |
$$ = new_attr_op_assign($1, idCOLON2, $3, $4, $5); | |
} | |
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON2($1, $3); | |
$$ = new_const_op_assign($$, $4, $5); | |
/*% | |
$$ = dispatch2(const_path_field, $1, $3); | |
$$ = dispatch3(opassign, $$, $4, $5); | |
%*/ | |
} | |
| tCOLON3 tCONSTANT tOP_ASGN arg | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON3($2); | |
$$ = new_const_op_assign($$, $3, $4); | |
/*% | |
$$ = dispatch1(top_const_field, $2); | |
$$ = dispatch3(opassign, $$, $3, $4); | |
%*/ | |
} | |
| backref tOP_ASGN arg | |
{ | |
/*%%%*/ | |
rb_backref_error($1); | |
$$ = NEW_BEGIN(0); | |
/*% | |
$$ = dispatch1(var_field, $1); | |
$$ = dispatch3(opassign, $$, $2, $3); | |
$$ = dispatch1(assign_error, $$); | |
ripper_error(); | |
%*/ | |
} | |
| arg tDOT2 arg | |
{ | |
/*%%%*/ | |
value_expr($1); | |
value_expr($3); | |
$$ = NEW_DOT2($1, $3); | |
if ($1 && nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) && | |
$3 && nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) { | |
deferred_nodes = list_append(deferred_nodes, $$); | |
} | |
/*% | |
$$ = dispatch2(dot2, $1, $3); | |
%*/ | |
} | |
| arg tDOT3 arg | |
{ | |
/*%%%*/ | |
value_expr($1); | |
value_expr($3); | |
$$ = NEW_DOT3($1, $3); | |
if ($1 && nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) && | |
$3 && nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) { | |
deferred_nodes = list_append(deferred_nodes, $$); | |
} | |
/*% | |
$$ = dispatch2(dot3, $1, $3); | |
%*/ | |
} | |
| arg '+' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '+', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('+'), $3); | |
%*/ | |
} | |
| arg '-' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '-', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('-'), $3); | |
%*/ | |
} | |
| arg '*' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '*', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('*'), $3); | |
%*/ | |
} | |
| arg '/' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '/', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('/'), $3); | |
%*/ | |
} | |
| arg '%' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '%', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('%'), $3); | |
%*/ | |
} | |
| arg tPOW arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tPOW, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idPow), $3); | |
%*/ | |
} | |
| tUMINUS_NUM simple_numeric tPOW arg | |
{ | |
/*%%%*/ | |
$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0); | |
/*% | |
$$ = dispatch3(binary, $2, ID2SYM(idPow), $4); | |
$$ = dispatch2(unary, ID2SYM(idUMinus), $$); | |
%*/ | |
} | |
| tUPLUS arg | |
{ | |
/*%%%*/ | |
$$ = call_uni_op($2, tUPLUS); | |
/*% | |
$$ = dispatch2(unary, ID2SYM(idUPlus), $2); | |
%*/ | |
} | |
| tUMINUS arg | |
{ | |
/*%%%*/ | |
$$ = call_uni_op($2, tUMINUS); | |
/*% | |
$$ = dispatch2(unary, ID2SYM(idUMinus), $2); | |
%*/ | |
} | |
| arg '|' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '|', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('|'), $3); | |
%*/ | |
} | |
| arg '^' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '^', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('^'), $3); | |
%*/ | |
} | |
| arg '&' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '&', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('&'), $3); | |
%*/ | |
} | |
| arg tCMP arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tCMP, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idCmp), $3); | |
%*/ | |
} | |
| arg '>' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '>', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('>'), $3); | |
%*/ | |
} | |
| arg tGEQ arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tGEQ, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idGE), $3); | |
%*/ | |
} | |
| arg '<' arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, '<', $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM('<'), $3); | |
%*/ | |
} | |
| arg tLEQ arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tLEQ, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idLE), $3); | |
%*/ | |
} | |
| arg tEQ arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tEQ, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idEq), $3); | |
%*/ | |
} | |
| arg tEQQ arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tEQQ, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idEqq), $3); | |
%*/ | |
} | |
| arg tNEQ arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tNEQ, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idNeq), $3); | |
%*/ | |
} | |
| arg tMATCH arg | |
{ | |
/*%%%*/ | |
$$ = match_op($1, $3); | |
if (nd_type($1) == NODE_LIT && RB_TYPE_P($1->nd_lit, T_REGEXP)) { | |
$$ = reg_named_capture_assign($1->nd_lit, $$); | |
} | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idEqTilde), $3); | |
%*/ | |
} | |
| arg tNMATCH arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tNMATCH, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idNeqTilde), $3); | |
%*/ | |
} | |
| '!' arg | |
{ | |
/*%%%*/ | |
$$ = call_uni_op(cond($2), '!'); | |
/*% | |
$$ = dispatch2(unary, ID2SYM('!'), $2); | |
%*/ | |
} | |
| '~' arg | |
{ | |
/*%%%*/ | |
$$ = call_uni_op($2, '~'); | |
/*% | |
$$ = dispatch2(unary, ID2SYM('~'), $2); | |
%*/ | |
} | |
| arg tLSHFT arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tLSHFT, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idLTLT), $3); | |
%*/ | |
} | |
| arg tRSHFT arg | |
{ | |
/*%%%*/ | |
$$ = call_bin_op($1, tRSHFT, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idGTGT), $3); | |
%*/ | |
} | |
| arg tANDOP arg | |
{ | |
/*%%%*/ | |
$$ = logop(NODE_AND, $1, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idANDOP), $3); | |
%*/ | |
} | |
| arg tOROP arg | |
{ | |
/*%%%*/ | |
$$ = logop(NODE_OR, $1, $3); | |
/*% | |
$$ = dispatch3(binary, $1, ID2SYM(idOROP), $3); | |
%*/ | |
} | |
| keyword_defined opt_nl {in_defined = 1;} arg | |
{ | |
in_defined = 0; | |
/*%%%*/ | |
$$ = new_defined($4); | |
/*% | |
$$ = dispatch1(defined, $4); | |
%*/ | |
} | |
| arg '?' arg opt_nl ':' arg | |
{ | |
/*%%%*/ | |
value_expr($1); | |
$$ = new_if($1, $3, $6); | |
fixpos($$, $1); | |
/*% | |
$$ = dispatch3(ifop, $1, $3, $6); | |
%*/ | |
} | |
| primary | |
{ | |
$$ = $1; | |
} | |
; | |
arg_value : arg | |
{ | |
/*%%%*/ | |
value_expr($1); | |
$$ = $1; | |
if (!$$) $$ = NEW_NIL(); | |
/*% | |
$$ = $1; | |
%*/ | |
} | |
; | |
aref_args : none | |
| args trailer | |
{ | |
$$ = $1; | |
} | |
| args ',' assocs trailer | |
{ | |
/*%%%*/ | |
$$ = $3 ? arg_append($1, new_hash($3)) : $1; | |
/*% | |
$$ = arg_add_assocs($1, $3); | |
%*/ | |
} | |
| assocs trailer | |
{ | |
/*%%%*/ | |
$$ = $1 ? NEW_LIST(new_hash($1)) : 0; | |
/*% | |
$$ = arg_add_assocs(arg_new(), $1); | |
%*/ | |
} | |
; | |
paren_args : '(' opt_call_args rparen | |
{ | |
/*%%%*/ | |
$$ = $2; | |
/*% | |
$$ = dispatch1(arg_paren, escape_Qundef($2)); | |
%*/ | |
} | |
; | |
opt_paren_args : none | |
| paren_args | |
; | |
opt_call_args : none | |
| call_args | |
| args ',' | |
{ | |
$$ = $1; | |
} | |
| args ',' assocs ',' | |
{ | |
/*%%%*/ | |
$$ = $3 ? arg_append($1, new_hash($3)) : $1; | |
/*% | |
$$ = arg_add_assocs($1, $3); | |
%*/ | |
} | |
| assocs ',' | |
{ | |
/*%%%*/ | |
$$ = $1 ? NEW_LIST(new_hash($1)) : 0; | |
/*% | |
$$ = arg_add_assocs(arg_new(), $1); | |
%*/ | |
} | |
; | |
call_args : command | |
{ | |
/*%%%*/ | |
value_expr($1); | |
$$ = NEW_LIST($1); | |
/*% | |
$$ = arg_add(arg_new(), $1); | |
%*/ | |
} | |
| args opt_block_arg | |
{ | |
/*%%%*/ | |
$$ = arg_blk_pass($1, $2); | |
/*% | |
$$ = arg_add_optblock($1, $2); | |
%*/ | |
} | |
| assocs opt_block_arg | |
{ | |
/*%%%*/ | |
$$ = NEW_LIST($1 ? new_hash($1) : 0); | |
$$ = arg_blk_pass($$, $2); | |
/*% | |
$$ = arg_add_assocs(arg_new(), $1); | |
$$ = arg_add_optblock($$, $2); | |
%*/ | |
} | |
| args ',' assocs opt_block_arg | |
{ | |
/*%%%*/ | |
$$ = $3 ? arg_append($1, new_hash($3)) : $1; | |
$$ = arg_blk_pass($$, $4); | |
/*% | |
$$ = arg_add_optblock(arg_add_assocs($1, $3), $4); | |
%*/ | |
} | |
| block_arg | |
/*%c%*/ | |
/*%c | |
{ | |
$$ = arg_add_block(arg_new(), $1); | |
} | |
%*/ | |
; | |
command_args : { | |
$<val>$ = cmdarg_stack; | |
CMDARG_PUSH(1); | |
} | |
call_args | |
{ | |
/* CMDARG_POP() */ | |
CMDARG_SET($<val>1); | |
$$ = $2; | |
} | |
; | |
block_arg : tAMPER arg_value | |
{ | |
/*%%%*/ | |
$$ = NEW_BLOCK_PASS($2); | |
/*% | |
$$ = $2; | |
%*/ | |
} | |
; | |
opt_block_arg : ',' block_arg | |
{ | |
$$ = $2; | |
} | |
| none | |
{ | |
$$ = 0; | |
} | |
; | |
args : arg_value | |
{ | |
/*%%%*/ | |
$$ = NEW_LIST($1); | |
/*% | |
$$ = arg_add(arg_new(), $1); | |
%*/ | |
} | |
| tSTAR arg_value | |
{ | |
/*%%%*/ | |
$$ = NEW_SPLAT($2); | |
/*% | |
$$ = arg_add_star(arg_new(), $2); | |
%*/ | |
} | |
| args ',' arg_value | |
{ | |
/*%%%*/ | |
NODE *n1; | |
if ((n1 = splat_array($1)) != 0) { | |
$$ = list_append(n1, $3); | |
} | |
else { | |
$$ = arg_append($1, $3); | |
} | |
/*% | |
$$ = arg_add($1, $3); | |
%*/ | |
} | |
| args ',' tSTAR arg_value | |
{ | |
/*%%%*/ | |
NODE *n1; | |
if ((nd_type($4) == NODE_ARRAY) && (n1 = splat_array($1)) != 0) { | |
$$ = list_concat(n1, $4); | |
} | |
else { | |
$$ = arg_concat($1, $4); | |
} | |
/*% | |
$$ = arg_add_star($1, $4); | |
%*/ | |
} | |
; | |
mrhs_arg : mrhs | |
| arg_value | |
; | |
mrhs : args ',' arg_value | |
{ | |
/*%%%*/ | |
NODE *n1; | |
if ((n1 = splat_array($1)) != 0) { | |
$$ = list_append(n1, $3); | |
} | |
else { | |
$$ = arg_append($1, $3); | |
} | |
/*% | |
$$ = mrhs_add(args2mrhs($1), $3); | |
%*/ | |
} | |
| args ',' tSTAR arg_value | |
{ | |
/*%%%*/ | |
NODE *n1; | |
if (nd_type($4) == NODE_ARRAY && | |
(n1 = splat_array($1)) != 0) { | |
$$ = list_concat(n1, $4); | |
} | |
else { | |
$$ = arg_concat($1, $4); | |
} | |
/*% | |
$$ = mrhs_add_star(args2mrhs($1), $4); | |
%*/ | |
} | |
| tSTAR arg_value | |
{ | |
/*%%%*/ | |
$$ = NEW_SPLAT($2); | |
/*% | |
$$ = mrhs_add_star(mrhs_new(), $2); | |
%*/ | |
} | |
; | |
primary : literal | |
| strings | |
| xstring | |
| regexp | |
| words | |
| qwords | |
| symbols | |
| qsymbols | |
| var_ref | |
| backref | |
| tFID | |
{ | |
/*%%%*/ | |
$$ = NEW_FCALL($1, 0); | |
/*% | |
$$ = method_arg(dispatch1(fcall, $1), arg_new()); | |
%*/ | |
} | |
| k_begin | |
{ | |
$<val>1 = cmdarg_stack; | |
CMDARG_SET(0); | |
/*%%%*/ | |
$<num>$ = ruby_sourceline; | |
/*% | |
%*/ | |
} | |
bodystmt | |
k_end | |
{ | |
CMDARG_SET($<val>1); | |
/*%%%*/ | |
if ($3 == NULL) { | |
$$ = NEW_NIL(); | |
} | |
else { | |
if (nd_type($3) == NODE_RESCUE || | |
nd_type($3) == NODE_ENSURE) | |
nd_set_line($3, $<num>2); | |
$$ = NEW_BEGIN($3); | |
} | |
nd_set_line($$, $<num>2); | |
/*% | |
$$ = dispatch1(begin, $3); | |
%*/ | |
} | |
| tLPAREN_ARG {SET_LEX_STATE(EXPR_ENDARG);} rparen | |
{ | |
/*%%%*/ | |
$$ = 0; | |
/*% | |
$$ = dispatch1(paren, 0); | |
%*/ | |
} | |
| tLPAREN_ARG | |
{ | |
$<val>1 = cmdarg_stack; | |
CMDARG_SET(0); | |
} | |
expr {SET_LEX_STATE(EXPR_ENDARG);} rparen | |
{ | |
CMDARG_SET($<val>1); | |
/*%%%*/ | |
$$ = $3; | |
/*% | |
$$ = dispatch1(paren, $3); | |
%*/ | |
} | |
| tLPAREN compstmt ')' | |
{ | |
/*%%%*/ | |
$$ = $2; | |
/*% | |
$$ = dispatch1(paren, $2); | |
%*/ | |
} | |
| primary_value tCOLON2 tCONSTANT | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON2($1, $3); | |
/*% | |
$$ = dispatch2(const_path_ref, $1, $3); | |
%*/ | |
} | |
| tCOLON3 tCONSTANT | |
{ | |
/*%%%*/ | |
$$ = NEW_COLON3($2); | |
/*% | |
$$ = dispatch1(top_const_ref, $2); | |
%*/ | |
} | |
| tLBRACK aref_args ']' | |
{ | |
/*%%%*/ | |
if ($2 == 0) { | |
$$ = NEW_ZARRAY(); /* zero length array*/ | |
} | |
else { | |
$$ = $2; | |
} | |
/*% | |
$$ = dispatch1(array, escape_Qundef($2)); | |
%*/ | |
} | |
| tLBRACE assoc_list '}' | |
{ | |
/*%%%*/ | |
$$ = new_hash($2); | |
/*% | |
$$ = dispatch1(hash, escape_Qundef($2)); | |
%*/ | |
} | |
| keyword_return | |
{ | |
/*%%%*/ | |
$$ = NEW_RETURN(0); | |
/*% | |
$$ = dispatch0(return0); | |
%*/ | |
} | |
| keyword_yield '(' call_args rparen | |
{ | |
/*%%%*/ | |
$$ = new_yield($3); | |
/*% | |
$$ = dispatch1(yield, dispatch1(paren, $3)); | |
%*/ | |
} | |
| keyword_yield '(' rparen | |
{ | |
/*%%%*/ | |
$$ = NEW_YIELD(0); | |
/*% | |
$$ = dispatch1(yield, dispatch1(paren, arg_new())); | |
%*/ | |
} | |
| keyword_yield | |
{ | |
/*%%%*/ | |
$$ = NEW_YIELD(0); | |
/*% | |
$$ = dispatch0(yield0); | |
%*/ | |
} | |
| keyword_defined opt_nl '(' {in_defined = 1;} expr rparen | |
{ | |
in_defined = 0; | |
/*%%%*/ | |
$$ = new_defined($5); | |
/*% | |
$$ = dispatch1(defined, $5); | |
%*/ | |
} | |
| keyword_not '(' expr rparen | |
{ | |
/*%%%*/ | |
$$ = call_uni_op(cond($3), '!'); | |
/*% | |
$$ = dispatch2(unary, ripper_intern("not"), $3); | |
%*/ | |
} | |
| keyword_not '(' rparen | |
{ | |
/*%%%*/ | |
$$ = call_uni_op(cond(NEW_NIL()), '!'); | |
/*% | |
$$ = dispatch2(unary, ripper_intern("not"), Qnil); | |
%*/ | |
} | |
| fcall brace_block | |
{ | |
/*%%%*/ | |
$2->nd_iter = $1; | |
$$ = $2; | |
/*% | |
$$ = method_arg(dispatch1(fcall, $1), arg_new()); | |
$$ = method_add_block($$, $2); | |
%*/ | |
} | |
| method_call | |
| method_call brace_block | |
{ | |
/*%%%*/ | |
block_dup_check($1->nd_args, $2); | |
$2->nd_iter = $1; | |
$$ = $2; | |
/*% | |
$$ = method_add_block($1, $2); | |
%*/ | |
} | |
| tLAMBDA lambda | |
{ | |
$$ = $2; | |
} | |
| k_if expr_value then | |
compstmt | |
if_tail | |
k_end | |
{ | |
/*%%%*/ | |
$$ = new_if($2, $4, $5); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch3(if, $2, $4, escape_Qundef($5)); | |
%*/ | |
} | |
| k_unless expr_value then | |
compstmt | |
opt_else | |
k_end | |
{ | |
/*%%%*/ | |
$$ = new_unless($2, $4, $5); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch3(unless, $2, $4, escape_Qundef($5)); | |
%*/ | |
} | |
| k_while {COND_PUSH(1);} expr_value do {COND_POP();} | |
compstmt | |
k_end | |
{ | |
/*%%%*/ | |
$$ = NEW_WHILE(cond($3), $6, 1); | |
fixpos($$, $3); | |
/*% | |
$$ = dispatch2(while, $3, $6); | |
%*/ | |
} | |
| k_until {COND_PUSH(1);} expr_value do {COND_POP();} | |
compstmt | |
k_end | |
{ | |
/*%%%*/ | |
$$ = NEW_UNTIL(cond($3), $6, 1); | |
fixpos($$, $3); | |
/*% | |
$$ = dispatch2(until, $3, $6); | |
%*/ | |
} | |
| k_case expr_value opt_terms | |
case_body | |
k_end | |
{ | |
/*%%%*/ | |
$$ = NEW_CASE($2, $4); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch2(case, $2, $4); | |
%*/ | |
} | |
| k_case opt_terms case_body k_end | |
{ | |
/*%%%*/ | |
$$ = NEW_CASE(0, $3); | |
/*% | |
$$ = dispatch2(case, Qnil, $3); | |
%*/ | |
} | |
| k_for for_var keyword_in | |
{COND_PUSH(1);} | |
expr_value do | |
{COND_POP();} | |
compstmt | |
k_end | |
{ | |
/*%%%*/ | |
/* | |
* for a, b, c in e | |
* #=> | |
* e.each{|*x| a, b, c = x} | |
* | |
* for a in e | |
* #=> | |
* e.each{|x| a, = x} | |
*/ | |
ID id = internal_id(); | |
ID *tbl = ALLOC_N(ID, 2); | |
NODE *m = NEW_ARGS_AUX(0, 0); | |
NODE *args, *scope; | |
switch (nd_type($2)) { | |
case NODE_MASGN: | |
m->nd_next = node_assign($2, NEW_FOR(NEW_DVAR(id), 0, 0)); | |
args = new_args(m, 0, id, 0, new_args_tail(0, 0, 0)); | |
break; | |
case NODE_LASGN: | |
case NODE_DASGN: | |
case NODE_DASGN_CURR: | |
$2->nd_value = NEW_DVAR(id); | |
m->nd_plen = 1; | |
m->nd_next = $2; | |
args = new_args(m, 0, 0, 0, new_args_tail(0, 0, 0)); | |
break; | |
default: | |
m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id)); | |
args = new_args(m, 0, id, 0, new_args_tail(0, 0, 0)); | |
break; | |
} | |
scope = NEW_NODE(NODE_SCOPE, tbl, $8, args); | |
tbl[0] = 1; tbl[1] = id; | |
$$ = NEW_FOR(0, $5, scope); | |
fixpos($$, $2); | |
/*% | |
$$ = dispatch3(for, $2, $5, $8); | |
%*/ | |
} | |
| k_class cpath superclass | |
{ | |
if (in_def || in_single) | |
yyerror("class definition in method body"); | |
local_push(0); | |
/*%%%*/ | |
$<num>$ = ruby_sourceline; | |
/*% | |
%*/ | |
} | |
bodystmt | |
k_end | |
{ | |
/*%%%*/ | |
$$ = NEW_CLASS($2, $5, $3); | |
nd_set_line($$, $<num>4); | |
/*% | |
$$ = dispatch3(class, $2, $3, $5); | |
%*/ | |
local_pop(); | |
} | |
| k_class tLSHFT expr | |
{ | |
$<num>$ = (in_def << 1) | in_single; | |
in_def = 0; | |
in_single = 0; | |
local_push(0); | |
} | |
term | |
bodystmt | |