2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
parse.y -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri May 28 18:02:42 JST 1993
|
|
|
|
|
2001-01-29 08:10:42 +03:00
|
|
|
Copyright (C) 1993-2001 Yukihiro Matsumoto
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
#define YYDEBUG 1
|
|
|
|
#include "ruby.h"
|
|
|
|
#include "env.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "st.h"
|
|
|
|
#include <stdio.h>
|
1999-08-13 09:45:20 +04:00
|
|
|
#include <errno.h>
|
2001-05-16 13:05:54 +04:00
|
|
|
#include <ctype.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#define ID_SCOPE_SHIFT 3
|
|
|
|
#define ID_SCOPE_MASK 0x07
|
|
|
|
#define ID_LOCAL 0x01
|
|
|
|
#define ID_INSTANCE 0x02
|
|
|
|
#define ID_GLOBAL 0x03
|
|
|
|
#define ID_ATTRSET 0x04
|
1999-12-14 09:50:43 +03:00
|
|
|
#define ID_CONST 0x05
|
2000-03-23 11:37:35 +03:00
|
|
|
#define ID_CLASS 0x06
|
2001-06-05 11:50:59 +04:00
|
|
|
#define ID_JUNK 0x07
|
2001-09-20 10:23:50 +04:00
|
|
|
#define ID_INTERNAL ID_JUNK
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-11-17 10:30:37 +03:00
|
|
|
#define is_notop_id(id) ((id)>LAST_TOKEN)
|
|
|
|
#define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
|
|
|
|
#define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
|
|
|
|
#define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
|
|
|
|
#define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
|
1999-12-14 09:50:43 +03:00
|
|
|
#define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
|
2000-03-23 11:37:35 +03:00
|
|
|
#define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
NODE *ruby_eval_tree_begin = 0;
|
|
|
|
NODE *ruby_eval_tree = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
char *ruby_sourcefile; /* current source file */
|
|
|
|
int ruby_sourceline; /* current line no. */
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static int yylex();
|
|
|
|
static int yyerror();
|
|
|
|
|
|
|
|
static enum lex_state {
|
|
|
|
EXPR_BEG, /* ignore newline, +/- is a sign. */
|
|
|
|
EXPR_END, /* newline significant, +/- is a operator. */
|
1999-01-20 07:59:39 +03:00
|
|
|
EXPR_ARG, /* newline significant, +/- is a operator. */
|
2001-05-30 13:12:34 +04:00
|
|
|
EXPR_CMDARG, /* newline significant, +/- is a operator. */
|
2001-06-01 10:47:32 +04:00
|
|
|
EXPR_ENDARG, /* newline significant, +/- is a operator. */
|
2000-05-30 08:24:17 +04:00
|
|
|
EXPR_MID, /* newline significant, +/- is a operator. */
|
1999-08-13 09:45:20 +04:00
|
|
|
EXPR_FNAME, /* ignore newline, no reserved words. */
|
|
|
|
EXPR_DOT, /* right after `.' or `::', no reserved words. */
|
1999-01-20 07:59:39 +03:00
|
|
|
EXPR_CLASS, /* immediate after `class', no here document. */
|
1998-01-16 15:13:05 +03:00
|
|
|
} lex_state;
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
typedef unsigned LONG_LONG stack_type;
|
2001-01-29 08:10:42 +03:00
|
|
|
#else
|
|
|
|
typedef unsigned long stack_type;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static stack_type cond_stack = 0;
|
2001-05-30 13:12:34 +04:00
|
|
|
#define COND_PUSH(n) do {\
|
|
|
|
cond_stack = (cond_stack<<1)|((n)&1);\
|
2000-09-04 12:24:09 +04:00
|
|
|
} while(0)
|
2001-05-30 13:12:34 +04:00
|
|
|
#define COND_POP() do {\
|
2000-09-04 12:24:09 +04:00
|
|
|
cond_stack >>= 1;\
|
|
|
|
} while (0)
|
2001-05-30 13:12:34 +04:00
|
|
|
#define COND_LEXPOP() do {\
|
|
|
|
int last = COND_P();\
|
|
|
|
cond_stack >>= 1;\
|
|
|
|
if (last) cond_stack |= 1;\
|
|
|
|
} while (0)
|
|
|
|
#define COND_P() (cond_stack&1)
|
2000-09-04 12:24:09 +04:00
|
|
|
|
2001-01-29 08:10:42 +03:00
|
|
|
static stack_type cmdarg_stack = 0;
|
2001-05-30 13:12:34 +04:00
|
|
|
#define CMDARG_PUSH(n) do {\
|
|
|
|
cmdarg_stack = (cmdarg_stack<<1)|((n)&1);\
|
2001-01-26 08:02:19 +03:00
|
|
|
} while(0)
|
2001-05-30 13:12:34 +04:00
|
|
|
#define CMDARG_POP() do {\
|
|
|
|
cmdarg_stack >>= 1;\
|
|
|
|
} while (0)
|
|
|
|
#define CMDARG_LEXPOP() do {\
|
|
|
|
int last = CMDARG_P();\
|
2001-01-26 08:02:19 +03:00
|
|
|
cmdarg_stack >>= 1;\
|
2001-05-30 13:12:34 +04:00
|
|
|
if (last) cmdarg_stack |= 1;\
|
2001-01-26 08:02:19 +03:00
|
|
|
} while (0)
|
2001-05-30 13:12:34 +04:00
|
|
|
#define CMDARG_P() (cmdarg_stack&1)
|
2001-01-26 08:02:19 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int class_nest = 0;
|
|
|
|
static int in_single = 0;
|
2001-02-13 08:09:11 +03:00
|
|
|
static int in_def = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
static int compile_for_eval = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
static ID cur_mid = 0;
|
|
|
|
|
|
|
|
static NODE *cond();
|
|
|
|
static NODE *logop();
|
|
|
|
|
|
|
|
static NODE *newline_node();
|
|
|
|
static void fixpos();
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static int value_expr();
|
|
|
|
static void void_expr();
|
|
|
|
static void void_stmts();
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE *block_append();
|
|
|
|
static NODE *list_append();
|
|
|
|
static NODE *list_concat();
|
1999-08-13 09:45:20 +04:00
|
|
|
static NODE *arg_concat();
|
2001-05-30 13:12:34 +04:00
|
|
|
static NODE *arg_prepend();
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE *call_op();
|
|
|
|
static int in_defined = 0;
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
static NODE *ret_args();
|
1999-01-20 07:59:39 +03:00
|
|
|
static NODE *arg_blk_pass();
|
|
|
|
static NODE *new_call();
|
|
|
|
static NODE *new_fcall();
|
2000-06-23 11:05:59 +04:00
|
|
|
static NODE *new_super();
|
1999-01-20 07:59:39 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE *gettable();
|
|
|
|
static NODE *assignable();
|
|
|
|
static NODE *aryset();
|
|
|
|
static NODE *attrset();
|
1999-01-20 07:59:39 +03:00
|
|
|
static void rb_backref_error();
|
1999-08-13 09:45:20 +04:00
|
|
|
static NODE *node_assign();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static NODE *match_gen();
|
1998-01-16 15:13:05 +03:00
|
|
|
static void local_push();
|
|
|
|
static void local_pop();
|
1999-01-20 07:59:39 +03:00
|
|
|
static int local_append();
|
1998-01-16 15:13:05 +03:00
|
|
|
static int local_cnt();
|
|
|
|
static int local_id();
|
|
|
|
static ID *local_tbl();
|
2001-09-20 10:23:50 +04:00
|
|
|
static ID internal_id();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static struct RVarmap *dyna_push();
|
|
|
|
static void dyna_pop();
|
|
|
|
static int dyna_in_block();
|
|
|
|
|
|
|
|
static void top_local_init();
|
|
|
|
static void top_local_setup();
|
2001-05-30 13:12:34 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
NODE *node;
|
|
|
|
VALUE val;
|
|
|
|
ID id;
|
|
|
|
int num;
|
|
|
|
struct RVarmap *vars;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
%token kCLASS
|
|
|
|
kMODULE
|
|
|
|
kDEF
|
|
|
|
kUNDEF
|
|
|
|
kBEGIN
|
|
|
|
kRESCUE
|
|
|
|
kENSURE
|
|
|
|
kEND
|
|
|
|
kIF
|
|
|
|
kUNLESS
|
|
|
|
kTHEN
|
|
|
|
kELSIF
|
|
|
|
kELSE
|
|
|
|
kCASE
|
|
|
|
kWHEN
|
|
|
|
kWHILE
|
|
|
|
kUNTIL
|
|
|
|
kFOR
|
|
|
|
kBREAK
|
|
|
|
kNEXT
|
|
|
|
kREDO
|
|
|
|
kRETRY
|
|
|
|
kIN
|
|
|
|
kDO
|
2001-01-26 08:02:19 +03:00
|
|
|
kDO_COND
|
|
|
|
kDO_BLOCK
|
1998-01-16 15:19:22 +03:00
|
|
|
kRETURN
|
|
|
|
kYIELD
|
|
|
|
kSUPER
|
|
|
|
kSELF
|
|
|
|
kNIL
|
|
|
|
kTRUE
|
|
|
|
kFALSE
|
|
|
|
kAND
|
|
|
|
kOR
|
|
|
|
kNOT
|
|
|
|
kIF_MOD
|
|
|
|
kUNLESS_MOD
|
|
|
|
kWHILE_MOD
|
|
|
|
kUNTIL_MOD
|
1999-11-10 09:47:11 +03:00
|
|
|
kRESCUE_MOD
|
1998-01-16 15:19:22 +03:00
|
|
|
kALIAS
|
|
|
|
kDEFINED
|
|
|
|
klBEGIN
|
|
|
|
klEND
|
1999-01-20 07:59:39 +03:00
|
|
|
k__LINE__
|
|
|
|
k__FILE__
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR
|
1999-01-20 07:59:39 +03:00
|
|
|
%token <val> tINTEGER tFLOAT tSTRING tXSTRING tREGEXP
|
|
|
|
%token <node> tDSTRING tDXSTRING tDREGEXP tNTH_REF tBACK_REF
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-10-15 12:52:18 +04:00
|
|
|
%type <node> singleton string
|
1998-01-16 15:13:05 +03:00
|
|
|
%type <val> literal numeric
|
2001-01-20 17:02:28 +03:00
|
|
|
%type <node> compstmt stmts stmt expr arg primary command command_call method_call
|
2000-03-23 11:37:35 +03:00
|
|
|
%type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure
|
2001-05-30 13:12:34 +04:00
|
|
|
%type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args
|
2001-01-26 08:02:19 +03:00
|
|
|
%type <node> command_args aref_args opt_block_arg block_arg var_ref
|
|
|
|
%type <node> mrhs mrhs_basic superclass block_call block_command
|
1999-01-20 07:59:39 +03:00
|
|
|
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
|
2000-09-12 09:37:38 +04:00
|
|
|
%type <node> assoc_list assocs assoc undef_list backref
|
1999-08-13 09:45:20 +04:00
|
|
|
%type <node> block_var opt_block_var brace_block do_block lhs none
|
2000-03-09 12:04:36 +03:00
|
|
|
%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
|
1999-08-13 09:45:20 +04:00
|
|
|
%type <id> fitem variable sym symbol operation operation2 operation3
|
1999-01-20 07:59:39 +03:00
|
|
|
%type <id> cname fname op f_rest_arg
|
1999-08-13 09:45:20 +04:00
|
|
|
%type <num> f_norm_arg f_arg
|
1999-01-20 07:59:39 +03:00
|
|
|
%token tUPLUS /* unary+ */
|
|
|
|
%token tUMINUS /* unary- */
|
|
|
|
%token tPOW /* ** */
|
|
|
|
%token tCMP /* <=> */
|
|
|
|
%token tEQ /* == */
|
|
|
|
%token tEQQ /* === */
|
|
|
|
%token tNEQ /* != */
|
|
|
|
%token tGEQ /* >= */
|
|
|
|
%token tLEQ /* <= */
|
|
|
|
%token tANDOP tOROP /* && and || */
|
|
|
|
%token tMATCH tNMATCH /* =~ and !~ */
|
|
|
|
%token tDOT2 tDOT3 /* .. and ... */
|
|
|
|
%token tAREF tASET /* [] and []= */
|
|
|
|
%token tLSHFT tRSHFT /* << and >> */
|
|
|
|
%token tCOLON2 /* :: */
|
|
|
|
%token tCOLON3 /* :: at EXPR_BEG */
|
|
|
|
%token <id> tOP_ASGN /* +=, -= etc. */
|
|
|
|
%token tASSOC /* => */
|
|
|
|
%token tLPAREN /* ( */
|
2001-05-30 13:12:34 +04:00
|
|
|
%token tLPAREN_ARG /* ( */
|
2001-03-13 08:45:13 +03:00
|
|
|
%token tRPAREN /* ) */
|
1999-01-20 07:59:39 +03:00
|
|
|
%token tLBRACK /* [ */
|
|
|
|
%token tLBRACE /* { */
|
2001-05-30 13:12:34 +04:00
|
|
|
%token tLBRACE_ARG /* { */
|
1999-01-20 07:59:39 +03:00
|
|
|
%token tSTAR /* * */
|
|
|
|
%token tAMPER /* & */
|
|
|
|
%token tSYMBEG
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* precedence table
|
|
|
|
*/
|
|
|
|
|
1999-11-10 09:47:11 +03:00
|
|
|
%left kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD kRESCUE_MOD
|
1998-01-16 15:19:22 +03:00
|
|
|
%left kOR kAND
|
|
|
|
%right kNOT
|
|
|
|
%nonassoc kDEFINED
|
1999-01-20 07:59:39 +03:00
|
|
|
%right '=' tOP_ASGN
|
|
|
|
%right '?' ':'
|
|
|
|
%nonassoc tDOT2 tDOT3
|
|
|
|
%left tOROP
|
|
|
|
%left tANDOP
|
|
|
|
%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
|
|
|
%left '>' tGEQ '<' tLEQ
|
1998-01-16 15:13:05 +03:00
|
|
|
%left '|' '^'
|
|
|
|
%left '&'
|
1999-01-20 07:59:39 +03:00
|
|
|
%left tLSHFT tRSHFT
|
1998-01-16 15:13:05 +03:00
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/' '%'
|
1999-01-20 07:59:39 +03:00
|
|
|
%right '!' '~' tUPLUS tUMINUS
|
|
|
|
%right tPOW
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
%token LAST_TOKEN
|
|
|
|
|
|
|
|
%%
|
|
|
|
program : {
|
1999-01-20 07:59:39 +03:00
|
|
|
$<vars>$ = ruby_dyna_vars;
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
top_local_init();
|
1999-01-20 07:59:39 +03:00
|
|
|
if ((VALUE)ruby_class == rb_cObject) class_nest = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
else class_nest = 1;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree = block_append(ruby_eval_tree, $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
top_local_setup();
|
|
|
|
class_nest = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_dyna_vars = $<vars>1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt : stmts opt_terms
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
void_stmts($1);
|
|
|
|
$$ = $1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
stmts : none
|
1998-01-16 15:19:22 +03:00
|
|
|
| stmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = newline_node($1);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| stmts terms stmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = block_append($1, newline_node($3));
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| error stmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:02:28 +03:00
|
|
|
stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("alias within method");
|
|
|
|
$$ = NEW_ALIAS($2, $4);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| kALIAS tGVAR tGVAR
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("alias within method");
|
|
|
|
$$ = NEW_VALIAS($2, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| kALIAS tGVAR tBACK_REF
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
char buf[3];
|
|
|
|
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("alias within method");
|
|
|
|
sprintf(buf, "$%c", $3->nd_nth);
|
|
|
|
$$ = NEW_VALIAS($2, rb_intern(buf));
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| kALIAS tGVAR tNTH_REF
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
yyerror("can't make alias for the number variables");
|
|
|
|
$$ = 0;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kUNDEF undef_list
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("undef within method");
|
|
|
|
$$ = $2;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| stmt kIF_MOD expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_IF(cond($3), $1, 0);
|
|
|
|
fixpos($$, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| stmt kUNLESS_MOD expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_UNLESS(cond($3), $1, 0);
|
|
|
|
fixpos($$, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| stmt kWHILE_MOD expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
2001-03-13 08:45:13 +03:00
|
|
|
if ($1 && nd_type($1) == NODE_BEGIN) {
|
|
|
|
$$ = NEW_WHILE(cond($3), $1->nd_body, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-03-13 08:45:13 +03:00
|
|
|
$$ = NEW_WHILE(cond($3), $1, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| stmt kUNTIL_MOD expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
2001-03-13 08:45:13 +03:00
|
|
|
if ($1 && nd_type($1) == NODE_BEGIN) {
|
|
|
|
$$ = NEW_UNTIL(cond($3), $1->nd_body, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-03-13 08:45:13 +03:00
|
|
|
$$ = NEW_UNTIL(cond($3), $1, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-01 13:42:38 +04:00
|
|
|
| stmt kRESCUE_MOD stmt
|
1999-11-10 09:47:11 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| klBEGIN
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single) {
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("BEGIN in method");
|
|
|
|
}
|
|
|
|
local_push();
|
|
|
|
}
|
|
|
|
'{' compstmt '}'
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
|
1999-08-13 09:45:20 +04:00
|
|
|
NEW_PREEXE($4));
|
1998-01-16 15:19:22 +03:00
|
|
|
local_pop();
|
|
|
|
$$ = 0;
|
|
|
|
}
|
|
|
|
| klEND '{' compstmt '}'
|
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (compile_for_eval && (in_def || in_single)) {
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("END in method; use at_exit");
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = NEW_ITER(0, NEW_POSTEXE(), $3);
|
|
|
|
}
|
2001-01-20 17:02:28 +03:00
|
|
|
| lhs '=' command_call
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
value_expr($3);
|
|
|
|
$$ = node_assign($1, $3);
|
|
|
|
}
|
2001-01-20 17:02:28 +03:00
|
|
|
| mlhs '=' command_call
|
2000-08-31 09:29:54 +04:00
|
|
|
{
|
|
|
|
value_expr($3);
|
|
|
|
$1->nd_value = $3;
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2000-12-05 12:36:54 +03:00
|
|
|
| lhs '=' mrhs_basic
|
|
|
|
{
|
2001-06-23 19:14:28 +04:00
|
|
|
$$ = node_assign($1, NEW_REXPAND($3));
|
2000-12-05 12:36:54 +03:00
|
|
|
}
|
2001-05-07 13:26:29 +04:00
|
|
|
| mlhs '=' mrhs
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
|
|
|
$1->nd_value = $3;
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2001-05-07 13:26:29 +04:00
|
|
|
| expr
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
expr : kRETURN call_args
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (!compile_for_eval && !in_def && !in_single)
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("return appeared outside of method");
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = NEW_RETURN(ret_args($2));
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kBREAK call_args
|
2001-05-21 08:22:54 +04:00
|
|
|
{
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = NEW_BREAK(ret_args($2));
|
2001-05-21 08:22:54 +04:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kNEXT call_args
|
2001-05-21 08:22:54 +04:00
|
|
|
{
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = NEW_NEXT(ret_args($2));
|
2001-05-21 08:22:54 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| command_call
|
|
|
|
| expr kAND expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = logop(NODE_AND, $1, $3);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| expr kOR expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = logop(NODE_OR, $1, $3);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kNOT expr
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_NOT(cond($2));
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| '!' command_call
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_NOT(cond($2));
|
|
|
|
}
|
|
|
|
| arg
|
|
|
|
|
2001-01-20 17:02:28 +03:00
|
|
|
command_call : command
|
2001-01-26 08:02:19 +03:00
|
|
|
| block_command
|
2001-01-20 17:02:28 +03:00
|
|
|
|
2001-01-26 08:02:19 +03:00
|
|
|
block_command : block_call
|
|
|
|
| block_call '.' operation2 command_args
|
2001-01-20 17:02:28 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = new_call($1, $3, $4);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| block_call tCOLON2 operation2 command_args
|
2001-01-20 17:02:28 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = new_call($1, $3, $4);
|
|
|
|
}
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
command : operation command_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = new_fcall($1, $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| primary '.' operation2 command_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| primary tCOLON2 operation2 command_args
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
1998-01-16 15:19:22 +03:00
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| kSUPER command_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (!compile_for_eval && !in_def && !in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("super called outside of method");
|
2000-06-23 11:05:59 +04:00
|
|
|
$$ = new_super($2);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kYIELD call_args
|
2000-09-12 09:37:38 +04:00
|
|
|
{
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = NEW_YIELD(ret_args($2));
|
2000-09-12 09:37:38 +04:00
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
mlhs : mlhs_basic
|
|
|
|
| tLPAREN mlhs_entry ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlhs_entry : mlhs_basic
|
|
|
|
| tLPAREN mlhs_entry ')'
|
|
|
|
{
|
|
|
|
$$ = NEW_MASGN(NEW_LIST($2), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mlhs_basic : mlhs_head
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-03-09 12:04:36 +03:00
|
|
|
$$ = NEW_MASGN($1, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-03-09 12:04:36 +03:00
|
|
|
| mlhs_head mlhs_item
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-03-09 12:04:36 +03:00
|
|
|
$$ = NEW_MASGN(list_append($1,$2), 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-03-09 12:04:36 +03:00
|
|
|
| mlhs_head tSTAR mlhs_node
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-03-09 12:04:36 +03:00
|
|
|
$$ = NEW_MASGN($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-03-09 12:04:36 +03:00
|
|
|
| mlhs_head tSTAR
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2000-03-09 12:04:36 +03:00
|
|
|
$$ = NEW_MASGN($1, -1);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
| tSTAR mlhs_node
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_MASGN(0, $2);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| tSTAR
|
|
|
|
{
|
|
|
|
$$ = NEW_MASGN(0, -1);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
mlhs_item : mlhs_node
|
1999-01-20 07:59:39 +03:00
|
|
|
| tLPAREN mlhs_entry ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlhs_head : mlhs_item ','
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_LIST($1);
|
|
|
|
}
|
2000-03-09 12:04:36 +03:00
|
|
|
| mlhs_head mlhs_item ','
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-03-09 12:04:36 +03:00
|
|
|
$$ = list_append($1, $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
mlhs_node : variable
|
|
|
|
{
|
|
|
|
$$ = assignable($1, 0);
|
|
|
|
}
|
|
|
|
| primary '[' aref_args ']'
|
|
|
|
{
|
|
|
|
$$ = aryset($1, $3);
|
|
|
|
}
|
|
|
|
| primary '.' tIDENTIFIER
|
|
|
|
{
|
|
|
|
$$ = attrset($1, $3);
|
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
| primary tCOLON2 tIDENTIFIER
|
|
|
|
{
|
|
|
|
$$ = attrset($1, $3);
|
|
|
|
}
|
2000-05-09 08:53:16 +04:00
|
|
|
| primary '.' tCONSTANT
|
|
|
|
{
|
|
|
|
$$ = attrset($1, $3);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| backref
|
|
|
|
{
|
|
|
|
rb_backref_error($1);
|
|
|
|
$$ = 0;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
lhs : variable
|
|
|
|
{
|
|
|
|
$$ = assignable($1, 0);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '[' aref_args ']'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = aryset($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '.' tIDENTIFIER
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = attrset($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
| primary tCOLON2 tIDENTIFIER
|
|
|
|
{
|
|
|
|
$$ = attrset($1, $3);
|
|
|
|
}
|
2000-05-09 08:53:16 +04:00
|
|
|
| primary '.' tCONSTANT
|
|
|
|
{
|
|
|
|
$$ = attrset($1, $3);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
| backref
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_backref_error($1);
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = 0;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
cname : tIDENTIFIER
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
yyerror("class/module name must be CONSTANT");
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tCONSTANT
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
fname : tIDENTIFIER
|
|
|
|
| tCONSTANT
|
|
|
|
| tFID
|
1998-01-16 15:13:05 +03:00
|
|
|
| op
|
|
|
|
{
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
$$ = $1;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| reswords
|
|
|
|
{
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
$$ = $<id>1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
fitem : fname
|
|
|
|
| symbol
|
|
|
|
|
|
|
|
undef_list : fitem
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_UNDEF($1);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| undef_list ',' {lex_state = EXPR_FNAME;} fitem
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = block_append($1, NEW_UNDEF($4));
|
|
|
|
}
|
|
|
|
|
2000-01-08 08:00:25 +03:00
|
|
|
op : '|' { $$ = '|'; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '^' { $$ = '^'; }
|
|
|
|
| '&' { $$ = '&'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tCMP { $$ = tCMP; }
|
|
|
|
| tEQ { $$ = tEQ; }
|
|
|
|
| tEQQ { $$ = tEQQ; }
|
|
|
|
| tMATCH { $$ = tMATCH; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '>' { $$ = '>'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tGEQ { $$ = tGEQ; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '<' { $$ = '<'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tLEQ { $$ = tLEQ; }
|
|
|
|
| tLSHFT { $$ = tLSHFT; }
|
|
|
|
| tRSHFT { $$ = tRSHFT; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '+' { $$ = '+'; }
|
|
|
|
| '-' { $$ = '-'; }
|
|
|
|
| '*' { $$ = '*'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tSTAR { $$ = '*'; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '/' { $$ = '/'; }
|
|
|
|
| '%' { $$ = '%'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tPOW { $$ = tPOW; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '~' { $$ = '~'; }
|
1999-01-20 07:59:39 +03:00
|
|
|
| tUPLUS { $$ = tUPLUS; }
|
|
|
|
| tUMINUS { $$ = tUMINUS; }
|
|
|
|
| tAREF { $$ = tAREF; }
|
|
|
|
| tASET { $$ = tASET; }
|
1998-01-16 15:13:05 +03:00
|
|
|
| '`' { $$ = '`'; }
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
|
1999-01-20 07:59:39 +03:00
|
|
|
| kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF
|
|
|
|
| kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
|
|
|
|
| kFOR | kIF_MOD | kIN | kMODULE | kNEXT | kNIL | kNOT
|
|
|
|
| kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER
|
|
|
|
| kTHEN | kTRUE | kUNDEF | kUNLESS_MOD | kUNTIL_MOD | kWHEN
|
1999-11-10 09:47:11 +03:00
|
|
|
| kWHILE_MOD | kYIELD | kRESCUE_MOD
|
1999-01-20 07:59:39 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
arg : lhs '=' arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = node_assign($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| variable tOP_ASGN {$$ = assignable($1, 0);} arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if ($2 == tOROP) {
|
|
|
|
$<node>3->nd_value = $4;
|
|
|
|
$$ = NEW_OP_ASGN_OR(gettable($1), $<node>3);
|
2001-05-07 13:26:29 +04:00
|
|
|
if (is_instance_id($1)) {
|
|
|
|
$$->nd_aid = $1;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else if ($2 == tANDOP) {
|
|
|
|
$<node>3->nd_value = $4;
|
|
|
|
$$ = NEW_OP_ASGN_AND(gettable($1), $<node>3);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$$ = $<node>3;
|
1999-09-16 20:11:25 +04:00
|
|
|
if ($$) {
|
|
|
|
$$->nd_value = call_op(gettable($1),$2,1,$4);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
fixpos($$, $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '[' aref_args ']' tOP_ASGN arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-10-02 08:31:23 +04:00
|
|
|
NODE *tmp, *args = NEW_LIST($6);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-09-26 21:09:47 +04:00
|
|
|
$3 = list_append($3, NEW_NIL());
|
1998-01-16 15:13:05 +03:00
|
|
|
list_concat(args, $3);
|
1999-01-20 07:59:39 +03:00
|
|
|
if ($5 == tOROP) {
|
|
|
|
$5 = 0;
|
|
|
|
}
|
|
|
|
else if ($5 == tANDOP) {
|
|
|
|
$5 = 1;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
$$ = NEW_OP_ASGN1($1, $5, args);
|
|
|
|
fixpos($$, $1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '.' tIDENTIFIER tOP_ASGN arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if ($4 == tOROP) {
|
|
|
|
$4 = 0;
|
|
|
|
}
|
|
|
|
else if ($4 == tANDOP) {
|
|
|
|
$4 = 1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
|
1998-01-16 15:19:22 +03:00
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '.' tCONSTANT tOP_ASGN arg
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if ($4 == tOROP) {
|
|
|
|
$4 = 0;
|
|
|
|
}
|
|
|
|
else if ($4 == tANDOP) {
|
|
|
|
$4 = 1;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
|
|
|
|
fixpos($$, $1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
| primary tCOLON2 tIDENTIFIER tOP_ASGN arg
|
|
|
|
{
|
|
|
|
if ($4 == tOROP) {
|
|
|
|
$4 = 0;
|
|
|
|
}
|
|
|
|
else if ($4 == tANDOP) {
|
|
|
|
$4 = 1;
|
|
|
|
}
|
|
|
|
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
|
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| backref tOP_ASGN arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_backref_error($1);
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = 0;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tDOT2 arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_DOT2($1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tDOT3 arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_DOT3($1, $3);
|
|
|
|
}
|
|
|
|
| arg '+' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '+', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '-' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '-', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '*' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '*', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '/' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '/', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '%' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '%', 1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tPOW arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-11-13 08:39:35 +03:00
|
|
|
int need_negate = Qfalse;
|
|
|
|
|
|
|
|
if (nd_type($1) == NODE_LIT) {
|
|
|
|
|
|
|
|
switch (TYPE($1->nd_lit)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_BIGNUM:
|
|
|
|
if (RTEST(rb_funcall($1->nd_lit,'<',1,INT2FIX(0)))) {
|
|
|
|
$1->nd_lit = rb_funcall($1->nd_lit,rb_intern("-@"),0,0);
|
|
|
|
need_negate = Qtrue;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tPOW, 1, $3);
|
2000-11-13 08:39:35 +03:00
|
|
|
if (need_negate) {
|
|
|
|
$$ = call_op($$, tUMINUS, 0, 0);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tUPLUS arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-01-05 07:41:21 +03:00
|
|
|
if ($2 && nd_type($2) == NODE_LIT) {
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
else {
|
1999-12-14 09:50:43 +03:00
|
|
|
$$ = call_op($2, tUPLUS, 0, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tUMINUS arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-01-05 07:41:21 +03:00
|
|
|
if ($2 && nd_type($2) == NODE_LIT && FIXNUM_P($2->nd_lit)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
long i = FIX2LONG($2->nd_lit);
|
|
|
|
|
|
|
|
$2->nd_lit = INT2FIX(-i);
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
else {
|
1999-12-14 09:50:43 +03:00
|
|
|
$$ = call_op($2, tUMINUS, 0, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
| arg '|' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '|', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '^' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '^', 1, $3);
|
|
|
|
}
|
|
|
|
| arg '&' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '&', 1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tCMP arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tCMP, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
| arg '>' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '>', 1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tGEQ arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tGEQ, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
| arg '<' arg
|
|
|
|
{
|
|
|
|
$$ = call_op($1, '<', 1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tLEQ arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tLEQ, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tEQ arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tEQ, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tEQQ arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tEQQ, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tNEQ arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_NOT(call_op($1, tEQ, 1, $3));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tMATCH arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
$$ = match_gen($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tNMATCH arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
$$ = NEW_NOT(match_gen($1, $3));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
| '!' arg
|
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_NOT(cond($2));
|
|
|
|
}
|
|
|
|
| '~' arg
|
|
|
|
{
|
1999-12-14 09:50:43 +03:00
|
|
|
$$ = call_op($2, '~', 0, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tLSHFT arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tLSHFT, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tRSHFT arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = call_op($1, tRSHFT, 1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tANDOP arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = logop(NODE_AND, $1, $3);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg tOROP arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = logop(NODE_OR, $1, $3);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kDEFINED opt_nl {in_defined = 1;} arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
in_defined = 0;
|
|
|
|
$$ = NEW_DEFINED($4);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| arg '?' arg ':' arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = NEW_IF(cond($1), $3, $5);
|
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
| primary
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:46:36 +04:00
|
|
|
aref_args : none
|
2001-05-07 13:26:29 +04:00
|
|
|
| command opt_nl
|
2000-07-21 12:45:34 +04:00
|
|
|
{
|
|
|
|
$$ = NEW_LIST($1);
|
|
|
|
}
|
2000-09-04 12:24:09 +04:00
|
|
|
| args trailer
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2000-07-03 09:46:36 +04:00
|
|
|
| args ',' tSTAR arg opt_nl
|
|
|
|
{
|
|
|
|
value_expr($4);
|
|
|
|
$$ = arg_concat($1, $4);
|
|
|
|
}
|
2000-09-04 12:24:09 +04:00
|
|
|
| assocs trailer
|
2000-07-07 07:20:53 +04:00
|
|
|
{
|
|
|
|
$$ = NEW_LIST(NEW_HASH($1));
|
|
|
|
}
|
2000-07-03 09:46:36 +04:00
|
|
|
| tSTAR arg opt_nl
|
|
|
|
{
|
|
|
|
value_expr($2);
|
2001-06-08 18:20:58 +04:00
|
|
|
$$ = NEW_RESTARY($2);
|
2000-07-03 09:46:36 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2001-01-23 11:08:59 +03:00
|
|
|
paren_args : '(' none ')'
|
2000-09-01 13:18:11 +04:00
|
|
|
{
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = $2;
|
2000-09-01 13:18:11 +04:00
|
|
|
}
|
2001-01-23 11:08:59 +03:00
|
|
|
| '(' call_args opt_nl ')'
|
2000-09-04 12:24:09 +04:00
|
|
|
{
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = $2;
|
2000-09-04 12:24:09 +04:00
|
|
|
}
|
2001-01-23 11:08:59 +03:00
|
|
|
| '(' block_call opt_nl ')'
|
|
|
|
{
|
|
|
|
$$ = NEW_LIST($2);
|
|
|
|
}
|
|
|
|
| '(' args ',' block_call opt_nl ')'
|
|
|
|
{
|
|
|
|
$$ = list_append($2, $4);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt_paren_args : none
|
|
|
|
| paren_args
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-01-20 17:02:28 +03:00
|
|
|
call_args : command
|
2000-07-01 10:51:28 +04:00
|
|
|
{
|
|
|
|
$$ = NEW_LIST($1);
|
2001-01-20 17:02:28 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| args opt_block_arg
|
|
|
|
{
|
|
|
|
$$ = arg_blk_pass($1, $2);
|
|
|
|
}
|
|
|
|
| args ',' tSTAR arg opt_block_arg
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2000-07-03 09:46:36 +04:00
|
|
|
value_expr($4);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = arg_concat($1, $4);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass($$, $5);
|
2001-01-20 17:02:28 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| assocs opt_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_LIST(NEW_HASH($1));
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass($$, $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| assocs ',' tSTAR arg opt_block_arg
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2000-07-03 09:46:36 +04:00
|
|
|
value_expr($4);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass($$, $5);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| args ',' assocs opt_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = list_append($1, NEW_HASH($3));
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass($$, $4);
|
2001-01-20 17:02:28 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| args ',' assocs ',' tSTAR arg opt_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-07-03 09:46:36 +04:00
|
|
|
value_expr($6);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = arg_concat(list_append($1, NEW_HASH($3)), $6);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass($$, $7);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tSTAR arg opt_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = arg_blk_pass(NEW_RESTARGS($2), $3);
|
|
|
|
}
|
|
|
|
| block_arg
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
call_args2 : arg ',' args opt_block_arg
|
|
|
|
{
|
2001-06-01 11:52:34 +04:00
|
|
|
$$ = arg_blk_pass(list_concat(NEW_LIST($1),$3), $4);
|
2001-05-30 13:12:34 +04:00
|
|
|
}
|
|
|
|
| arg ',' tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
value_expr($4);
|
|
|
|
$$ = arg_concat(NEW_LIST($1), $4);
|
|
|
|
$$ = arg_blk_pass($$, $5);
|
|
|
|
}
|
|
|
|
| arg ',' args ',' tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
value_expr($6);
|
2001-06-01 11:52:34 +04:00
|
|
|
$$ = arg_concat(list_concat($1,$3), $6);
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = arg_blk_pass($$, $7);
|
|
|
|
}
|
|
|
|
| assocs opt_block_arg
|
|
|
|
{
|
|
|
|
$$ = NEW_LIST(NEW_HASH($1));
|
|
|
|
$$ = arg_blk_pass($$, $2);
|
|
|
|
}
|
|
|
|
| assocs ',' tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($4);
|
|
|
|
$$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
|
|
|
|
$$ = arg_blk_pass($$, $5);
|
|
|
|
}
|
|
|
|
| arg ',' assocs opt_block_arg
|
|
|
|
{
|
|
|
|
$$ = list_append(NEW_LIST($1), NEW_HASH($3));
|
|
|
|
$$ = arg_blk_pass($$, $4);
|
|
|
|
}
|
|
|
|
| arg ',' args ',' assocs opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
value_expr($6);
|
2001-06-01 11:52:34 +04:00
|
|
|
$$ = list_append(list_concat($1,$3), NEW_HASH($5));
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = arg_blk_pass($$, $6);
|
|
|
|
}
|
|
|
|
| arg ',' assocs ',' tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
value_expr($6);
|
|
|
|
$$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6);
|
|
|
|
$$ = arg_blk_pass($$, $7);
|
|
|
|
}
|
|
|
|
| arg ',' args ',' assocs ',' tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
value_expr($8);
|
2001-06-01 11:52:34 +04:00
|
|
|
$$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8);
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = arg_blk_pass($$, $9);
|
|
|
|
}
|
|
|
|
| tSTAR arg opt_block_arg
|
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = arg_blk_pass(NEW_RESTARGS($2), $3);
|
|
|
|
}
|
|
|
|
| block_arg
|
|
|
|
|
|
|
|
command_args : {
|
|
|
|
$<num>$ = cmdarg_stack;
|
|
|
|
CMDARG_PUSH(1);
|
|
|
|
}
|
|
|
|
open_args
|
|
|
|
{
|
|
|
|
/* CMDARG_POP() */
|
|
|
|
cmdarg_stack = $<num>1;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
open_args : call_args
|
2001-07-02 12:46:28 +04:00
|
|
|
| tLPAREN_ARG {lex_state = EXPR_ENDARG;} ')'
|
2001-05-30 13:12:34 +04:00
|
|
|
{
|
|
|
|
rb_warning("%s (...) interpreted as method call",
|
2001-07-02 12:46:28 +04:00
|
|
|
rb_id2name($<id>1));
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = 0;
|
|
|
|
}
|
2001-06-01 10:47:32 +04:00
|
|
|
| tLPAREN_ARG call_args2 {lex_state = EXPR_ENDARG;} ')'
|
2001-01-26 08:02:19 +03:00
|
|
|
{
|
2001-05-30 13:12:34 +04:00
|
|
|
rb_warning("%s (...) interpreted as method call",
|
2001-07-02 12:46:28 +04:00
|
|
|
rb_id2name($<id>1));
|
2001-01-26 08:02:19 +03:00
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
block_arg : tAMPER arg
|
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_BLOCK_PASS($2);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt_block_arg : ',' block_arg
|
|
|
|
{
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = $2;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| none
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
args : arg
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = NEW_LIST($1);
|
|
|
|
}
|
|
|
|
| args ',' arg
|
|
|
|
{
|
|
|
|
value_expr($3);
|
|
|
|
$$ = list_append($1, $3);
|
|
|
|
}
|
|
|
|
|
2000-12-05 12:36:54 +03:00
|
|
|
mrhs : arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-12-05 12:36:54 +03:00
|
|
|
value_expr($1);
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| mrhs_basic
|
2001-06-22 13:12:24 +04:00
|
|
|
{
|
2001-06-23 19:14:28 +04:00
|
|
|
$$ = NEW_REXPAND($1);
|
2001-06-22 13:12:24 +04:00
|
|
|
}
|
2000-12-05 12:36:54 +03:00
|
|
|
|
|
|
|
mrhs_basic : args ',' arg
|
|
|
|
{
|
2000-12-22 06:22:25 +03:00
|
|
|
value_expr($3);
|
2000-12-05 12:36:54 +03:00
|
|
|
$$ = list_append($1, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| args ',' tSTAR arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
value_expr($4);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = arg_concat($1, $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tSTAR arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
2001-06-22 13:12:24 +04:00
|
|
|
$$ = $2;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
primary : literal
|
|
|
|
{
|
|
|
|
$$ = NEW_LIT($1);
|
|
|
|
}
|
1999-10-15 12:52:18 +04:00
|
|
|
| string
|
1999-01-20 07:59:39 +03:00
|
|
|
| tXSTRING
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_XSTR($1);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tDXSTRING
|
|
|
|
| tDREGEXP
|
1998-01-16 15:13:05 +03:00
|
|
|
| var_ref
|
|
|
|
| backref
|
2000-02-01 06:12:21 +03:00
|
|
|
| tFID
|
|
|
|
{
|
|
|
|
$$ = NEW_VCALL($1);
|
|
|
|
}
|
|
|
|
| kBEGIN
|
|
|
|
compstmt
|
|
|
|
rescue
|
|
|
|
opt_else
|
|
|
|
ensure
|
|
|
|
kEND
|
|
|
|
{
|
|
|
|
if (!$3 && !$4 && !$5)
|
|
|
|
$$ = NEW_BEGIN($2);
|
|
|
|
else {
|
|
|
|
if ($3) $2 = NEW_RESCUE($2, $3, $4);
|
|
|
|
else if ($4) {
|
|
|
|
rb_warn("else without rescue is useless");
|
|
|
|
$2 = block_append($2, $4);
|
|
|
|
}
|
|
|
|
if ($5) $2 = NEW_ENSURE($2, $5);
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2001-06-01 10:47:32 +04:00
|
|
|
| tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} ')'
|
2001-05-30 13:12:34 +04:00
|
|
|
{
|
2001-08-23 10:02:15 +04:00
|
|
|
rb_warning("%s (...) interpreted as grouped expression", rb_id2name($<id>1));
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = $2;
|
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
| tLPAREN compstmt ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| primary tCOLON2 tCONSTANT
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = NEW_COLON2($1, $3);
|
|
|
|
}
|
|
|
|
| tCOLON3 cname
|
|
|
|
{
|
|
|
|
$$ = NEW_COLON3($2);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| primary '[' aref_args ']'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_CALL($1, tAREF, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-09-12 09:37:38 +04:00
|
|
|
| tLBRACK aref_args ']'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-06-07 12:29:59 +04:00
|
|
|
if ($2 == 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = NEW_ZARRAY(); /* zero length array*/
|
2001-06-07 12:29:59 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
else {
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tLBRACE assoc_list '}'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_HASH($2);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kRETURN
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (!compile_for_eval && !in_def && !in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("return appeared outside of method");
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_RETURN(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kYIELD '(' call_args ')'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($3);
|
2001-05-30 13:12:34 +04:00
|
|
|
$$ = NEW_YIELD(ret_args($3));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kYIELD '(' ')'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_YIELD(0);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kYIELD
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_YIELD(0);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kDEFINED opt_nl '(' {in_defined = 1;} expr ')'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
in_defined = 0;
|
|
|
|
$$ = NEW_DEFINED($5);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| operation brace_block
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$2->nd_iter = NEW_FCALL($1, 0);
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| method_call
|
1999-08-13 09:45:20 +04:00
|
|
|
| method_call brace_block
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
|
|
|
|
rb_compile_error("both block arg and actual block given");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
$2->nd_iter = $1;
|
|
|
|
$$ = $2;
|
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kIF expr then
|
|
|
|
compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
if_tail
|
1998-01-16 15:19:22 +03:00
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_IF(cond($2), $4, $5);
|
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kUNLESS expr then
|
|
|
|
compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
opt_else
|
1998-01-16 15:19:22 +03:00
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_UNLESS(cond($2), $4, $5);
|
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kWHILE {COND_PUSH(1);} expr do {COND_POP();}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
value_expr($3);
|
|
|
|
$$ = NEW_WHILE(cond($3), $6, 1);
|
|
|
|
fixpos($$, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kUNTIL {COND_PUSH(1);} expr do {COND_POP();}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
value_expr($3);
|
|
|
|
$$ = NEW_UNTIL(cond($3), $6, 1);
|
|
|
|
fixpos($$, $3);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-12-18 12:46:21 +03:00
|
|
|
| kCASE expr opt_terms
|
1998-01-16 15:13:05 +03:00
|
|
|
case_body
|
1998-01-16 15:19:22 +03:00
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
2000-12-18 12:46:21 +03:00
|
|
|
$$ = NEW_CASE($2, $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2000-12-18 12:46:21 +03:00
|
|
|
| kCASE opt_terms case_body kEND
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| kFOR block_var kIN {COND_PUSH(1);} expr do {COND_POP();}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-12-05 12:36:54 +03:00
|
|
|
value_expr($5);
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = NEW_FOR($2, $5, $8);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kCLASS cname superclass
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("class definition in method body");
|
|
|
|
class_nest++;
|
|
|
|
local_push();
|
2000-09-22 22:15:52 +04:00
|
|
|
$<num>$ = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_CLASS($2, $5, $3);
|
2000-09-22 22:15:52 +04:00
|
|
|
nd_set_line($$, $<num>4);
|
1998-01-16 15:13:05 +03:00
|
|
|
local_pop();
|
|
|
|
class_nest--;
|
|
|
|
}
|
2001-02-26 08:29:06 +03:00
|
|
|
| kCLASS tLSHFT expr
|
|
|
|
{
|
|
|
|
$<num>$ = in_def;
|
|
|
|
in_def = 0;
|
|
|
|
}
|
|
|
|
term
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
$<num>$ = in_single;
|
|
|
|
in_single = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
class_nest++;
|
|
|
|
local_push();
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
$$ = NEW_SCLASS($3, $7);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $3);
|
|
|
|
local_pop();
|
|
|
|
class_nest--;
|
2001-02-26 08:29:06 +03:00
|
|
|
in_def = $<num>4;
|
|
|
|
in_single = $<num>6;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kMODULE cname
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("module definition in method body");
|
|
|
|
class_nest++;
|
|
|
|
local_push();
|
2000-09-22 22:15:52 +04:00
|
|
|
$<num>$ = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_MODULE($2, $4);
|
2000-09-22 22:15:52 +04:00
|
|
|
nd_set_line($$, $<num>3);
|
1998-01-16 15:13:05 +03:00
|
|
|
local_pop();
|
|
|
|
class_nest--;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kDEF fname
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("nested method definition");
|
2001-02-13 08:09:11 +03:00
|
|
|
$<id>$ = cur_mid;
|
1998-01-16 15:13:05 +03:00
|
|
|
cur_mid = $2;
|
2001-02-13 08:09:11 +03:00
|
|
|
in_def++;
|
1998-01-16 15:13:05 +03:00
|
|
|
local_push();
|
|
|
|
}
|
|
|
|
f_arglist
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
1999-10-13 10:44:42 +04:00
|
|
|
rescue
|
|
|
|
opt_else
|
|
|
|
ensure
|
1998-01-16 15:19:22 +03:00
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-10-13 10:44:42 +04:00
|
|
|
if ($6) $5 = NEW_RESCUE($5, $6, $7);
|
|
|
|
else if ($7) {
|
|
|
|
rb_warn("else without rescue is useless");
|
|
|
|
$5 = block_append($5, $7);
|
|
|
|
}
|
|
|
|
if ($8) $5 = NEW_ENSURE($5, $8);
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
/* NOEX_PRIVATE for toplevel */
|
2000-05-01 13:42:38 +04:00
|
|
|
$$ = NEW_DEFN($2, $4, $5, class_nest?NOEX_PUBLIC:NOEX_PRIVATE);
|
2000-10-11 10:29:16 +04:00
|
|
|
if (is_attrset_id($2)) $$->nd_noex = NOEX_PUBLIC;
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $4);
|
|
|
|
local_pop();
|
2001-02-13 08:09:11 +03:00
|
|
|
in_def--;
|
|
|
|
cur_mid = $<id>3;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
in_single++;
|
|
|
|
local_push();
|
|
|
|
lex_state = EXPR_END; /* force for args */
|
|
|
|
}
|
|
|
|
f_arglist
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
2001-03-06 11:17:54 +03:00
|
|
|
rescue
|
|
|
|
opt_else
|
|
|
|
ensure
|
1998-01-16 15:19:22 +03:00
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-03-06 11:17:54 +03:00
|
|
|
if ($9) $8 = NEW_RESCUE($8, $9, $10);
|
|
|
|
else if ($10) {
|
|
|
|
rb_warn("else without rescue is useless");
|
|
|
|
$8 = block_append($8, $10);
|
|
|
|
}
|
|
|
|
if ($11) $8 = NEW_ENSURE($8, $11);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = NEW_DEFS($2, $5, $7, $8);
|
|
|
|
fixpos($$, $2);
|
|
|
|
local_pop();
|
|
|
|
in_single--;
|
|
|
|
}
|
2001-05-22 12:28:11 +04:00
|
|
|
| kBREAK
|
|
|
|
{
|
|
|
|
$$ = NEW_BREAK(0);
|
|
|
|
}
|
|
|
|
| kNEXT
|
|
|
|
{
|
|
|
|
$$ = NEW_NEXT(0);
|
|
|
|
}
|
|
|
|
| kREDO
|
|
|
|
{
|
|
|
|
$$ = NEW_REDO();
|
|
|
|
}
|
|
|
|
| kRETRY
|
|
|
|
{
|
|
|
|
$$ = NEW_RETRY();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
then : term
|
1998-01-16 15:19:22 +03:00
|
|
|
| kTHEN
|
|
|
|
| term kTHEN
|
|
|
|
|
|
|
|
do : term
|
2001-01-26 08:02:19 +03:00
|
|
|
| kDO_COND
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if_tail : opt_else
|
1998-01-16 15:19:22 +03:00
|
|
|
| kELSIF expr then
|
|
|
|
compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
if_tail
|
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_IF(cond($2), $4, $5);
|
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
opt_else : none
|
1998-01-16 15:19:22 +03:00
|
|
|
| kELSE compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
block_var : lhs
|
1998-01-16 15:13:05 +03:00
|
|
|
| mlhs
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
opt_block_var : none
|
1999-01-20 07:59:39 +03:00
|
|
|
| '|' /* none */ '|'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-12-05 12:36:54 +03:00
|
|
|
$$ = (NODE*)1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tOROP
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-12-05 12:36:54 +03:00
|
|
|
$$ = (NODE*)1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| '|' block_var '|'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2000-10-16 13:13:20 +04:00
|
|
|
|
2001-01-26 08:02:19 +03:00
|
|
|
do_block : kDO_BLOCK
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$<vars>$ = dyna_push();
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
opt_block_var
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
|
|
|
kEND
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = NEW_ITER($3, 0, $4);
|
|
|
|
fixpos($$, $3?$3:$4);
|
|
|
|
dyna_pop($<vars>2);
|
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
| tLBRACE_ARG {$<vars>$ = dyna_push();}
|
|
|
|
opt_block_var
|
|
|
|
compstmt
|
|
|
|
'}'
|
|
|
|
{
|
|
|
|
$$ = NEW_ITER($3, 0, $4);
|
|
|
|
fixpos($$, $3?$3:$4);
|
|
|
|
dyna_pop($<vars>2);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-01-26 08:02:19 +03:00
|
|
|
block_call : command do_block
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
|
|
|
|
rb_compile_error("both block arg and actual block given");
|
|
|
|
}
|
|
|
|
$2->nd_iter = $1;
|
|
|
|
$$ = $2;
|
|
|
|
fixpos($$, $2);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| block_call '.' operation2 opt_paren_args
|
2001-01-20 17:02:28 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
2001-01-20 17:02:28 +03:00
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
| block_call tCOLON2 operation2 opt_paren_args
|
2001-01-20 17:02:28 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
2001-01-20 17:02:28 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2001-01-23 11:08:59 +03:00
|
|
|
method_call : operation paren_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_fcall($1, $2);
|
|
|
|
fixpos($$, $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-01-23 11:08:59 +03:00
|
|
|
| primary '.' operation2 opt_paren_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
1999-01-20 07:59:39 +03:00
|
|
|
fixpos($$, $1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-01-23 11:08:59 +03:00
|
|
|
| primary tCOLON2 operation2 paren_args
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr($1);
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_call($1, $3, $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
fixpos($$, $1);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| primary tCOLON2 operation3
|
|
|
|
{
|
|
|
|
value_expr($1);
|
|
|
|
$$ = new_call($1, $3, 0);
|
|
|
|
}
|
2001-01-23 11:08:59 +03:00
|
|
|
| kSUPER paren_args
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (!compile_for_eval && !in_def &&
|
1999-08-13 09:45:20 +04:00
|
|
|
!in_single && !in_defined)
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("super called outside of method");
|
2001-01-23 11:08:59 +03:00
|
|
|
$$ = new_super($2);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
| kSUPER
|
|
|
|
{
|
2001-02-13 08:09:11 +03:00
|
|
|
if (!compile_for_eval && !in_def &&
|
1999-08-13 09:45:20 +04:00
|
|
|
!in_single && !in_defined)
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("super called outside of method");
|
|
|
|
$$ = NEW_ZSUPER();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-01-26 08:02:19 +03:00
|
|
|
brace_block : '{'
|
|
|
|
{
|
|
|
|
$<vars>$ = dyna_push();
|
|
|
|
}
|
|
|
|
opt_block_var
|
|
|
|
compstmt '}'
|
|
|
|
{
|
|
|
|
$$ = NEW_ITER($3, 0, $4);
|
|
|
|
fixpos($$, $4);
|
|
|
|
dyna_pop($<vars>2);
|
|
|
|
}
|
|
|
|
| kDO
|
|
|
|
{
|
|
|
|
$<vars>$ = dyna_push();
|
|
|
|
}
|
|
|
|
opt_block_var
|
|
|
|
compstmt kEND
|
|
|
|
{
|
|
|
|
$$ = NEW_ITER($3, 0, $4);
|
|
|
|
fixpos($$, $4);
|
|
|
|
dyna_pop($<vars>2);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
case_body : kWHEN when_args then
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
cases
|
|
|
|
{
|
|
|
|
$$ = NEW_WHEN($2, $4, $5);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
when_args : args
|
|
|
|
| args ',' tSTAR arg
|
|
|
|
{
|
|
|
|
value_expr($4);
|
|
|
|
$$ = list_append($1, NEW_WHEN($4, 0, 0));
|
|
|
|
}
|
|
|
|
| tSTAR arg
|
|
|
|
{
|
|
|
|
value_expr($2);
|
|
|
|
$$ = NEW_LIST(NEW_WHEN($2, 0, 0));
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
cases : opt_else
|
|
|
|
| case_body
|
|
|
|
|
2000-05-30 08:24:17 +04:00
|
|
|
exc_list : none
|
|
|
|
| args
|
2000-03-23 11:37:35 +03:00
|
|
|
|
2000-05-30 08:24:17 +04:00
|
|
|
exc_var : tASSOC lhs
|
2000-03-23 11:37:35 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| none
|
|
|
|
|
2000-05-30 08:24:17 +04:00
|
|
|
rescue : kRESCUE exc_list exc_var then
|
1998-01-16 15:19:22 +03:00
|
|
|
compstmt
|
1999-01-20 07:59:39 +03:00
|
|
|
rescue
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-04 12:24:09 +04:00
|
|
|
if ($3) {
|
2000-03-23 11:37:35 +03:00
|
|
|
$3 = node_assign($3, NEW_GVAR(rb_intern("$!")));
|
|
|
|
$5 = block_append($3, $5);
|
|
|
|
}
|
|
|
|
$$ = NEW_RESBODY($2, $5, $6);
|
|
|
|
fixpos($$, $2?$2:$5);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| none
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
ensure : none
|
1998-01-16 15:19:22 +03:00
|
|
|
| kENSURE compstmt
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-09-18 12:47:10 +04:00
|
|
|
if ($2)
|
|
|
|
$$ = $2;
|
|
|
|
else
|
|
|
|
/* place holder */
|
|
|
|
$$ = NEW_NIL();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
literal : numeric
|
1999-08-13 09:45:20 +04:00
|
|
|
| symbol
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-03-07 11:37:59 +03:00
|
|
|
$$ = ID2SYM($1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| tREGEXP
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-10-15 12:52:18 +04:00
|
|
|
string : tSTRING
|
|
|
|
{
|
|
|
|
$$ = NEW_STR($1);
|
|
|
|
}
|
|
|
|
| tDSTRING
|
|
|
|
| string tSTRING
|
|
|
|
{
|
|
|
|
if (nd_type($1) == NODE_DSTR) {
|
|
|
|
list_append($1, NEW_STR($2));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_concat($1->nd_lit, $2);
|
|
|
|
}
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| string tDSTRING
|
|
|
|
{
|
|
|
|
if (nd_type($1) == NODE_STR) {
|
|
|
|
$$ = NEW_DSTR($1->nd_lit);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
$2->nd_head = NEW_STR($2->nd_lit);
|
|
|
|
nd_set_type($2, NODE_ARRAY);
|
|
|
|
list_concat($$, $2);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
symbol : tSYMBEG sym
|
|
|
|
{
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
sym : fname
|
1999-01-20 07:59:39 +03:00
|
|
|
| tIVAR
|
|
|
|
| tGVAR
|
2000-10-16 13:13:20 +04:00
|
|
|
| tCVAR
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
numeric : tINTEGER
|
|
|
|
| tFLOAT
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
variable : tIDENTIFIER
|
|
|
|
| tIVAR
|
|
|
|
| tGVAR
|
|
|
|
| tCONSTANT
|
2000-03-23 11:37:35 +03:00
|
|
|
| tCVAR
|
1998-01-16 15:19:22 +03:00
|
|
|
| kNIL {$$ = kNIL;}
|
|
|
|
| kSELF {$$ = kSELF;}
|
1999-01-20 07:59:39 +03:00
|
|
|
| kTRUE {$$ = kTRUE;}
|
1998-01-16 15:19:22 +03:00
|
|
|
| kFALSE {$$ = kFALSE;}
|
1999-01-20 07:59:39 +03:00
|
|
|
| k__FILE__ {$$ = k__FILE__;}
|
|
|
|
| k__LINE__ {$$ = k__LINE__;}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
var_ref : variable
|
|
|
|
{
|
|
|
|
$$ = gettable($1);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
backref : tNTH_REF
|
|
|
|
| tBACK_REF
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
superclass : term
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
|
|
|
| '<'
|
|
|
|
{
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
}
|
|
|
|
expr term
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| error term {yyerrok; $$ = 0;}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
f_arglist : '(' f_args opt_nl ')'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
}
|
|
|
|
| f_args term
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS($1, $3, $5), $6);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_arg ',' f_optarg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS($1, $3, -1), $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_arg ',' f_rest_arg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS($1, 0, $3), $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_arg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS($1, 0, -1), $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_optarg ',' f_rest_arg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS(0, $1, $3), $4);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_optarg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS(0, $1, -1), $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_rest_arg opt_f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS(0, 0, $1), $2);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
| f_block_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = block_append(NEW_ARGS(0, 0, -1), $1);
|
|
|
|
}
|
|
|
|
| /* none */
|
|
|
|
{
|
|
|
|
$$ = NEW_ARGS(0, 0, -1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-03-13 10:18:45 +03:00
|
|
|
f_norm_arg : tCONSTANT
|
|
|
|
{
|
2000-07-01 10:47:47 +04:00
|
|
|
yyerror("formal argument cannot be a constant");
|
|
|
|
}
|
|
|
|
| tIVAR
|
|
|
|
{
|
|
|
|
yyerror("formal argument cannot be an instance variable");
|
|
|
|
}
|
|
|
|
| tGVAR
|
|
|
|
{
|
|
|
|
yyerror("formal argument cannot be a global variable");
|
|
|
|
}
|
|
|
|
| tCVAR
|
|
|
|
{
|
|
|
|
yyerror("formal argument cannot be a class variable");
|
2000-03-13 10:18:45 +03:00
|
|
|
}
|
|
|
|
| tIDENTIFIER
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (!is_local_id($1))
|
|
|
|
yyerror("formal argument must be local variable");
|
1999-08-13 09:45:20 +04:00
|
|
|
else if (local_id($1))
|
|
|
|
yyerror("duplicate argument name");
|
1998-01-16 15:13:05 +03:00
|
|
|
local_cnt($1);
|
|
|
|
$$ = 1;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
f_arg : f_norm_arg
|
|
|
|
| f_arg ',' f_norm_arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ += 1;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
f_opt : tIDENTIFIER '=' arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (!is_local_id($1))
|
|
|
|
yyerror("formal argument must be local variable");
|
1999-08-13 09:45:20 +04:00
|
|
|
else if (local_id($1))
|
|
|
|
yyerror("duplicate optional argument name");
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = assignable($1, $3);
|
|
|
|
}
|
|
|
|
|
|
|
|
f_optarg : f_opt
|
|
|
|
{
|
|
|
|
$$ = NEW_BLOCK($1);
|
|
|
|
$$->nd_end = $$;
|
|
|
|
}
|
|
|
|
| f_optarg ',' f_opt
|
|
|
|
{
|
|
|
|
$$ = block_append($1, $3);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
f_rest_arg : tSTAR tIDENTIFIER
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (!is_local_id($2))
|
|
|
|
yyerror("rest argument must be local variable");
|
1999-08-13 09:45:20 +04:00
|
|
|
else if (local_id($2))
|
|
|
|
yyerror("duplicate rest argument name");
|
1998-01-16 15:13:05 +03:00
|
|
|
$$ = local_cnt($2);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| tSTAR
|
|
|
|
{
|
|
|
|
$$ = -2;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
f_block_arg : tAMPER tIDENTIFIER
|
|
|
|
{
|
2000-02-18 09:59:36 +03:00
|
|
|
if (!is_local_id($2))
|
|
|
|
yyerror("block argument must be local variable");
|
|
|
|
else if (local_id($2))
|
|
|
|
yyerror("duplicate block argument name");
|
1999-01-20 07:59:39 +03:00
|
|
|
$$ = NEW_BLOCK_ARG($2);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt_f_block_arg : ',' f_block_arg
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| none
|
1999-01-20 07:59:39 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
singleton : var_ref
|
|
|
|
{
|
|
|
|
if (nd_type($1) == NODE_SELF) {
|
|
|
|
$$ = NEW_SELF();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
| '(' {lex_state = EXPR_BEG;} expr opt_nl ')'
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
switch (nd_type($3)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_STR:
|
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_ARRAY:
|
|
|
|
case NODE_ZARRAY:
|
1999-08-13 09:45:20 +04:00
|
|
|
yyerror("can't define single method for literals.");
|
1998-01-16 15:13:05 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
$$ = $3;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
assoc_list : none
|
1998-01-16 15:13:05 +03:00
|
|
|
| assocs trailer
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| args trailer
|
|
|
|
{
|
|
|
|
if ($1->nd_alen%2 != 0) {
|
|
|
|
yyerror("odd number list for Hash");
|
|
|
|
}
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assocs : assoc
|
|
|
|
| assocs ',' assoc
|
|
|
|
{
|
|
|
|
$$ = list_concat($1, $3);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
assoc : arg tASSOC arg
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
$$ = list_append(NEW_LIST($1), $3);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
operation : tIDENTIFIER
|
|
|
|
| tCONSTANT
|
|
|
|
| tFID
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
operation2 : tIDENTIFIER
|
|
|
|
| tCONSTANT
|
|
|
|
| tFID
|
|
|
|
| op
|
|
|
|
|
|
|
|
operation3 : tIDENTIFIER
|
|
|
|
| tFID
|
|
|
|
| op
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
dot_or_colon : '.'
|
|
|
|
| tCOLON2
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
opt_terms : /* none */
|
|
|
|
| terms
|
|
|
|
|
|
|
|
opt_nl : /* none */
|
|
|
|
| '\n'
|
|
|
|
|
|
|
|
trailer : /* none */
|
|
|
|
| '\n'
|
|
|
|
| ','
|
|
|
|
|
|
|
|
term : ';' {yyerrok;}
|
|
|
|
| '\n'
|
|
|
|
|
|
|
|
terms : term
|
|
|
|
| terms ';' {yyerrok;}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
none : /* none */
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
%%
|
|
|
|
#include "regex.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2000-10-20 20:37:01 +04:00
|
|
|
/* We remove any previous definition of `SIGN_EXTEND_CHAR',
|
|
|
|
since ours (we hope) works properly with all combinations of
|
|
|
|
machines, compilers, `char' and `unsigned char' argument types.
|
|
|
|
(Per Bothner suggested the basic approach.) */
|
|
|
|
#undef SIGN_EXTEND_CHAR
|
|
|
|
#if __STDC__
|
|
|
|
# define SIGN_EXTEND_CHAR(c) ((signed char)(c))
|
|
|
|
#else /* not __STDC__ */
|
|
|
|
/* As in Harbison and Steele. */
|
|
|
|
# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
|
|
|
|
#endif
|
|
|
|
#define is_identchar(c) (SIGN_EXTEND_CHAR(c)!=-1&&(ISALNUM(c) || (c) == '_' || ismbchar(c)))
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static char *tokenbuf = NULL;
|
|
|
|
static int tokidx, toksiz = 0;
|
|
|
|
|
1999-10-15 12:52:18 +04:00
|
|
|
static NODE *str_extend();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#define LEAVE_BS 1
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE (*lex_gets)(); /* gets function */
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE lex_input; /* non-nil if File */
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE lex_lastline; /* gc protect */
|
1998-01-16 15:13:05 +03:00
|
|
|
static char *lex_pbeg;
|
|
|
|
static char *lex_p;
|
|
|
|
static char *lex_pend;
|
|
|
|
|
|
|
|
static int
|
|
|
|
yyerror(msg)
|
|
|
|
char *msg;
|
|
|
|
{
|
|
|
|
char *p, *pe, *buf;
|
|
|
|
int len, i;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error("%s", msg);
|
1998-01-16 15:13:05 +03:00
|
|
|
p = lex_p;
|
|
|
|
while (lex_pbeg <= p) {
|
|
|
|
if (*p == '\n') break;
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
|
|
|
|
pe = lex_p;
|
|
|
|
while (pe < lex_pend) {
|
|
|
|
if (*pe == '\n') break;
|
|
|
|
pe++;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = pe - p;
|
|
|
|
if (len > 4) {
|
|
|
|
buf = ALLOCA_N(char, len+2);
|
|
|
|
MEMCPY(buf, p, char, len);
|
|
|
|
buf[len] = '\0';
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error_append("%s", buf);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
i = lex_p - p;
|
|
|
|
p = buf; pe = p + len;
|
|
|
|
|
|
|
|
while (p < pe) {
|
|
|
|
if (*p != '\t') *p = ' ';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
buf[i] = '^';
|
|
|
|
buf[i+1] = '\0';
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error_append("%s", buf);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int heredoc_end;
|
2001-05-30 13:12:34 +04:00
|
|
|
static int command_start = Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
int ruby_in_compile = 0;
|
|
|
|
int ruby__end__seen;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-10-15 12:52:18 +04:00
|
|
|
static VALUE ruby_debug_lines;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE*
|
2000-01-05 07:41:21 +03:00
|
|
|
yycompile(f, line)
|
1998-01-16 15:13:05 +03:00
|
|
|
char *f;
|
2000-01-05 07:41:21 +03:00
|
|
|
int line;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int n;
|
2000-07-27 13:49:34 +04:00
|
|
|
NODE *node = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-07-18 10:00:45 +04:00
|
|
|
if (!compile_for_eval && rb_safe_level() == 0 &&
|
2000-01-05 07:41:21 +03:00
|
|
|
rb_const_defined(rb_cObject, rb_intern("SCRIPT_LINES__"))) {
|
1999-10-15 12:52:18 +04:00
|
|
|
VALUE hash, fname;
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
hash = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
|
1999-10-15 12:52:18 +04:00
|
|
|
if (TYPE(hash) == T_HASH) {
|
|
|
|
fname = rb_str_new2(f);
|
|
|
|
ruby_debug_lines = rb_hash_aref(hash, fname);
|
|
|
|
if (NIL_P(ruby_debug_lines)) {
|
|
|
|
ruby_debug_lines = rb_ary_new();
|
|
|
|
rb_hash_aset(hash, fname, ruby_debug_lines);
|
|
|
|
}
|
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
if (line > 1) {
|
|
|
|
VALUE str = rb_str_new(0,0);
|
|
|
|
while (line > 1) {
|
|
|
|
rb_ary_push(ruby_debug_lines, str);
|
|
|
|
line--;
|
|
|
|
}
|
|
|
|
}
|
1999-10-15 12:52:18 +04:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby__end__seen = 0;
|
|
|
|
ruby_eval_tree = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
heredoc_end = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_sourcefile = f;
|
|
|
|
ruby_in_compile = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
n = yyparse();
|
1999-10-15 12:52:18 +04:00
|
|
|
ruby_debug_lines = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
compile_for_eval = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_in_compile = 0;
|
2000-09-04 12:24:09 +04:00
|
|
|
cond_stack = 0;
|
2001-05-02 08:22:21 +04:00
|
|
|
cmdarg_stack = 0;
|
2001-05-30 13:12:34 +04:00
|
|
|
command_start = 1;
|
1999-08-13 09:45:20 +04:00
|
|
|
class_nest = 0;
|
|
|
|
in_single = 0;
|
2001-02-13 08:09:11 +03:00
|
|
|
in_def = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
cur_mid = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-07-27 13:49:34 +04:00
|
|
|
if (n == 0) node = ruby_eval_tree;
|
|
|
|
return node;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int lex_gets_ptr;
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
lex_get_str(s)
|
|
|
|
VALUE s;
|
|
|
|
{
|
|
|
|
char *beg, *end, *pend;
|
|
|
|
|
|
|
|
beg = RSTRING(s)->ptr;
|
|
|
|
if (lex_gets_ptr) {
|
|
|
|
if (RSTRING(s)->len == lex_gets_ptr) return Qnil;
|
|
|
|
beg += lex_gets_ptr;
|
|
|
|
}
|
|
|
|
pend = RSTRING(s)->ptr + RSTRING(s)->len;
|
|
|
|
end = beg;
|
|
|
|
while (end < pend) {
|
|
|
|
if (*end++ == '\n') break;
|
|
|
|
}
|
|
|
|
lex_gets_ptr = end - RSTRING(s)->ptr;
|
|
|
|
return rb_str_new(beg, end - beg);
|
|
|
|
}
|
|
|
|
|
1999-10-15 12:52:18 +04:00
|
|
|
static VALUE
|
|
|
|
lex_getline()
|
|
|
|
{
|
|
|
|
VALUE line = (*lex_gets)(lex_input);
|
|
|
|
if (ruby_debug_lines && !NIL_P(line)) {
|
|
|
|
rb_ary_push(ruby_debug_lines, line);
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE*
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_compile_string(f, s, line)
|
|
|
|
const char *f;
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE s;
|
1999-08-13 09:45:20 +04:00
|
|
|
int line;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_gets = lex_get_str;
|
|
|
|
lex_gets_ptr = 0;
|
|
|
|
lex_input = s;
|
|
|
|
lex_pbeg = lex_p = lex_pend = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
ruby_sourceline = line - 1;
|
2000-05-30 08:24:17 +04:00
|
|
|
compile_for_eval = ruby_in_eval;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
return yycompile(f, line);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NODE*
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_compile_cstr(f, s, len, line)
|
|
|
|
const char *f, *s;
|
|
|
|
int len, line;
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_compile_string(f, rb_str_new(s, len), line);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NODE*
|
|
|
|
rb_compile_file(f, file, start)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *f;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE file;
|
|
|
|
int start;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_gets = rb_io_gets;
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_input = file;
|
|
|
|
lex_pbeg = lex_p = lex_pend = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
ruby_sourceline = start - 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
return yycompile(strdup(f), start);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2001-01-10 13:07:31 +03:00
|
|
|
static inline int
|
1998-01-16 15:13:05 +03:00
|
|
|
nextc()
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (lex_p == lex_pend) {
|
|
|
|
if (lex_input) {
|
1999-10-15 12:52:18 +04:00
|
|
|
VALUE v = lex_getline();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (NIL_P(v)) return -1;
|
1999-01-20 07:59:39 +03:00
|
|
|
if (heredoc_end > 0) {
|
1999-08-13 09:45:20 +04:00
|
|
|
ruby_sourceline = heredoc_end;
|
1999-01-20 07:59:39 +03:00
|
|
|
heredoc_end = 0;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
ruby_sourceline++;
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_pbeg = lex_p = RSTRING(v)->ptr;
|
|
|
|
lex_pend = lex_p + RSTRING(v)->len;
|
1999-09-16 13:40:33 +04:00
|
|
|
if (strncmp(lex_pbeg, "__END__", 7) == 0 &&
|
|
|
|
(RSTRING(v)->len == 7 || lex_pbeg[7] == '\n' || lex_pbeg[7] == '\r')) {
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby__end__seen = 1;
|
1998-01-16 15:19:22 +03:00
|
|
|
lex_lastline = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
lex_lastline = v;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 15:19:22 +03:00
|
|
|
lex_lastline = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (unsigned char)*lex_p++;
|
1999-09-16 13:40:33 +04:00
|
|
|
if (c == '\r' && lex_p <= lex_pend && *lex_p == '\n') {
|
|
|
|
lex_p++;
|
|
|
|
c = '\n';
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static void
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c)
|
|
|
|
int c;
|
|
|
|
{
|
|
|
|
if (c == -1) return;
|
|
|
|
lex_p--;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#define peek(c) (lex_p != lex_pend && (c) == *lex_p)
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#define tokfix() (tokenbuf[tokidx]='\0')
|
|
|
|
#define tok() tokenbuf
|
|
|
|
#define toklen() tokidx
|
|
|
|
#define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
|
|
|
|
|
|
|
|
static char*
|
|
|
|
newtok()
|
|
|
|
{
|
|
|
|
tokidx = 0;
|
|
|
|
if (!tokenbuf) {
|
|
|
|
toksiz = 60;
|
|
|
|
tokenbuf = ALLOC_N(char, 60);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
if (toksiz > 4096) {
|
1998-01-16 15:13:05 +03:00
|
|
|
toksiz = 60;
|
|
|
|
REALLOC_N(tokenbuf, char, 60);
|
|
|
|
}
|
|
|
|
return tokenbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tokadd(c)
|
|
|
|
char c;
|
|
|
|
{
|
|
|
|
tokenbuf[tokidx++] = c;
|
|
|
|
if (tokidx >= toksiz) {
|
|
|
|
toksiz *= 2;
|
|
|
|
REALLOC_N(tokenbuf, char, toksiz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_escape()
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
switch (c = nextc()) {
|
|
|
|
case '\\': /* Backslash */
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case 'n': /* newline */
|
|
|
|
return '\n';
|
|
|
|
|
|
|
|
case 't': /* horizontal tab */
|
|
|
|
return '\t';
|
|
|
|
|
|
|
|
case 'r': /* carriage-return */
|
|
|
|
return '\r';
|
|
|
|
|
|
|
|
case 'f': /* form-feed */
|
|
|
|
return '\f';
|
|
|
|
|
|
|
|
case 'v': /* vertical tab */
|
|
|
|
return '\13';
|
|
|
|
|
|
|
|
case 'a': /* alarm(bell) */
|
|
|
|
return '\007';
|
|
|
|
|
|
|
|
case 'e': /* escape */
|
|
|
|
return 033;
|
|
|
|
|
|
|
|
case '0': case '1': case '2': case '3': /* octal constant */
|
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
{
|
|
|
|
char buf[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pushback(c);
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
c = nextc();
|
|
|
|
if (c == -1) goto eof;
|
|
|
|
if (c < '0' || '7' < c) {
|
|
|
|
pushback(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i] = c;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
c = scan_oct(buf, i, &i);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case 'x': /* hex constant */
|
|
|
|
{
|
2000-03-08 09:25:19 +03:00
|
|
|
int numlen;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2000-03-08 09:25:19 +03:00
|
|
|
c = scan_hex(lex_p, 2, &numlen);
|
|
|
|
lex_p += numlen;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case 'b': /* backspace */
|
1999-08-13 09:45:20 +04:00
|
|
|
return '\010';
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
case 's': /* space */
|
|
|
|
return ' ';
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'M':
|
|
|
|
if ((c = nextc()) != '-') {
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
pushback(c);
|
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
if ((c = nextc()) == '\\') {
|
|
|
|
return read_escape() | 0x80;
|
|
|
|
}
|
|
|
|
else if (c == -1) goto eof;
|
|
|
|
else {
|
|
|
|
return ((c & 0xff) | 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
if ((c = nextc()) != '-') {
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
pushback(c);
|
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
case 'c':
|
|
|
|
if ((c = nextc())== '\\') {
|
|
|
|
c = read_escape();
|
|
|
|
}
|
|
|
|
else if (c == '?')
|
|
|
|
return 0177;
|
|
|
|
else if (c == -1) goto eof;
|
|
|
|
return c & 0x9f;
|
|
|
|
|
|
|
|
eof:
|
|
|
|
case -1:
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
return '\0';
|
|
|
|
|
|
|
|
default:
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-12 13:07:57 +04:00
|
|
|
static int
|
2001-08-20 08:29:58 +04:00
|
|
|
tokadd_escape(term)
|
|
|
|
int term;
|
2000-05-12 13:07:57 +04:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
switch (c = nextc()) {
|
|
|
|
case '\n':
|
|
|
|
return 0; /* just ignore */
|
|
|
|
|
|
|
|
case '0': case '1': case '2': case '3': /* octal constant */
|
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
tokadd('\\');
|
|
|
|
tokadd(c);
|
|
|
|
for (i=0; i<2; i++) {
|
|
|
|
c = nextc();
|
|
|
|
if (c == -1) goto eof;
|
|
|
|
if (c < '0' || '7' < c) {
|
|
|
|
pushback(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'x': /* hex constant */
|
|
|
|
{
|
|
|
|
int numlen;
|
|
|
|
|
2000-05-25 09:55:12 +04:00
|
|
|
tokadd('\\');
|
|
|
|
tokadd(c);
|
2000-05-12 13:07:57 +04:00
|
|
|
scan_hex(lex_p, 2, &numlen);
|
|
|
|
while (numlen--)
|
|
|
|
tokadd(nextc());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
if ((c = nextc()) != '-') {
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
pushback(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tokadd('\\'); tokadd('M'); tokadd('-');
|
|
|
|
goto escaped;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
if ((c = nextc()) != '-') {
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
pushback(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tokadd('\\'); tokadd('C'); tokadd('-');
|
|
|
|
goto escaped;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
tokadd('\\'); tokadd('c');
|
|
|
|
escaped:
|
|
|
|
if ((c = nextc()) == '\\') {
|
2001-08-20 08:29:58 +04:00
|
|
|
return tokadd_escape(term);
|
2000-05-12 13:07:57 +04:00
|
|
|
}
|
|
|
|
else if (c == -1) goto eof;
|
|
|
|
tokadd(c);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
eof:
|
|
|
|
case -1:
|
|
|
|
yyerror("Invalid escape character syntax");
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
2001-08-20 10:15:53 +04:00
|
|
|
if (c != '/' || c != term)
|
2001-08-20 08:29:58 +04:00
|
|
|
tokadd('\\');
|
2000-05-12 13:07:57 +04:00
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
1999-01-20 07:59:39 +03:00
|
|
|
parse_regx(term, paren)
|
1999-08-13 09:45:20 +04:00
|
|
|
int term, paren;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
register int c;
|
|
|
|
char kcode = 0;
|
|
|
|
int once = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
int nest = 0;
|
|
|
|
int options = 0;
|
|
|
|
int re_start = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *list = 0;
|
|
|
|
|
|
|
|
newtok();
|
|
|
|
while ((c = nextc()) != -1) {
|
2000-05-12 13:07:57 +04:00
|
|
|
if (c == term && nest == 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
goto regx_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '#':
|
1999-10-15 12:52:18 +04:00
|
|
|
list = str_extend(list, term);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (list == (NODE*)-1) return 0;
|
1998-01-16 15:19:22 +03:00
|
|
|
continue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '\\':
|
2001-08-20 08:29:58 +04:00
|
|
|
if (tokadd_escape(term) < 0)
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case -1:
|
2000-05-12 13:07:57 +04:00
|
|
|
goto unterminated;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
default:
|
2000-05-12 13:07:57 +04:00
|
|
|
if (paren) {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c == paren) nest++;
|
|
|
|
if (c == term) nest--;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (ismbchar(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
regx_end:
|
|
|
|
for (;;) {
|
|
|
|
switch (c = nextc()) {
|
|
|
|
case 'i':
|
1999-01-20 07:59:39 +03:00
|
|
|
options |= RE_OPTION_IGNORECASE;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
options |= RE_OPTION_EXTENDED;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2000-05-24 08:34:26 +04:00
|
|
|
case 'p': /* /p is obsolete */
|
2000-05-22 11:29:50 +04:00
|
|
|
rb_warn("/p option is obsolete; use /m\n\tnote: /m does not change ^, $ behavior");
|
|
|
|
options |= RE_OPTION_POSIXLINE;
|
2000-05-18 08:32:13 +04:00
|
|
|
break;
|
2000-05-17 10:33:50 +04:00
|
|
|
case 'm':
|
|
|
|
options |= RE_OPTION_MULTILINE;
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'o':
|
|
|
|
once = 1;
|
|
|
|
break;
|
|
|
|
case 'n':
|
2000-05-22 11:29:50 +04:00
|
|
|
kcode = 16;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case 'e':
|
2000-05-22 11:29:50 +04:00
|
|
|
kcode = 32;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case 's':
|
2000-05-22 11:29:50 +04:00
|
|
|
kcode = 48;
|
1999-01-20 07:59:39 +03:00
|
|
|
break;
|
|
|
|
case 'u':
|
2000-05-22 11:29:50 +04:00
|
|
|
kcode = 64;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pushback(c);
|
|
|
|
goto end_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end_options:
|
|
|
|
tokfix();
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
if (list) {
|
1999-08-13 09:45:20 +04:00
|
|
|
nd_set_line(list, re_start);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (toklen() > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE ss = rb_str_new(tok(), toklen());
|
1998-01-16 15:13:05 +03:00
|
|
|
list_append(list, NEW_STR(ss));
|
|
|
|
}
|
|
|
|
nd_set_type(list, once?NODE_DREGX_ONCE:NODE_DREGX);
|
1999-01-20 07:59:39 +03:00
|
|
|
list->nd_cflag = options | kcode;
|
1998-01-16 15:13:05 +03:00
|
|
|
yylval.node = list;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDREGEXP;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.val = rb_reg_new(tok(), toklen(), options | kcode);
|
|
|
|
return tREGEXP;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tokadd(c);
|
|
|
|
}
|
2000-05-12 13:07:57 +04:00
|
|
|
unterminated:
|
|
|
|
ruby_sourceline = re_start;
|
|
|
|
rb_compile_error("unterminated regexp meets end of file");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int parse_qstring _((int,int));
|
1998-01-16 15:19:22 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
1999-01-20 07:59:39 +03:00
|
|
|
parse_string(func, term, paren)
|
|
|
|
int func, term, paren;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
NODE *list = 0;
|
|
|
|
int strstart;
|
1999-01-20 07:59:39 +03:00
|
|
|
int nest = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (func == '\'') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_qstring(term, paren);
|
|
|
|
}
|
|
|
|
if (func == 0) { /* read 1 line for heredoc */
|
|
|
|
/* -1 for chomp */
|
|
|
|
yylval.val = rb_str_new(lex_pbeg, lex_pend - lex_pbeg - 1);
|
1999-08-13 09:45:20 +04:00
|
|
|
lex_p = lex_pend;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tSTRING;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
strstart = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
newtok();
|
1999-01-20 07:59:39 +03:00
|
|
|
while ((c = nextc()) != term || nest > 0) {
|
|
|
|
if (c == -1) {
|
1998-01-16 15:13:05 +03:00
|
|
|
unterm_str:
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_sourceline = strstart;
|
|
|
|
rb_compile_error("unterminated string meets end of file");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ismbchar(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '#') {
|
1999-10-15 12:52:18 +04:00
|
|
|
list = str_extend(list, term);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (list == (NODE*)-1) goto unterm_str;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (c == '\\') {
|
|
|
|
c = nextc();
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c == '\n')
|
|
|
|
continue;
|
|
|
|
if (c == term) {
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pushback(c);
|
|
|
|
if (func != '"') tokadd('\\');
|
|
|
|
tokadd(read_escape());
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (paren) {
|
|
|
|
if (c == paren) nest++;
|
|
|
|
if (c == term && nest-- == 0) break;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
tokfix();
|
|
|
|
lex_state = EXPR_END;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
if (list) {
|
1999-08-13 09:45:20 +04:00
|
|
|
nd_set_line(list, strstart);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (toklen() > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE ss = rb_str_new(tok(), toklen());
|
1998-01-16 15:13:05 +03:00
|
|
|
list_append(list, NEW_STR(ss));
|
|
|
|
}
|
|
|
|
yylval.node = list;
|
|
|
|
if (func == '`') {
|
|
|
|
nd_set_type(list, NODE_DXSTR);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDXSTRING;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDSTRING;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.val = rb_str_new(tok(), toklen());
|
|
|
|
return (func == '`') ? tXSTRING : tSTRING;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-01-20 07:59:39 +03:00
|
|
|
parse_qstring(term, paren)
|
|
|
|
int term, paren;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int strstart;
|
|
|
|
int c;
|
1999-01-20 07:59:39 +03:00
|
|
|
int nest = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
strstart = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
newtok();
|
1999-01-20 07:59:39 +03:00
|
|
|
while ((c = nextc()) != term || nest > 0) {
|
|
|
|
if (c == -1) {
|
|
|
|
ruby_sourceline = strstart;
|
|
|
|
rb_compile_error("unterminated string meets end of file");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ismbchar(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '\\') {
|
|
|
|
c = nextc();
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case '\\':
|
|
|
|
c = '\\';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-02-08 12:19:27 +03:00
|
|
|
/* fall through */
|
|
|
|
if (c == term || (paren && c == paren)) {
|
|
|
|
tokadd(c);
|
|
|
|
continue;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd('\\');
|
|
|
|
}
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (paren) {
|
|
|
|
if (c == paren) nest++;
|
|
|
|
if (c == term && nest-- == 0) break;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
tokfix();
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.val = rb_str_new(tok(), toklen());
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_END;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tSTRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-02-01 06:12:21 +03:00
|
|
|
parse_quotedwords(term, paren)
|
1999-01-20 07:59:39 +03:00
|
|
|
int term, paren;
|
|
|
|
{
|
2000-02-01 06:12:21 +03:00
|
|
|
NODE *qwords = 0;
|
|
|
|
int strstart;
|
|
|
|
int c;
|
|
|
|
int nest = 0;
|
|
|
|
|
|
|
|
strstart = ruby_sourceline;
|
|
|
|
newtok();
|
|
|
|
|
2000-02-17 10:11:22 +03:00
|
|
|
while (c = nextc(),ISSPACE(c))
|
2000-02-01 06:12:21 +03:00
|
|
|
; /* skip preceding spaces */
|
|
|
|
pushback(c);
|
|
|
|
while ((c = nextc()) != term || nest > 0) {
|
|
|
|
if (c == -1) {
|
|
|
|
ruby_sourceline = strstart;
|
|
|
|
rb_compile_error("unterminated string meets end of file");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ismbchar(c)) {
|
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '\\') {
|
|
|
|
c = nextc();
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
continue;
|
|
|
|
case '\\':
|
|
|
|
c = '\\';
|
|
|
|
break;
|
|
|
|
default:
|
2001-02-08 12:19:27 +03:00
|
|
|
if (c == term || (paren && c == paren)) {
|
2000-05-01 13:42:38 +04:00
|
|
|
tokadd(c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!ISSPACE(c))
|
2000-02-17 10:11:22 +03:00
|
|
|
tokadd('\\');
|
2000-05-01 13:42:38 +04:00
|
|
|
break;
|
2000-02-01 06:12:21 +03:00
|
|
|
}
|
|
|
|
}
|
2000-02-17 10:11:22 +03:00
|
|
|
else if (ISSPACE(c)) {
|
2000-02-01 06:12:21 +03:00
|
|
|
NODE *str;
|
|
|
|
|
|
|
|
tokfix();
|
|
|
|
str = NEW_STR(rb_str_new(tok(), toklen()));
|
|
|
|
newtok();
|
|
|
|
if (!qwords) qwords = NEW_LIST(str);
|
|
|
|
else list_append(qwords, str);
|
2000-02-17 10:11:22 +03:00
|
|
|
while (c = nextc(),ISSPACE(c))
|
2000-02-01 06:12:21 +03:00
|
|
|
; /* skip continuous spaces */
|
|
|
|
pushback(c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (paren) {
|
|
|
|
if (c == paren) nest++;
|
|
|
|
if (c == term && nest-- == 0) break;
|
|
|
|
}
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
tokfix();
|
|
|
|
if (toklen() > 0) {
|
|
|
|
NODE *str;
|
|
|
|
|
|
|
|
str = NEW_STR(rb_str_new(tok(), toklen()));
|
|
|
|
if (!qwords) qwords = NEW_LIST(str);
|
|
|
|
else list_append(qwords, str);
|
|
|
|
}
|
|
|
|
if (!qwords) qwords = NEW_ZARRAY();
|
|
|
|
yylval.node = qwords;
|
|
|
|
lex_state = EXPR_END;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDSTRING;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static int
|
1999-01-20 07:59:39 +03:00
|
|
|
here_document(term, indent)
|
1998-01-16 15:19:22 +03:00
|
|
|
char term;
|
1999-01-20 07:59:39 +03:00
|
|
|
int indent;
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
int c;
|
1999-01-20 07:59:39 +03:00
|
|
|
char *eos, *p;
|
1998-01-16 15:19:22 +03:00
|
|
|
int len;
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE str;
|
1999-08-13 09:45:20 +04:00
|
|
|
volatile VALUE line = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE lastline_save;
|
|
|
|
int offset_save;
|
1998-01-16 15:19:22 +03:00
|
|
|
NODE *list = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
int linesave = ruby_sourceline;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
newtok();
|
|
|
|
switch (term) {
|
|
|
|
case '\'':
|
|
|
|
case '"':
|
|
|
|
case '`':
|
|
|
|
while ((c = nextc()) != term) {
|
|
|
|
tokadd(c);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (term == '\'') term = 0;
|
1998-01-16 15:19:22 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
c = term;
|
1998-01-16 15:19:22 +03:00
|
|
|
term = '"';
|
|
|
|
if (!is_identchar(c)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_warn("use of bare << to mean <<\"\" is deprecated");
|
1999-01-20 07:59:39 +03:00
|
|
|
break;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
while (is_identchar(c)) {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tokfix();
|
1999-01-20 07:59:39 +03:00
|
|
|
lastline_save = lex_lastline;
|
|
|
|
offset_save = lex_p - lex_pbeg;
|
1998-01-16 15:19:22 +03:00
|
|
|
eos = strdup(tok());
|
|
|
|
len = strlen(eos);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
str = rb_str_new(0,0);
|
1998-01-16 15:19:22 +03:00
|
|
|
for (;;) {
|
1999-10-15 12:52:18 +04:00
|
|
|
lex_lastline = line = lex_getline();
|
1998-01-16 15:19:22 +03:00
|
|
|
if (NIL_P(line)) {
|
|
|
|
error:
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_sourceline = linesave;
|
|
|
|
rb_compile_error("can't find string \"%s\" anywhere before EOF", eos);
|
1999-08-13 09:45:20 +04:00
|
|
|
free(eos);
|
|
|
|
return 0;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_sourceline++;
|
|
|
|
p = RSTRING(line)->ptr;
|
|
|
|
if (indent) {
|
|
|
|
while (*p && (*p == ' ' || *p == '\t')) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2000-07-04 08:17:26 +04:00
|
|
|
if (strncmp(eos, p, len) == 0) {
|
|
|
|
if (p[len] == '\n' || p[len] == '\r')
|
|
|
|
break;
|
|
|
|
if (len == RSTRING(line)->len)
|
|
|
|
break;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lex_pbeg = lex_p = RSTRING(line)->ptr;
|
|
|
|
lex_pend = lex_p + RSTRING(line)->len;
|
1999-08-13 09:45:20 +04:00
|
|
|
retry:
|
1999-01-20 07:59:39 +03:00
|
|
|
switch (parse_string(term, '\n', '\n')) {
|
|
|
|
case tSTRING:
|
|
|
|
case tXSTRING:
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_cat2(yylval.val, "\n");
|
1998-01-16 15:19:22 +03:00
|
|
|
if (!list) {
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_append(str, yylval.val);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
list_append(list, NEW_STR(yylval.val));
|
|
|
|
}
|
|
|
|
break;
|
1999-01-20 07:59:39 +03:00
|
|
|
case tDSTRING:
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!list) list = NEW_DSTR(str);
|
|
|
|
/* fall through */
|
1999-01-20 07:59:39 +03:00
|
|
|
case tDXSTRING:
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!list) list = NEW_DXSTR(str);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
list_append(yylval.node, NEW_STR(rb_str_new2("\n")));
|
1998-01-16 15:19:22 +03:00
|
|
|
nd_set_type(yylval.node, NODE_STR);
|
|
|
|
yylval.node = NEW_LIST(yylval.node);
|
|
|
|
yylval.node->nd_next = yylval.node->nd_head->nd_next;
|
|
|
|
list_concat(list, yylval.node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
goto error;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_p != lex_pend) {
|
|
|
|
goto retry;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
free(eos);
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_lastline = lastline_save;
|
|
|
|
lex_pbeg = RSTRING(lex_lastline)->ptr;
|
|
|
|
lex_pend = lex_pbeg + RSTRING(lex_lastline)->len;
|
|
|
|
lex_p = lex_pbeg + offset_save;
|
|
|
|
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
heredoc_end = ruby_sourceline;
|
|
|
|
ruby_sourceline = linesave;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
|
|
|
if (list) {
|
1999-08-13 09:45:20 +04:00
|
|
|
nd_set_line(list, linesave+1);
|
1998-01-16 15:19:22 +03:00
|
|
|
yylval.node = list;
|
|
|
|
}
|
|
|
|
switch (term) {
|
1999-01-20 07:59:39 +03:00
|
|
|
case '\0':
|
1998-01-16 15:19:22 +03:00
|
|
|
case '\'':
|
|
|
|
case '"':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (list) return tDSTRING;
|
|
|
|
yylval.val = str;
|
|
|
|
return tSTRING;
|
1998-01-16 15:19:22 +03:00
|
|
|
case '`':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (list) return tDXSTRING;
|
1999-08-13 09:45:20 +04:00
|
|
|
yylval.val = str;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tXSTRING;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "lex.c"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
arg_ambiguous()
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_warning("ambiguous first argument; make sure");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-12-26 11:08:50 +03:00
|
|
|
#if !defined(strtod) && !defined(HAVE_STDLIB_H)
|
1999-08-13 09:45:20 +04:00
|
|
|
double strtod ();
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
#define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
|
|
|
yylex()
|
|
|
|
{
|
2001-07-02 12:46:28 +04:00
|
|
|
static ID last_id = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
register int c;
|
|
|
|
int space_seen = 0;
|
2001-05-30 13:12:34 +04:00
|
|
|
int cmd_state;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
cmd_state = command_start;
|
|
|
|
command_start = Qfalse;
|
1999-08-13 09:45:20 +04:00
|
|
|
retry:
|
1998-01-16 15:13:05 +03:00
|
|
|
switch (c = nextc()) {
|
|
|
|
case '\0': /* NUL */
|
|
|
|
case '\004': /* ^D */
|
|
|
|
case '\032': /* ^Z */
|
|
|
|
case -1: /* end of script. */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* white spaces */
|
|
|
|
case ' ': case '\t': case '\f': case '\r':
|
|
|
|
case '\13': /* '\v' */
|
2000-12-12 10:42:35 +03:00
|
|
|
space_seen++;
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '#': /* it's a comment */
|
|
|
|
while ((c = nextc()) != '\n') {
|
|
|
|
if (c == -1)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case '\n':
|
1999-01-20 07:59:39 +03:00
|
|
|
switch (lex_state) {
|
|
|
|
case EXPR_BEG:
|
|
|
|
case EXPR_FNAME:
|
|
|
|
case EXPR_DOT:
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
1999-01-20 07:59:39 +03:00
|
|
|
default:
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
command_start = Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return '\n';
|
|
|
|
|
|
|
|
case '*':
|
|
|
|
if ((c = nextc()) == '*') {
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if (nextc() == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.id = tPOW;
|
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tPOW;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (c == '=') {
|
|
|
|
yylval.id = '*';
|
|
|
|
lex_state = EXPR_BEG;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
2001-05-30 13:12:34 +04:00
|
|
|
if (IS_ARG() && space_seen && !ISSPACE(c)){
|
2000-05-30 08:24:17 +04:00
|
|
|
rb_warning("`*' interpreted as argument prefix");
|
|
|
|
c = tSTAR;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-05-30 08:24:17 +04:00
|
|
|
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
|
|
|
c = tSTAR;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c = '*';
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
2000-05-30 08:24:17 +04:00
|
|
|
return c;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '!':
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tNEQ;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (c == '~') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tNMATCH;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '!';
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
if (lex_p == lex_pbeg + 1) {
|
|
|
|
/* skip embedded rd document */
|
1999-01-20 07:59:39 +03:00
|
|
|
if (strncmp(lex_p, "begin", 5) == 0 && ISSPACE(lex_p[5])) {
|
1998-01-16 15:13:05 +03:00
|
|
|
for (;;) {
|
1998-01-16 15:19:22 +03:00
|
|
|
lex_p = lex_pend;
|
1998-01-16 15:13:05 +03:00
|
|
|
c = nextc();
|
1998-01-16 15:19:22 +03:00
|
|
|
if (c == -1) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error("embedded document meets end of file");
|
1998-01-16 15:19:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (c != '=') continue;
|
2000-10-31 11:37:47 +03:00
|
|
|
if (strncmp(lex_p, "end", 3) == 0 &&
|
|
|
|
(lex_p + 3 == lex_pend || ISSPACE(lex_p[3]))) {
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
lex_p = lex_pend;
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '=') {
|
|
|
|
if ((c = nextc()) == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tEQQ;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tEQ;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (c == '~') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tMATCH;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '>') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tASSOC;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '=';
|
|
|
|
|
|
|
|
case '<':
|
1998-01-16 15:19:22 +03:00
|
|
|
c = nextc();
|
|
|
|
if (c == '<' &&
|
2001-06-01 10:47:32 +04:00
|
|
|
lex_state != EXPR_END &&
|
|
|
|
lex_state != EXPR_ENDARG
|
|
|
|
&& lex_state != EXPR_CLASS &&
|
2001-05-30 13:12:34 +04:00
|
|
|
(!IS_ARG() || space_seen)) {
|
1998-01-16 15:19:22 +03:00
|
|
|
int c2 = nextc();
|
1999-01-20 07:59:39 +03:00
|
|
|
int indent = 0;
|
|
|
|
if (c2 == '-') {
|
|
|
|
indent = 1;
|
|
|
|
c2 = nextc();
|
|
|
|
}
|
|
|
|
if (!ISSPACE(c2) && (strchr("\"'`", c2) || is_identchar(c2))) {
|
|
|
|
return here_document(c2, indent);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
pushback(c2);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
1998-01-16 15:19:22 +03:00
|
|
|
if (c == '=') {
|
1998-01-16 15:13:05 +03:00
|
|
|
if ((c = nextc()) == '>') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tCMP;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tLEQ;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (c == '<') {
|
|
|
|
if (nextc() == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.id = tLSHFT;
|
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tLSHFT;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '<';
|
|
|
|
|
|
|
|
case '>':
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tGEQ;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (c == '>') {
|
|
|
|
if ((c = nextc()) == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.id = tRSHFT;
|
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tRSHFT;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '>';
|
|
|
|
|
|
|
|
case '"':
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_string(c,c,c);
|
1998-01-16 15:13:05 +03:00
|
|
|
case '`':
|
|
|
|
if (lex_state == EXPR_FNAME) return c;
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_DOT) return c;
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_string(c,c,c);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '\'':
|
1999-08-13 09:45:20 +04:00
|
|
|
return parse_qstring(c,0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '?':
|
2001-06-01 10:47:32 +04:00
|
|
|
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) {
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
c = nextc();
|
2001-08-29 10:28:51 +04:00
|
|
|
if (c == -1) {
|
2000-12-12 10:42:35 +03:00
|
|
|
rb_compile_error("incomplete character syntax");
|
|
|
|
return 0;
|
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
if (IS_ARG() && ISSPACE(c)){
|
1999-01-20 07:59:39 +03:00
|
|
|
pushback(c);
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
if (c == '\\') {
|
1998-01-16 15:13:05 +03:00
|
|
|
c = read_escape();
|
|
|
|
}
|
|
|
|
c &= 0xff;
|
|
|
|
yylval.val = INT2FIX(c);
|
|
|
|
lex_state = EXPR_END;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tINTEGER;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '&':
|
|
|
|
if ((c = nextc()) == '&') {
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '=') {
|
|
|
|
yylval.id = tANDOP;
|
|
|
|
return tOP_ASGN;
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return tANDOP;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '=') {
|
|
|
|
yylval.id = '&';
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
2001-05-30 13:12:34 +04:00
|
|
|
if (IS_ARG() && space_seen && !ISSPACE(c)){
|
|
|
|
rb_warning("`&' interpeted as argument prefix");
|
2000-05-30 08:24:17 +04:00
|
|
|
c = tAMPER;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2000-05-30 08:24:17 +04:00
|
|
|
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
|
|
|
c = tAMPER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c = '&';
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
2000-05-30 08:24:17 +04:00
|
|
|
return c;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '|':
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '|') {
|
1999-01-20 07:59:39 +03:00
|
|
|
if ((c = nextc()) == '=') {
|
|
|
|
yylval.id = tOROP;
|
|
|
|
return tOP_ASGN;
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return tOROP;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '=') {
|
|
|
|
yylval.id = '|';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '|';
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
c = nextc();
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if (c == '@') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tUPLUS;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '+';
|
|
|
|
}
|
|
|
|
if (c == '=') {
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
yylval.id = '+';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
|
2001-05-30 13:12:34 +04:00
|
|
|
(IS_ARG() && space_seen && !ISSPACE(c))) {
|
|
|
|
if (IS_ARG()) arg_ambiguous();
|
2000-05-30 08:24:17 +04:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
pushback(c);
|
2000-02-26 04:16:48 +03:00
|
|
|
if (ISDIGIT(c)) {
|
|
|
|
c = '+';
|
|
|
|
goto start_num;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return tUPLUS;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
pushback(c);
|
|
|
|
return '+';
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
c = nextc();
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if (c == '@') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tUMINUS;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
if (c == '=') {
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
yylval.id = '-';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
|
2001-05-30 13:12:34 +04:00
|
|
|
(IS_ARG() && space_seen && !ISSPACE(c))) {
|
|
|
|
if (IS_ARG()) arg_ambiguous();
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
pushback(c);
|
2000-02-01 06:12:21 +03:00
|
|
|
if (ISDIGIT(c)) {
|
|
|
|
c = '-';
|
|
|
|
goto start_num;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return tUMINUS;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
pushback(c);
|
|
|
|
return '-';
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
if ((c = nextc()) == '.') {
|
|
|
|
if ((c = nextc()) == '.') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDOT3;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tDOT2;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!ISDIGIT(c)) {
|
|
|
|
lex_state = EXPR_DOT;
|
1998-01-16 15:13:05 +03:00
|
|
|
return '.';
|
|
|
|
}
|
|
|
|
c = '.';
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
start_num:
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
{
|
2000-12-22 06:22:25 +03:00
|
|
|
int is_float, seen_point, seen_e, seen_uc;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-12-22 06:22:25 +03:00
|
|
|
is_float = seen_point = seen_e = seen_uc = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_END;
|
|
|
|
newtok();
|
|
|
|
if (c == '-' || c == '+') {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
if (c == '0') {
|
|
|
|
c = nextc();
|
|
|
|
if (c == 'x' || c == 'X') {
|
|
|
|
/* hexadecimal */
|
1999-08-13 09:45:20 +04:00
|
|
|
c = nextc();
|
|
|
|
do {
|
2000-12-22 06:22:25 +03:00
|
|
|
if (c == '_') {
|
|
|
|
seen_uc = 1;
|
|
|
|
continue;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!ISXDIGIT(c)) break;
|
2000-12-22 06:22:25 +03:00
|
|
|
seen_uc = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
1999-08-13 09:45:20 +04:00
|
|
|
} while (c = nextc());
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c);
|
|
|
|
tokfix();
|
2000-12-22 06:22:25 +03:00
|
|
|
if (toklen() == 0) {
|
|
|
|
yyerror("hexadecimal number without hex-digits");
|
|
|
|
}
|
|
|
|
else if (seen_uc) goto trailing_uc;
|
2000-01-05 07:41:21 +03:00
|
|
|
yylval.val = rb_cstr2inum(tok(), 16);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tINTEGER;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c == 'b' || c == 'B') {
|
|
|
|
/* binary */
|
|
|
|
c = nextc();
|
1998-01-16 15:13:05 +03:00
|
|
|
do {
|
2000-12-22 06:22:25 +03:00
|
|
|
if (c == '_') {
|
|
|
|
seen_uc = 1;
|
|
|
|
continue;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c != '0'&& c != '1') break;
|
2000-12-22 06:22:25 +03:00
|
|
|
seen_uc = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
1999-08-13 09:45:20 +04:00
|
|
|
} while (c = nextc());
|
|
|
|
pushback(c);
|
|
|
|
tokfix();
|
2000-12-22 06:22:25 +03:00
|
|
|
if (toklen() == 0) {
|
|
|
|
yyerror("numeric literal without digits");
|
|
|
|
}
|
|
|
|
else if (seen_uc) goto trailing_uc;
|
2000-01-05 07:41:21 +03:00
|
|
|
yylval.val = rb_cstr2inum(tok(), 2);
|
1999-08-13 09:45:20 +04:00
|
|
|
return tINTEGER;
|
|
|
|
}
|
|
|
|
if (c >= '0' && c <= '7' || c == '_') {
|
|
|
|
/* octal */
|
|
|
|
do {
|
2000-12-22 06:22:25 +03:00
|
|
|
if (c == '_') {
|
|
|
|
seen_uc = 1;
|
|
|
|
continue;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c < '0' || c > '7') break;
|
2000-12-22 06:22:25 +03:00
|
|
|
seen_uc = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
tokadd(c);
|
|
|
|
} while (c = nextc());
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c);
|
|
|
|
tokfix();
|
2000-12-22 06:22:25 +03:00
|
|
|
if (seen_uc) goto trailing_uc;
|
2000-01-05 07:41:21 +03:00
|
|
|
yylval.val = rb_cstr2inum(tok(), 8);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tINTEGER;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (c > '7' && c <= '9') {
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("Illegal octal digit");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (c == '.') {
|
|
|
|
tokadd('0');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pushback(c);
|
|
|
|
yylval.val = INT2FIX(0);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tINTEGER;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
switch (c) {
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
2000-12-22 06:22:25 +03:00
|
|
|
seen_uc = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '.':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (seen_point || seen_e) {
|
1998-01-16 15:13:05 +03:00
|
|
|
goto decode_num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int c0 = nextc();
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!ISDIGIT(c0)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c0);
|
|
|
|
goto decode_num;
|
|
|
|
}
|
|
|
|
c = c0;
|
|
|
|
}
|
|
|
|
tokadd('.');
|
|
|
|
tokadd(c);
|
|
|
|
is_float++;
|
|
|
|
seen_point++;
|
2000-12-22 06:22:25 +03:00
|
|
|
seen_uc = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
if (seen_e) {
|
|
|
|
goto decode_num;
|
|
|
|
}
|
|
|
|
tokadd(c);
|
|
|
|
seen_e++;
|
|
|
|
is_float++;
|
2000-12-25 09:29:27 +03:00
|
|
|
while ((c = nextc()) == '_')
|
|
|
|
seen_uc = 1;
|
|
|
|
if (c == '-' || c == '+')
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
2000-12-25 09:29:27 +03:00
|
|
|
else
|
1998-01-16 15:13:05 +03:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
2000-12-22 06:22:25 +03:00
|
|
|
case '_': /* `_' in number just ignored */
|
|
|
|
seen_uc = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto decode_num;
|
|
|
|
}
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
|
|
|
|
decode_num:
|
|
|
|
pushback(c);
|
|
|
|
tokfix();
|
2000-12-22 06:22:25 +03:00
|
|
|
if (seen_uc) {
|
|
|
|
trailing_uc:
|
|
|
|
yyerror("trailing `_' in number");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (is_float) {
|
1999-08-13 09:45:20 +04:00
|
|
|
double d = strtod(tok(), 0);
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
rb_warn("Float %s out of range", tok());
|
|
|
|
errno = 0;
|
|
|
|
}
|
|
|
|
yylval.val = rb_float_new(d);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tFLOAT;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
yylval.val = rb_cstr2inum(tok(), 10);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tINTEGER;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case ']':
|
|
|
|
case '}':
|
|
|
|
case ')':
|
2001-05-30 13:12:34 +04:00
|
|
|
COND_LEXPOP();
|
|
|
|
CMDARG_LEXPOP();
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_END;
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
c = nextc();
|
|
|
|
if (c == ':') {
|
2000-05-30 08:24:17 +04:00
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
|
2001-05-30 13:12:34 +04:00
|
|
|
(IS_ARG() && space_seen)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return tCOLON3;
|
|
|
|
}
|
|
|
|
lex_state = EXPR_DOT;
|
|
|
|
return tCOLON2;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
2001-06-01 10:47:32 +04:00
|
|
|
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
lex_state = EXPR_BEG;
|
1998-01-16 15:13:05 +03:00
|
|
|
return ':';
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
lex_state = EXPR_FNAME;
|
1999-01-20 07:59:39 +03:00
|
|
|
return tSYMBEG;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '/':
|
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_regx('/', '/');
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if ((c = nextc()) == '=') {
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
yylval.id = '/';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-05-30 08:24:17 +04:00
|
|
|
pushback(c);
|
2001-05-30 13:12:34 +04:00
|
|
|
if (IS_ARG() && space_seen) {
|
2000-05-30 08:24:17 +04:00
|
|
|
if (!ISSPACE(c)) {
|
2000-12-12 10:42:35 +03:00
|
|
|
arg_ambiguous();
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_regx('/', '/');
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return '/';
|
|
|
|
|
|
|
|
case '^':
|
|
|
|
lex_state = EXPR_BEG;
|
2000-11-10 10:16:52 +03:00
|
|
|
if ((c = nextc()) == '=') {
|
1998-01-16 15:13:05 +03:00
|
|
|
yylval.id = '^';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
2000-11-10 10:16:52 +03:00
|
|
|
return '^';
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case ';':
|
2001-05-30 13:12:34 +04:00
|
|
|
command_start = Qtrue;
|
|
|
|
case ',':
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case '~':
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if ((c = nextc()) != '@') {
|
|
|
|
pushback(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return '~';
|
|
|
|
|
|
|
|
case '(':
|
2001-05-30 13:12:34 +04:00
|
|
|
command_start = Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
1999-01-20 07:59:39 +03:00
|
|
|
c = tLPAREN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
else if (space_seen) {
|
|
|
|
if (lex_state == EXPR_CMDARG) {
|
|
|
|
c = tLPAREN_ARG;
|
|
|
|
}
|
|
|
|
else if (lex_state == EXPR_ARG) {
|
|
|
|
c = tLPAREN_ARG;
|
2001-07-02 12:46:28 +04:00
|
|
|
yylval.id = last_id;
|
2001-05-30 13:12:34 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
COND_PUSH(0);
|
|
|
|
CMDARG_PUSH(0);
|
2000-05-30 08:24:17 +04:00
|
|
|
lex_state = EXPR_BEG;
|
1998-01-16 15:13:05 +03:00
|
|
|
return c;
|
|
|
|
|
|
|
|
case '[':
|
1999-08-13 09:45:20 +04:00
|
|
|
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if ((c = nextc()) == ']') {
|
|
|
|
if ((c = nextc()) == '=') {
|
1999-01-20 07:59:39 +03:00
|
|
|
return tASET;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tAREF;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '[';
|
|
|
|
}
|
|
|
|
else if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
1999-01-20 07:59:39 +03:00
|
|
|
c = tLBRACK;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
else if (IS_ARG() && space_seen) {
|
1999-01-20 07:59:39 +03:00
|
|
|
c = tLBRACK;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
2001-05-30 13:12:34 +04:00
|
|
|
COND_PUSH(0);
|
|
|
|
CMDARG_PUSH(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
return c;
|
|
|
|
|
|
|
|
case '{':
|
2001-05-30 13:12:34 +04:00
|
|
|
if (!IS_ARG()) {
|
2001-06-01 10:47:32 +04:00
|
|
|
if (space_seen && lex_state == EXPR_ENDARG)
|
2001-05-30 13:12:34 +04:00
|
|
|
c = tLBRACE_ARG;
|
2001-06-01 10:47:32 +04:00
|
|
|
if (lex_state != EXPR_END && lex_state != EXPR_ENDARG)
|
|
|
|
c = tLBRACE;
|
2001-05-30 13:12:34 +04:00
|
|
|
}
|
|
|
|
COND_PUSH(0);
|
|
|
|
CMDARG_PUSH(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case '\\':
|
|
|
|
c = nextc();
|
|
|
|
if (c == '\n') {
|
|
|
|
space_seen = 1;
|
|
|
|
goto retry; /* skip \\n */
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
return '\\';
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
|
|
|
|
int term;
|
1999-01-20 07:59:39 +03:00
|
|
|
int paren;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
c = nextc();
|
|
|
|
quotation:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!ISALNUM(c)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
term = c;
|
1999-01-20 07:59:39 +03:00
|
|
|
c = 'Q';
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
term = nextc();
|
|
|
|
}
|
|
|
|
if (c == -1 || term == -1) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error("unterminated quoted string meets end of file");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
paren = term;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (term == '(') term = ')';
|
|
|
|
else if (term == '[') term = ']';
|
|
|
|
else if (term == '{') term = '}';
|
|
|
|
else if (term == '<') term = '>';
|
1999-08-13 09:45:20 +04:00
|
|
|
else paren = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'Q':
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_string('"', term, paren);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case 'q':
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_qstring(term, paren);
|
|
|
|
|
|
|
|
case 'w':
|
2000-02-01 06:12:21 +03:00
|
|
|
return parse_quotedwords(term, paren);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case 'x':
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_string('`', term, paren);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case 'r':
|
1999-01-20 07:59:39 +03:00
|
|
|
return parse_regx(term, paren);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
yyerror("unknown type of %string");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((c = nextc()) == '=') {
|
|
|
|
yylval.id = '%';
|
1999-01-20 07:59:39 +03:00
|
|
|
return tOP_ASGN;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-05-30 13:12:34 +04:00
|
|
|
if (IS_ARG() && space_seen && !ISSPACE(c)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
goto quotation;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
pushback(c);
|
|
|
|
return '%';
|
|
|
|
|
|
|
|
case '$':
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
newtok();
|
|
|
|
c = nextc();
|
|
|
|
switch (c) {
|
1998-01-16 15:19:22 +03:00
|
|
|
case '_': /* $_: last read line string */
|
2000-09-15 10:00:30 +04:00
|
|
|
c = nextc();
|
|
|
|
if (is_identchar(c)) {
|
|
|
|
tokadd('$');
|
|
|
|
tokadd('_');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
c = '_';
|
2000-09-19 11:54:28 +04:00
|
|
|
/* fall through */
|
|
|
|
case '~': /* $~: match-data */
|
|
|
|
local_cnt(c);
|
1998-01-16 15:13:05 +03:00
|
|
|
/* fall through */
|
|
|
|
case '*': /* $*: argv */
|
|
|
|
case '$': /* $$: pid */
|
|
|
|
case '?': /* $?: last status */
|
|
|
|
case '!': /* $!: error string */
|
|
|
|
case '@': /* $@: error position */
|
|
|
|
case '/': /* $/: input record separator */
|
|
|
|
case '\\': /* $\: output record separator */
|
|
|
|
case ';': /* $;: field separator */
|
|
|
|
case ',': /* $,: output field separator */
|
|
|
|
case '.': /* $.: last read line number */
|
|
|
|
case '=': /* $=: ignorecase */
|
|
|
|
case ':': /* $:: load path */
|
|
|
|
case '<': /* $<: reading filename */
|
|
|
|
case '>': /* $>: default output handle */
|
|
|
|
case '\"': /* $": already loaded files */
|
|
|
|
tokadd('$');
|
|
|
|
tokadd(c);
|
|
|
|
tokfix();
|
|
|
|
yylval.id = rb_intern(tok());
|
1999-01-20 07:59:39 +03:00
|
|
|
return tGVAR;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '-':
|
|
|
|
tokadd('$');
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
tokadd(c);
|
|
|
|
tokfix();
|
|
|
|
yylval.id = rb_intern(tok());
|
2000-07-07 07:20:53 +04:00
|
|
|
/* xxx shouldn't check if valid option variable */
|
1999-01-20 07:59:39 +03:00
|
|
|
return tGVAR;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '&': /* $&: last match */
|
|
|
|
case '`': /* $`: string before last match */
|
|
|
|
case '\'': /* $': string after last match */
|
|
|
|
case '+': /* $+: string matches last paren. */
|
|
|
|
yylval.node = NEW_BACK_REF(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
return tBACK_REF;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6':
|
|
|
|
case '7': case '8': case '9':
|
2000-05-09 08:53:16 +04:00
|
|
|
tokadd('$');
|
1999-01-20 07:59:39 +03:00
|
|
|
while (ISDIGIT(c)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
2000-05-09 08:53:16 +04:00
|
|
|
if (is_identchar(c))
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c);
|
|
|
|
tokfix();
|
2000-05-09 08:53:16 +04:00
|
|
|
yylval.node = NEW_NTH_REF(atoi(tok()+1));
|
1999-01-20 07:59:39 +03:00
|
|
|
return tNTH_REF;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (!is_identchar(c)) {
|
|
|
|
pushback(c);
|
|
|
|
return '$';
|
|
|
|
}
|
|
|
|
case '0':
|
|
|
|
tokadd('$');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '@':
|
|
|
|
c = nextc();
|
2000-02-18 09:59:36 +03:00
|
|
|
newtok();
|
|
|
|
tokadd('@');
|
|
|
|
if (c == '@') {
|
|
|
|
tokadd('@');
|
|
|
|
c = nextc();
|
|
|
|
}
|
2000-07-11 12:27:06 +04:00
|
|
|
if (ISDIGIT(c)) {
|
|
|
|
rb_compile_error("`@%c' is not a valid instance variable name", c);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!is_identchar(c)) {
|
|
|
|
pushback(c);
|
|
|
|
return '@';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-07-11 12:27:06 +04:00
|
|
|
if (!is_identchar(c) || ISDIGIT(c)) {
|
2000-07-12 10:06:50 +04:00
|
|
|
rb_compile_error("Invalid char `\\%03o' in expression", c);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
newtok();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (is_identchar(c)) {
|
|
|
|
tokadd(c);
|
|
|
|
if (ismbchar(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = nextc();
|
|
|
|
tokadd(c);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
c = nextc();
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if ((c == '!' || c == '?') && is_identchar(tok()[0]) && !peek('=')) {
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pushback(c);
|
|
|
|
}
|
|
|
|
tokfix();
|
|
|
|
|
|
|
|
{
|
2000-01-17 11:37:53 +03:00
|
|
|
int result = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (tok()[0]) {
|
|
|
|
case '$':
|
|
|
|
lex_state = EXPR_END;
|
1999-01-20 07:59:39 +03:00
|
|
|
result = tGVAR;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
lex_state = EXPR_END;
|
2000-02-18 09:59:36 +03:00
|
|
|
if (tok()[1] == '@')
|
2000-03-23 11:37:35 +03:00
|
|
|
result = tCVAR;
|
2000-02-18 09:59:36 +03:00
|
|
|
else
|
|
|
|
result = tIVAR;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2001-09-05 10:54:57 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
default:
|
2001-09-05 10:54:57 +04:00
|
|
|
if (toklast() == '!' || toklast() == '?') {
|
|
|
|
result = tFID;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (lex_state == EXPR_FNAME) {
|
|
|
|
if ((c = nextc()) == '=' && !peek('~') && !peek('>') &&
|
|
|
|
(!peek('=') || lex_p + 1 < lex_pend && lex_p[1] == '>')) {
|
|
|
|
result = tIDENTIFIER;
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pushback(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == 0 && ISUPPER(tok()[0])) {
|
|
|
|
result = tCONSTANT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = tIDENTIFIER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lex_state != EXPR_DOT) {
|
2001-09-05 10:54:57 +04:00
|
|
|
struct kwtable *kw;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
/* See if it is a reserved word. */
|
|
|
|
kw = rb_reserved_word(tok(), toklen());
|
|
|
|
if (kw) {
|
|
|
|
enum lex_state state = lex_state;
|
1999-08-13 09:45:20 +04:00
|
|
|
lex_state = kw->state;
|
|
|
|
if (state == EXPR_FNAME) {
|
1999-01-20 07:59:39 +03:00
|
|
|
yylval.id = rb_intern(kw->name);
|
|
|
|
}
|
2001-01-26 08:02:19 +03:00
|
|
|
if (kw->id[0] == kDO) {
|
|
|
|
if (COND_P()) return kDO_COND;
|
2001-06-07 12:40:54 +04:00
|
|
|
if (CMDARG_P() && state != EXPR_CMDARG)
|
|
|
|
return kDO_BLOCK;
|
2001-01-26 08:02:19 +03:00
|
|
|
return kDO;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
if (state == EXPR_BEG)
|
|
|
|
return kw->id[0];
|
|
|
|
else {
|
|
|
|
if (kw->id[0] != kw->id[1])
|
|
|
|
lex_state = EXPR_BEG;
|
|
|
|
return kw->id[1];
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lex_state == EXPR_BEG ||
|
|
|
|
lex_state == EXPR_DOT ||
|
2001-05-30 13:12:34 +04:00
|
|
|
lex_state == EXPR_ARG ||
|
|
|
|
lex_state == EXPR_CMDARG) {
|
|
|
|
if (cmd_state)
|
|
|
|
lex_state = EXPR_CMDARG;
|
|
|
|
else
|
|
|
|
lex_state = EXPR_ARG;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lex_state = EXPR_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tokfix();
|
2001-05-30 13:12:34 +04:00
|
|
|
last_id = yylval.id = rb_intern(tok());
|
1998-01-16 15:13:05 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
1999-10-15 12:52:18 +04:00
|
|
|
str_extend(list, term)
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *list;
|
|
|
|
char term;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
int c;
|
|
|
|
int brace = -1;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE ss;
|
|
|
|
NODE *node;
|
|
|
|
int nest;
|
|
|
|
|
|
|
|
c = nextc();
|
|
|
|
switch (c) {
|
|
|
|
case '$':
|
|
|
|
case '@':
|
|
|
|
case '{':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tokadd('#');
|
|
|
|
pushback(c);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
ss = rb_str_new(tok(), toklen());
|
1998-01-16 15:13:05 +03:00
|
|
|
if (list == 0) {
|
|
|
|
list = NEW_DSTR(ss);
|
|
|
|
}
|
|
|
|
else if (toklen() > 0) {
|
|
|
|
list_append(list, NEW_STR(ss));
|
|
|
|
}
|
|
|
|
newtok();
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '$':
|
|
|
|
tokadd('$');
|
|
|
|
c = nextc();
|
|
|
|
if (c == -1) return (NODE*)-1;
|
|
|
|
switch (c) {
|
|
|
|
case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6':
|
|
|
|
case '7': case '8': case '9':
|
1999-01-20 07:59:39 +03:00
|
|
|
while (ISDIGIT(c)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
goto fetch_id;
|
|
|
|
|
|
|
|
case '&': case '+':
|
|
|
|
case '_': case '~':
|
|
|
|
case '*': case '$': case '?':
|
|
|
|
case '!': case '@': case ',':
|
|
|
|
case '.': case '=': case ':':
|
|
|
|
case '<': case '>': case '\\':
|
|
|
|
refetch:
|
|
|
|
tokadd(c);
|
|
|
|
goto fetch_id;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (c == term) {
|
1999-01-20 07:59:39 +03:00
|
|
|
list_append(list, NEW_STR(rb_str_new2("#$")));
|
1998-01-16 15:13:05 +03:00
|
|
|
pushback(c);
|
|
|
|
newtok();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case '\"':
|
|
|
|
case '/':
|
|
|
|
case '\'':
|
|
|
|
case '`':
|
|
|
|
goto refetch;
|
|
|
|
}
|
|
|
|
if (!is_identchar(c)) {
|
|
|
|
yyerror("bad global variable in string");
|
|
|
|
newtok();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
while (is_identchar(c)) {
|
|
|
|
tokadd(c);
|
|
|
|
if (ismbchar(c)) {
|
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = nextc();
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
case '@':
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
2000-04-10 09:48:43 +04:00
|
|
|
if (c == '@') {
|
|
|
|
tokadd(c);
|
|
|
|
c = nextc();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
while (is_identchar(c)) {
|
|
|
|
tokadd(c);
|
|
|
|
if (ismbchar(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
int i, len = mbclen(c)-1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = nextc();
|
|
|
|
tokadd(c);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
c = nextc();
|
|
|
|
}
|
|
|
|
pushback(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '{':
|
1998-01-16 15:19:22 +03:00
|
|
|
if (c == '{') brace = '}';
|
1998-01-16 15:13:05 +03:00
|
|
|
nest = 0;
|
|
|
|
do {
|
|
|
|
loop_again:
|
|
|
|
c = nextc();
|
|
|
|
switch (c) {
|
|
|
|
case -1:
|
|
|
|
if (nest > 0) {
|
1998-01-16 15:19:22 +03:00
|
|
|
yyerror("bad substitution in string");
|
1998-01-16 15:13:05 +03:00
|
|
|
newtok();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
return (NODE*)-1;
|
|
|
|
case '}':
|
1998-01-16 15:19:22 +03:00
|
|
|
if (c == brace) {
|
|
|
|
if (nest == 0) break;
|
|
|
|
nest--;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
tokadd(c);
|
|
|
|
goto loop_again;
|
|
|
|
case '\\':
|
2000-03-08 09:25:19 +03:00
|
|
|
c = nextc();
|
|
|
|
if (c == -1) return (NODE*)-1;
|
|
|
|
if (c == term) {
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tokadd('\\');
|
|
|
|
tokadd(c);
|
|
|
|
}
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
case '{':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (brace != -1) nest++;
|
1998-01-16 15:13:05 +03:00
|
|
|
case '\"':
|
|
|
|
case '/':
|
|
|
|
case '`':
|
|
|
|
if (c == term) {
|
|
|
|
pushback(c);
|
1999-01-20 07:59:39 +03:00
|
|
|
list_append(list, NEW_STR(rb_str_new2("#")));
|
|
|
|
rb_warning("bad substitution in string");
|
1998-01-16 15:13:05 +03:00
|
|
|
tokfix();
|
1999-01-20 07:59:39 +03:00
|
|
|
list_append(list, NEW_STR(rb_str_new(tok(), toklen())));
|
1998-01-16 15:13:05 +03:00
|
|
|
newtok();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
tokadd(c);
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
} while (c != brace);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch_id:
|
|
|
|
tokfix();
|
|
|
|
node = NEW_EVSTR(tok(),toklen());
|
|
|
|
list_append(list, node);
|
|
|
|
newtok();
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE*
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_node_newnode(type, a0, a1, a2)
|
1998-01-16 15:13:05 +03:00
|
|
|
enum node_type type;
|
|
|
|
NODE *a0, *a1, *a2;
|
|
|
|
{
|
|
|
|
NODE *n = (NODE*)rb_newobj();
|
|
|
|
|
|
|
|
n->flags |= T_NODE;
|
|
|
|
nd_set_type(n, type);
|
1999-01-20 07:59:39 +03:00
|
|
|
nd_set_line(n, ruby_sourceline);
|
|
|
|
n->nd_file = ruby_sourcefile;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
n->u1.node = a0;
|
|
|
|
n->u2.node = a1;
|
|
|
|
n->u3.node = a2;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static enum node_type
|
1998-01-16 15:13:05 +03:00
|
|
|
nodetype(node) /* for debug */
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
return (enum node_type)nd_type(node);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int
|
1998-01-16 15:13:05 +03:00
|
|
|
nodeline(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
return nd_line(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
newline_node(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
NODE *nl = 0;
|
|
|
|
if (node) {
|
|
|
|
nl = NEW_NEWLINE(node);
|
|
|
|
fixpos(nl, node);
|
2000-12-12 10:42:35 +03:00
|
|
|
nl->nd_nth = nd_line(node);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return nl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fixpos(node, orig)
|
|
|
|
NODE *node, *orig;
|
|
|
|
{
|
|
|
|
if (!node) return;
|
|
|
|
if (!orig) return;
|
1998-01-16 15:19:22 +03:00
|
|
|
node->nd_file = orig->nd_file;
|
1998-01-16 15:13:05 +03:00
|
|
|
nd_set_line(node, nd_line(orig));
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
block_append(head, tail)
|
|
|
|
NODE *head, *tail;
|
|
|
|
{
|
|
|
|
NODE *end;
|
|
|
|
|
|
|
|
if (tail == 0) return head;
|
|
|
|
if (head == 0) return tail;
|
|
|
|
|
|
|
|
if (nd_type(head) != NODE_BLOCK) {
|
|
|
|
end = NEW_BLOCK(head);
|
|
|
|
end->nd_end = end;
|
|
|
|
fixpos(end, head);
|
|
|
|
head = end;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
end = head->nd_end;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (RTEST(ruby_verbose)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *nd = end->nd_head;
|
|
|
|
newline:
|
|
|
|
switch (nd_type(nd)) {
|
|
|
|
case NODE_RETURN:
|
1998-01-16 15:19:22 +03:00
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_warning("statement not reached");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NODE_NEWLINE:
|
|
|
|
nd = nd->nd_next;
|
|
|
|
goto newline;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nd_type(tail) != NODE_BLOCK) {
|
|
|
|
tail = NEW_BLOCK(tail);
|
|
|
|
tail->nd_end = tail;
|
|
|
|
}
|
|
|
|
end->nd_next = tail;
|
|
|
|
head->nd_end = tail->nd_end;
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
list_append(head, tail)
|
|
|
|
NODE *head, *tail;
|
|
|
|
{
|
|
|
|
NODE *last;
|
|
|
|
|
|
|
|
if (head == 0) return NEW_LIST(tail);
|
|
|
|
|
|
|
|
last = head;
|
|
|
|
while (last->nd_next) {
|
|
|
|
last = last->nd_next;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
last->nd_next = NEW_LIST(tail);
|
|
|
|
head->nd_alen += 1;
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
list_concat(head, tail)
|
|
|
|
NODE *head, *tail;
|
|
|
|
{
|
|
|
|
NODE *last;
|
|
|
|
|
|
|
|
last = head;
|
|
|
|
while (last->nd_next) {
|
|
|
|
last = last->nd_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
last->nd_next = tail;
|
|
|
|
head->nd_alen += tail->nd_alen;
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE *
|
|
|
|
call_op(recv, id, narg, arg1)
|
|
|
|
NODE *recv;
|
|
|
|
ID id;
|
|
|
|
int narg;
|
|
|
|
NODE *arg1;
|
|
|
|
{
|
|
|
|
value_expr(recv);
|
|
|
|
if (narg == 1) {
|
|
|
|
value_expr(arg1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NEW_CALL(recv, id, narg==1?NEW_LIST(arg1):0);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static NODE*
|
|
|
|
match_gen(node1, node2)
|
|
|
|
NODE *node1;
|
|
|
|
NODE *node2;
|
|
|
|
{
|
|
|
|
local_cnt('~');
|
|
|
|
|
|
|
|
switch (nd_type(node1)) {
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
return NEW_MATCH2(node1, node2);
|
|
|
|
|
|
|
|
case NODE_LIT:
|
|
|
|
if (TYPE(node1->nd_lit) == T_REGEXP) {
|
|
|
|
return NEW_MATCH2(node1, node2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nd_type(node2)) {
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
return NEW_MATCH3(node2, node1);
|
|
|
|
|
|
|
|
case NODE_LIT:
|
|
|
|
if (TYPE(node2->nd_lit) == T_REGEXP) {
|
|
|
|
return NEW_MATCH3(node2, node1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return NEW_CALL(node1, tMATCH, NEW_LIST(node2));
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE*
|
|
|
|
gettable(id)
|
|
|
|
ID id;
|
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
if (id == kSELF) {
|
1998-01-16 15:13:05 +03:00
|
|
|
return NEW_SELF();
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
else if (id == kNIL) {
|
1998-01-16 15:13:05 +03:00
|
|
|
return NEW_NIL();
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
else if (id == kTRUE) {
|
|
|
|
return NEW_TRUE();
|
|
|
|
}
|
|
|
|
else if (id == kFALSE) {
|
|
|
|
return NEW_FALSE();
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (id == k__FILE__) {
|
|
|
|
return NEW_STR(rb_str_new2(ruby_sourcefile));
|
|
|
|
}
|
|
|
|
else if (id == k__LINE__) {
|
|
|
|
return NEW_LIT(INT2FIX(ruby_sourceline));
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
else if (is_local_id(id)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (dyna_in_block() && rb_dvar_defined(id)) return NEW_DVAR(id);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (local_id(id)) return NEW_LVAR(id);
|
|
|
|
/* method call without arguments */
|
|
|
|
return NEW_VCALL(id);
|
|
|
|
}
|
|
|
|
else if (is_global_id(id)) {
|
|
|
|
return NEW_GVAR(id);
|
|
|
|
}
|
|
|
|
else if (is_instance_id(id)) {
|
|
|
|
return NEW_IVAR(id);
|
|
|
|
}
|
1999-12-14 09:50:43 +03:00
|
|
|
else if (is_const_id(id)) {
|
2000-03-23 11:37:35 +03:00
|
|
|
return NEW_CONST(id);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-03-23 11:37:35 +03:00
|
|
|
else if (is_class_id(id)) {
|
2000-08-29 11:29:48 +04:00
|
|
|
if (in_single) return NEW_CVAR2(id);
|
2000-08-29 06:52:41 +04:00
|
|
|
return NEW_CVAR(id);
|
2000-02-18 09:59:36 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_bug("invalid id for gettable");
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
assignable(id, val)
|
|
|
|
ID id;
|
|
|
|
NODE *val;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
value_expr(val);
|
1998-01-16 15:19:22 +03:00
|
|
|
if (id == kSELF) {
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("Can't change the value of self");
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
else if (id == kNIL) {
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("Can't assign to nil");
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
else if (id == kTRUE) {
|
|
|
|
yyerror("Can't assign to true");
|
|
|
|
}
|
|
|
|
else if (id == kFALSE) {
|
|
|
|
yyerror("Can't assign to false");
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (id == k__FILE__) {
|
|
|
|
yyerror("Can't assign to __FILE__");
|
|
|
|
}
|
|
|
|
else if (id == k__LINE__) {
|
|
|
|
yyerror("Can't assign to __LINE__");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
else if (is_local_id(id)) {
|
2000-02-01 06:12:21 +03:00
|
|
|
if (rb_dvar_curr(id)) {
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_DASGN_CURR(id, val);
|
2000-02-01 06:12:21 +03:00
|
|
|
}
|
|
|
|
else if (rb_dvar_defined(id)) {
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_DASGN(id, val);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else if (local_id(id) || !dyna_in_block()) {
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_LASGN(id, val);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else{
|
2000-02-01 06:12:21 +03:00
|
|
|
rb_dvar_push(id, Qnil);
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_DASGN_CURR(id, val);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_global_id(id)) {
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_GASGN(id, val);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else if (is_instance_id(id)) {
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_IASGN(id, val);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-12-14 09:50:43 +03:00
|
|
|
else if (is_const_id(id)) {
|
2001-02-13 08:09:11 +03:00
|
|
|
if (in_def || in_single)
|
1999-12-14 09:50:43 +03:00
|
|
|
yyerror("dynamic constant assignment");
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_CDECL(id, val);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-03-23 11:37:35 +03:00
|
|
|
else if (is_class_id(id)) {
|
2000-11-21 17:26:25 +03:00
|
|
|
if (in_single) return NEW_CVASGN(id, val);
|
2000-08-28 13:53:42 +04:00
|
|
|
return NEW_CVDECL(id, val);
|
2000-02-18 09:59:36 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_bug("bad id for variable");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-08-28 13:53:42 +04:00
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static NODE *
|
1999-08-13 09:45:20 +04:00
|
|
|
aryset(recv, idx)
|
|
|
|
NODE *recv, *idx;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
value_expr(recv);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return NEW_CALL(recv, tASET, idx);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ID
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_id_attrset(id)
|
1998-01-16 15:13:05 +03:00
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
id &= ~ID_SCOPE_MASK;
|
|
|
|
id |= ID_ATTRSET;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE *
|
1999-08-13 09:45:20 +04:00
|
|
|
attrset(recv, id)
|
|
|
|
NODE *recv;
|
1998-01-16 15:13:05 +03:00
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
value_expr(recv);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
return NEW_CALL(recv, rb_id_attrset(id), 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_backref_error(node)
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_NTH_REF:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error("Can't set variable $%d", node->nd_nth);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case NODE_BACK_REF:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_compile_error("Can't set variable $%c", node->nd_nth);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static NODE *
|
|
|
|
arg_concat(node1, node2)
|
|
|
|
NODE *node1;
|
|
|
|
NODE *node2;
|
|
|
|
{
|
2000-01-17 11:37:53 +03:00
|
|
|
if (!node2) return node1;
|
1999-08-13 09:45:20 +04:00
|
|
|
return NEW_ARGSCAT(node1, node2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE *
|
|
|
|
arg_add(node1, node2)
|
|
|
|
NODE *node1;
|
|
|
|
NODE *node2;
|
|
|
|
{
|
|
|
|
if (!node1) return NEW_LIST(node2);
|
|
|
|
if (nd_type(node1) == NODE_ARRAY) {
|
|
|
|
return list_append(node1, node2);
|
|
|
|
}
|
|
|
|
else {
|
2000-01-17 11:37:53 +03:00
|
|
|
return NEW_ARGSPUSH(node1, node2);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
node_assign(lhs, rhs)
|
|
|
|
NODE *lhs, *rhs;
|
|
|
|
{
|
|
|
|
if (!lhs) return 0;
|
|
|
|
|
|
|
|
value_expr(rhs);
|
|
|
|
switch (nd_type(lhs)) {
|
|
|
|
case NODE_GASGN:
|
|
|
|
case NODE_IASGN:
|
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
2000-02-01 06:12:21 +03:00
|
|
|
case NODE_DASGN_CURR:
|
1999-08-13 09:45:20 +04:00
|
|
|
case NODE_MASGN:
|
1999-11-17 10:30:37 +03:00
|
|
|
case NODE_CDECL:
|
2000-03-23 11:37:35 +03:00
|
|
|
case NODE_CVDECL:
|
2000-11-21 17:26:25 +03:00
|
|
|
case NODE_CVASGN:
|
1999-08-13 09:45:20 +04:00
|
|
|
lhs->nd_value = rhs;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NODE_CALL:
|
|
|
|
lhs->nd_args = arg_add(lhs->nd_args, rhs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* should not happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rhs) fixpos(lhs, rhs);
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
|
|
|
value_expr(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (node == 0) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_WHILE:
|
|
|
|
case NODE_UNTIL:
|
|
|
|
case NODE_CLASS:
|
|
|
|
case NODE_MODULE:
|
|
|
|
case NODE_DEFN:
|
|
|
|
case NODE_DEFS:
|
2001-08-23 10:02:15 +04:00
|
|
|
rb_warning("void value expression");
|
|
|
|
return Qfalse;
|
|
|
|
|
|
|
|
case NODE_RETURN:
|
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
1998-01-16 15:13:05 +03:00
|
|
|
yyerror("void value expression");
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case NODE_BLOCK:
|
|
|
|
while (node->nd_next) {
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
return value_expr(node->nd_head);
|
|
|
|
|
2000-05-17 08:38:19 +04:00
|
|
|
case NODE_BEGIN:
|
|
|
|
return value_expr(node->nd_body);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_IF:
|
|
|
|
return value_expr(node->nd_body) && value_expr(node->nd_else);
|
|
|
|
|
|
|
|
case NODE_NEWLINE:
|
|
|
|
return value_expr(node->nd_next);
|
|
|
|
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static void
|
|
|
|
void_expr(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
char *useless = 0;
|
|
|
|
|
|
|
|
if (!ruby_verbose) return;
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
again:
|
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_NEWLINE:
|
|
|
|
node = node->nd_next;
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
case NODE_CALL:
|
|
|
|
switch (node->nd_mid) {
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
case '*':
|
|
|
|
case '/':
|
|
|
|
case '%':
|
|
|
|
case tPOW:
|
|
|
|
case tUPLUS:
|
|
|
|
case tUMINUS:
|
|
|
|
case '|':
|
|
|
|
case '^':
|
|
|
|
case '&':
|
|
|
|
case tCMP:
|
|
|
|
case '>':
|
|
|
|
case tGEQ:
|
|
|
|
case '<':
|
|
|
|
case tLEQ:
|
|
|
|
case tEQ:
|
|
|
|
case tNEQ:
|
|
|
|
useless = rb_id2name(node->nd_mid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NODE_LVAR:
|
|
|
|
case NODE_DVAR:
|
|
|
|
case NODE_GVAR:
|
|
|
|
case NODE_IVAR:
|
2000-03-23 11:37:35 +03:00
|
|
|
case NODE_CVAR:
|
1999-08-13 09:45:20 +04:00
|
|
|
case NODE_NTH_REF:
|
|
|
|
case NODE_BACK_REF:
|
|
|
|
useless = "a variable";
|
|
|
|
break;
|
2000-03-23 11:37:35 +03:00
|
|
|
case NODE_CONST:
|
1999-08-13 09:45:20 +04:00
|
|
|
case NODE_CREF:
|
|
|
|
useless = "a constant";
|
|
|
|
break;
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
useless = "a literal";
|
|
|
|
break;
|
|
|
|
case NODE_COLON2:
|
|
|
|
case NODE_COLON3:
|
|
|
|
useless = "::";
|
|
|
|
break;
|
|
|
|
case NODE_DOT2:
|
|
|
|
useless = "..";
|
|
|
|
break;
|
|
|
|
case NODE_DOT3:
|
|
|
|
useless = "...";
|
|
|
|
break;
|
|
|
|
case NODE_SELF:
|
|
|
|
useless = "self";
|
|
|
|
break;
|
|
|
|
case NODE_NIL:
|
|
|
|
useless = "nil";
|
|
|
|
break;
|
|
|
|
case NODE_TRUE:
|
|
|
|
useless = "true";
|
|
|
|
break;
|
|
|
|
case NODE_FALSE:
|
|
|
|
useless = "false";
|
|
|
|
break;
|
|
|
|
case NODE_DEFINED:
|
|
|
|
useless = "defined?";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useless) {
|
|
|
|
int line = ruby_sourceline;
|
|
|
|
|
|
|
|
ruby_sourceline = nd_line(node);
|
|
|
|
rb_warn("useless use of %s in void context", useless);
|
|
|
|
ruby_sourceline = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
void_stmts(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
if (!ruby_verbose) return;
|
|
|
|
if (!node) return;
|
|
|
|
if (nd_type(node) != NODE_BLOCK) return;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!node->nd_next) return;
|
|
|
|
void_expr(node->nd_head);
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int
|
|
|
|
assign_in_cond(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_MASGN:
|
|
|
|
yyerror("multiple assignment in conditional");
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
|
|
|
case NODE_GASGN:
|
|
|
|
case NODE_IASGN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NODE_NEWLINE:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nd_type(node->nd_value)) {
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_NIL:
|
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_FALSE:
|
|
|
|
/* reports always */
|
|
|
|
rb_warn("found = in conditional, should be ==");
|
|
|
|
return 1;
|
|
|
|
|
2000-10-10 11:03:36 +04:00
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_EVSTR:
|
|
|
|
case NODE_DREGX:
|
1999-01-20 07:59:39 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-10-10 11:03:36 +04:00
|
|
|
#if 0
|
1999-01-20 07:59:39 +03:00
|
|
|
if (assign_in_cond(node->nd_value) == 0) {
|
|
|
|
rb_warning("assignment in condition");
|
|
|
|
}
|
2000-10-10 11:03:36 +04:00
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-02-08 12:19:27 +03:00
|
|
|
static int
|
|
|
|
e_option_supplied()
|
|
|
|
{
|
|
|
|
if (strcmp(ruby_sourcefile, "-e") == 0)
|
|
|
|
return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2000-12-28 08:00:47 +03:00
|
|
|
static void
|
|
|
|
warn_unless_e_option(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
2001-03-13 08:45:13 +03:00
|
|
|
if (!e_option_supplied()) rb_warn(str);
|
2001-02-08 12:19:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
warning_unless_e_option(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
2001-03-13 08:45:13 +03:00
|
|
|
if (!e_option_supplied()) rb_warning(str);
|
2000-12-28 08:00:47 +03:00
|
|
|
}
|
|
|
|
|
2001-02-19 10:03:06 +03:00
|
|
|
static NODE *cond0();
|
|
|
|
|
|
|
|
static NODE*
|
2001-08-14 12:13:31 +04:00
|
|
|
range_op(node)
|
2001-02-19 10:03:06 +03:00
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
enum node_type type;
|
|
|
|
|
|
|
|
if (!e_option_supplied()) return node;
|
|
|
|
|
|
|
|
node = cond0(node);
|
|
|
|
type = nd_type(node);
|
|
|
|
if (type == NODE_NEWLINE) node = node->nd_next;
|
|
|
|
if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
|
2001-08-14 12:13:31 +04:00
|
|
|
warn_unless_e_option("integer literal in conditional range");
|
2001-02-19 10:03:06 +03:00
|
|
|
return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static NODE*
|
2001-08-14 12:13:31 +04:00
|
|
|
cond0(node)
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
enum node_type type = nd_type(node);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
assign_in_cond(node);
|
2001-08-06 07:05:23 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
switch (type) {
|
2000-12-27 08:59:03 +03:00
|
|
|
case NODE_DSTR:
|
2001-03-13 08:45:13 +03:00
|
|
|
case NODE_STR:
|
2001-03-13 09:00:50 +03:00
|
|
|
rb_warn("string literal in condition");
|
2001-03-13 08:45:13 +03:00
|
|
|
break;
|
2001-02-08 12:19:27 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
2001-02-08 12:19:27 +03:00
|
|
|
warning_unless_e_option("regex literal in condition");
|
1998-01-16 15:13:05 +03:00
|
|
|
local_cnt('_');
|
|
|
|
local_cnt('~');
|
1998-01-16 15:19:22 +03:00
|
|
|
return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-14 12:13:31 +04:00
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:
|
|
|
|
node->nd_1st = cond0(node->nd_1st);
|
|
|
|
node->nd_2nd = cond0(node->nd_2nd);
|
|
|
|
break;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_DOT2:
|
|
|
|
case NODE_DOT3:
|
2001-08-14 12:13:31 +04:00
|
|
|
node->nd_beg = range_op(node->nd_beg);
|
|
|
|
node->nd_end = range_op(node->nd_end);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (type == NODE_DOT2) nd_set_type(node,NODE_FLIP2);
|
|
|
|
else if (type == NODE_DOT3) nd_set_type(node, NODE_FLIP3);
|
2001-09-20 10:23:50 +04:00
|
|
|
node->nd_cnt = local_append(internal_id());
|
2001-03-13 12:00:01 +03:00
|
|
|
warning_unless_e_option("range literal in condition");
|
2000-12-28 08:00:47 +03:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case NODE_LIT:
|
2001-02-19 10:03:06 +03:00
|
|
|
if (TYPE(node->nd_lit) == T_REGEXP) {
|
2001-08-14 12:13:31 +04:00
|
|
|
warn_unless_e_option("regex literal in condition");
|
2000-12-27 08:59:03 +03:00
|
|
|
nd_set_type(node, NODE_MATCH);
|
1998-01-16 15:13:05 +03:00
|
|
|
local_cnt('_');
|
|
|
|
local_cnt('~');
|
|
|
|
}
|
2001-08-14 12:13:31 +04:00
|
|
|
else {
|
|
|
|
rb_warning("literal in condition");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-12-27 08:59:03 +03:00
|
|
|
return node;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
2001-08-14 12:13:31 +04:00
|
|
|
cond(node)
|
1998-01-16 15:13:05 +03:00
|
|
|
NODE *node;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (node == 0) return 0;
|
|
|
|
if (nd_type(node) == NODE_NEWLINE){
|
2001-08-14 12:13:31 +04:00
|
|
|
node->nd_next = cond0(node->nd_next);
|
1998-01-16 15:13:05 +03:00
|
|
|
return node;
|
|
|
|
}
|
2001-08-14 12:13:31 +04:00
|
|
|
return cond0(node);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static NODE*
|
|
|
|
logop(type, left, right)
|
|
|
|
enum node_type type;
|
|
|
|
NODE *left, *right;
|
|
|
|
{
|
|
|
|
value_expr(left);
|
2001-08-14 12:13:31 +04:00
|
|
|
return rb_node_newnode(type, left, right, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
static NODE *
|
|
|
|
ret_args(node)
|
|
|
|
NODE *node;
|
|
|
|
{
|
|
|
|
if (node) {
|
2001-06-22 13:12:24 +04:00
|
|
|
if (nd_type(node) == NODE_BLOCK_PASS) {
|
2001-05-30 13:12:34 +04:00
|
|
|
rb_compile_error("block argument should not be given");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static NODE *
|
|
|
|
arg_blk_pass(node1, node2)
|
|
|
|
NODE *node1;
|
|
|
|
NODE *node2;
|
|
|
|
{
|
|
|
|
if (node2) {
|
|
|
|
node2->nd_head = node1;
|
|
|
|
return node2;
|
|
|
|
}
|
|
|
|
return node1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
static NODE*
|
|
|
|
arg_prepend(node1, node2)
|
|
|
|
NODE *node1, *node2;
|
|
|
|
{
|
|
|
|
switch (nodetype(node2)) {
|
|
|
|
case NODE_ARRAY:
|
|
|
|
return list_concat(NEW_LIST(node1), node2);
|
|
|
|
|
|
|
|
case NODE_RESTARGS:
|
|
|
|
return arg_concat(node1, node2->nd_head);
|
|
|
|
|
|
|
|
case NODE_BLOCK_PASS:
|
|
|
|
node2->nd_body = arg_prepend(node1, node2->nd_body);
|
|
|
|
return node2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rb_bug("unknown nodetype(%d) for arg_prepend");
|
|
|
|
}
|
|
|
|
return 0; /* not reached */
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static NODE*
|
|
|
|
new_call(r,m,a)
|
|
|
|
NODE *r;
|
|
|
|
ID m;
|
|
|
|
NODE *a;
|
|
|
|
{
|
|
|
|
if (a && nd_type(a) == NODE_BLOCK_PASS) {
|
|
|
|
a->nd_iter = NEW_CALL(r,m,a->nd_head);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
return NEW_CALL(r,m,a);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static NODE*
|
|
|
|
new_fcall(m,a)
|
|
|
|
ID m;
|
|
|
|
NODE *a;
|
|
|
|
{
|
|
|
|
if (a && nd_type(a) == NODE_BLOCK_PASS) {
|
|
|
|
a->nd_iter = NEW_FCALL(m,a->nd_head);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
return NEW_FCALL(m,a);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-06-23 11:05:59 +04:00
|
|
|
static NODE*
|
|
|
|
new_super(a)
|
|
|
|
NODE *a;
|
|
|
|
{
|
|
|
|
if (a && nd_type(a) == NODE_BLOCK_PASS) {
|
|
|
|
a->nd_iter = NEW_SUPER(a->nd_head);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
return NEW_SUPER(a);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static struct local_vars {
|
|
|
|
ID *tbl;
|
|
|
|
int nofree;
|
|
|
|
int cnt;
|
|
|
|
int dlev;
|
|
|
|
struct local_vars *prev;
|
|
|
|
} *lvtbl;
|
|
|
|
|
|
|
|
static void
|
|
|
|
local_push()
|
|
|
|
{
|
|
|
|
struct local_vars *local;
|
|
|
|
|
|
|
|
local = ALLOC(struct local_vars);
|
|
|
|
local->prev = lvtbl;
|
|
|
|
local->nofree = 0;
|
|
|
|
local->cnt = 0;
|
|
|
|
local->tbl = 0;
|
|
|
|
local->dlev = 0;
|
|
|
|
lvtbl = local;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
local_pop()
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
struct local_vars *local = lvtbl->prev;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lvtbl->tbl) {
|
|
|
|
if (!lvtbl->nofree) free(lvtbl->tbl);
|
|
|
|
else lvtbl->tbl[0] = lvtbl->cnt;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
free(lvtbl);
|
|
|
|
lvtbl = local;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ID*
|
|
|
|
local_tbl()
|
|
|
|
{
|
|
|
|
lvtbl->nofree = 1;
|
|
|
|
return lvtbl->tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-01-20 07:59:39 +03:00
|
|
|
local_append(id)
|
1998-01-16 15:13:05 +03:00
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
if (lvtbl->tbl == 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
lvtbl->tbl = ALLOC_N(ID, 4);
|
1998-01-16 15:13:05 +03:00
|
|
|
lvtbl->tbl[0] = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
lvtbl->tbl[1] = '_';
|
|
|
|
lvtbl->tbl[2] = '~';
|
|
|
|
lvtbl->cnt = 2;
|
|
|
|
if (id == '_') return 0;
|
|
|
|
if (id == '~') return 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
REALLOC_N(lvtbl->tbl, ID, lvtbl->cnt+2);
|
|
|
|
}
|
|
|
|
|
|
|
|
lvtbl->tbl[lvtbl->cnt+1] = id;
|
|
|
|
return lvtbl->cnt++;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static int
|
|
|
|
local_cnt(id)
|
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
int cnt, max;
|
|
|
|
|
|
|
|
if (id == 0) return lvtbl->cnt;
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
for (cnt=1, max=lvtbl->cnt+1; cnt<max;cnt++) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lvtbl->tbl[cnt] == id) return cnt-1;
|
|
|
|
}
|
|
|
|
return local_append(id);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
|
|
|
local_id(id)
|
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
int i, max;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (lvtbl == 0) return Qfalse;
|
|
|
|
for (i=3, max=lvtbl->cnt+1; i<max; i++) {
|
|
|
|
if (lvtbl->tbl[i] == id) return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
top_local_init()
|
|
|
|
{
|
|
|
|
local_push();
|
1999-01-20 07:59:39 +03:00
|
|
|
lvtbl->cnt = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (lvtbl->cnt > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+3);
|
|
|
|
MEMCPY(lvtbl->tbl, ruby_scope->local_tbl, ID, lvtbl->cnt+1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lvtbl->tbl = 0;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ruby_dyna_vars)
|
1998-01-16 15:13:05 +03:00
|
|
|
lvtbl->dlev = 1;
|
|
|
|
else
|
|
|
|
lvtbl->dlev = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
top_local_setup()
|
|
|
|
{
|
|
|
|
int len = lvtbl->cnt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (len > 0) {
|
1999-08-13 09:45:20 +04:00
|
|
|
i = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (i < len) {
|
2001-02-02 14:38:20 +03:00
|
|
|
if (i == 0 || (ruby_scope->flags & SCOPE_MALLOC) == 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE *vars = ALLOC_N(VALUE, len+1);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ruby_scope->local_vars) {
|
|
|
|
*vars++ = ruby_scope->local_vars[-1];
|
|
|
|
MEMCPY(vars, ruby_scope->local_vars, VALUE, i);
|
|
|
|
rb_mem_clear(vars+i, len-i);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*vars++ = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_mem_clear(vars, len);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_scope->local_vars = vars;
|
2001-02-02 14:38:20 +03:00
|
|
|
ruby_scope->flags |= SCOPE_MALLOC;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE *vars = ruby_scope->local_vars-1;
|
1998-01-16 15:13:05 +03:00
|
|
|
REALLOC_N(vars, VALUE, len+1);
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_scope->local_vars = vars+1;
|
|
|
|
rb_mem_clear(ruby_scope->local_vars+i, len-i);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ruby_scope->local_tbl && ruby_scope->local_vars[-1] == 0) {
|
|
|
|
free(ruby_scope->local_tbl);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_scope->local_vars[-1] = 0;
|
|
|
|
ruby_scope->local_tbl = local_tbl();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
local_pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct RVarmap*
|
|
|
|
dyna_push()
|
|
|
|
{
|
2000-02-01 06:12:21 +03:00
|
|
|
struct RVarmap* vars = ruby_dyna_vars;
|
|
|
|
|
|
|
|
rb_dvar_push(0, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
lvtbl->dlev++;
|
2000-02-01 06:12:21 +03:00
|
|
|
return vars;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dyna_pop(vars)
|
|
|
|
struct RVarmap* vars;
|
|
|
|
{
|
|
|
|
lvtbl->dlev--;
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_dyna_vars = vars;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dyna_in_block()
|
|
|
|
{
|
|
|
|
return (lvtbl->dlev > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_parser_append_print()
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree =
|
|
|
|
block_append(ruby_eval_tree,
|
1998-01-16 15:19:22 +03:00
|
|
|
NEW_FCALL(rb_intern("print"),
|
|
|
|
NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_parser_while_loop(chop, split)
|
1998-01-16 15:13:05 +03:00
|
|
|
int chop, split;
|
|
|
|
{
|
|
|
|
if (split) {
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree =
|
1998-01-16 15:13:05 +03:00
|
|
|
block_append(NEW_GASGN(rb_intern("$F"),
|
|
|
|
NEW_CALL(NEW_GVAR(rb_intern("$_")),
|
|
|
|
rb_intern("split"), 0)),
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (chop) {
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree =
|
1998-01-16 15:13:05 +03:00
|
|
|
block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_intern("chop!"), 0), ruby_eval_tree);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_eval_tree = NEW_OPT_N(ruby_eval_tree);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static struct {
|
|
|
|
ID token;
|
|
|
|
char *name;
|
|
|
|
} op_tbl[] = {
|
|
|
|
tDOT2, "..",
|
1999-08-13 09:45:20 +04:00
|
|
|
tDOT3, "...",
|
1998-01-16 15:13:05 +03:00
|
|
|
'+', "+",
|
|
|
|
'-', "-",
|
|
|
|
'+', "+(binary)",
|
|
|
|
'-', "-(binary)",
|
|
|
|
'*', "*",
|
|
|
|
'/', "/",
|
|
|
|
'%', "%",
|
1999-01-20 07:59:39 +03:00
|
|
|
tPOW, "**",
|
|
|
|
tUPLUS, "+@",
|
|
|
|
tUMINUS, "-@",
|
|
|
|
tUPLUS, "+(unary)",
|
|
|
|
tUMINUS, "-(unary)",
|
1998-01-16 15:13:05 +03:00
|
|
|
'|', "|",
|
|
|
|
'^', "^",
|
|
|
|
'&', "&",
|
1999-01-20 07:59:39 +03:00
|
|
|
tCMP, "<=>",
|
1998-01-16 15:13:05 +03:00
|
|
|
'>', ">",
|
1999-01-20 07:59:39 +03:00
|
|
|
tGEQ, ">=",
|
1998-01-16 15:13:05 +03:00
|
|
|
'<', "<",
|
1999-01-20 07:59:39 +03:00
|
|
|
tLEQ, "<=",
|
|
|
|
tEQ, "==",
|
|
|
|
tEQQ, "===",
|
|
|
|
tNEQ, "!=",
|
|
|
|
tMATCH, "=~",
|
|
|
|
tNMATCH, "!~",
|
1998-01-16 15:13:05 +03:00
|
|
|
'!', "!",
|
|
|
|
'~', "~",
|
|
|
|
'!', "!(unary)",
|
|
|
|
'~', "~(unary)",
|
|
|
|
'!', "!@",
|
|
|
|
'~', "~@",
|
1999-01-20 07:59:39 +03:00
|
|
|
tAREF, "[]",
|
|
|
|
tASET, "[]=",
|
|
|
|
tLSHFT, "<<",
|
|
|
|
tRSHFT, ">>",
|
|
|
|
tCOLON2, "::",
|
1998-01-16 15:13:05 +03:00
|
|
|
'`', "`",
|
|
|
|
0, 0,
|
|
|
|
};
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static st_table *sym_tbl;
|
|
|
|
static st_table *sym_rev_tbl;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
Init_sym()
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
sym_tbl = st_init_strtable_with_size(200);
|
|
|
|
sym_rev_tbl = st_init_numtable_with_size(200);
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_global_variable((VALUE*)&lex_lastline);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-09-20 10:23:50 +04:00
|
|
|
static ID last_id = LAST_TOKEN;
|
|
|
|
|
|
|
|
static ID
|
|
|
|
internal_id()
|
|
|
|
{
|
|
|
|
return ID_INTERNAL | (++last_id << ID_SCOPE_SHIFT);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
ID
|
|
|
|
rb_intern(name)
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *name;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-06-05 11:50:59 +04:00
|
|
|
const char *m = name;
|
2000-05-22 11:29:50 +04:00
|
|
|
ID id;
|
1998-01-16 15:13:05 +03:00
|
|
|
int last;
|
|
|
|
|
|
|
|
if (st_lookup(sym_tbl, name, &id))
|
|
|
|
return id;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
id = 0;
|
2001-06-05 11:50:59 +04:00
|
|
|
switch (*name) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case '$':
|
|
|
|
id |= ID_GLOBAL;
|
2001-06-05 11:50:59 +04:00
|
|
|
m++;
|
|
|
|
if (!is_identchar(*m)) m++;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case '@':
|
2001-06-05 11:50:59 +04:00
|
|
|
if (name[1] == '@') {
|
|
|
|
m++;
|
2000-03-23 11:37:35 +03:00
|
|
|
id |= ID_CLASS;
|
2001-06-05 11:50:59 +04:00
|
|
|
}
|
|
|
|
else {
|
2000-02-18 09:59:36 +03:00
|
|
|
id |= ID_INSTANCE;
|
2001-06-05 11:50:59 +04:00
|
|
|
}
|
|
|
|
m++;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (name[0] != '_' && !ISALPHA(name[0]) && !ismbchar(name[0])) {
|
2001-06-05 11:50:59 +04:00
|
|
|
/* operators */
|
1998-01-16 15:13:05 +03:00
|
|
|
int i;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (i=0; op_tbl[i].token; i++) {
|
|
|
|
if (*op_tbl[i].name == *name &&
|
|
|
|
strcmp(op_tbl[i].name, name) == 0) {
|
|
|
|
id = op_tbl[i].token;
|
|
|
|
goto id_regist;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
last = strlen(name)-1;
|
|
|
|
if (name[last] == '=') {
|
|
|
|
/* attribute assignment */
|
|
|
|
char *buf = ALLOCA_N(char,last+1);
|
|
|
|
|
|
|
|
strncpy(buf, name, last);
|
|
|
|
buf[last] = '\0';
|
|
|
|
id = rb_intern(buf);
|
1999-10-12 08:53:36 +04:00
|
|
|
if (id > LAST_TOKEN && !is_attrset_id(id)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
id = rb_id_attrset(id);
|
|
|
|
goto id_regist;
|
|
|
|
}
|
1999-10-12 08:53:36 +04:00
|
|
|
id = ID_ATTRSET;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (ISUPPER(name[0])) {
|
1999-12-14 09:50:43 +03:00
|
|
|
id = ID_CONST;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
id = ID_LOCAL;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-06-05 11:50:59 +04:00
|
|
|
while (*m && is_identchar(*m)) {
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
if (*m) id = ID_JUNK;
|
1999-01-20 07:59:39 +03:00
|
|
|
id |= ++last_id << ID_SCOPE_SHIFT;
|
|
|
|
id_regist:
|
|
|
|
name = strdup(name);
|
|
|
|
st_add_direct(sym_tbl, name, id);
|
|
|
|
st_add_direct(sym_rev_tbl, id, name);
|
1998-01-16 15:13:05 +03:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
rb_id2name(id)
|
|
|
|
ID id;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
char *name;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (id < LAST_TOKEN) {
|
|
|
|
int i = 0;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (i=0; op_tbl[i].token; i++) {
|
|
|
|
if (op_tbl[i].token == id)
|
|
|
|
return op_tbl[i].name;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (st_lookup(sym_rev_tbl, id, &name))
|
|
|
|
return name;
|
|
|
|
|
|
|
|
if (is_attrset_id(id)) {
|
2000-06-05 12:46:59 +04:00
|
|
|
ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-06-05 12:46:59 +04:00
|
|
|
again:
|
|
|
|
name = rb_id2name(id2);
|
|
|
|
if (name) {
|
|
|
|
char *buf = ALLOCA_N(char, strlen(name)+2);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-06-05 12:46:59 +04:00
|
|
|
strcpy(buf, name);
|
1998-01-16 15:13:05 +03:00
|
|
|
strcat(buf, "=");
|
|
|
|
rb_intern(buf);
|
|
|
|
return rb_id2name(id);
|
|
|
|
}
|
2000-06-05 12:46:59 +04:00
|
|
|
if (is_local_id(id2)) {
|
|
|
|
id2 = (id & ~ID_SCOPE_MASK) | ID_CONST;
|
|
|
|
goto again;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
static int
|
|
|
|
symbols_i(key, value, ary)
|
|
|
|
char *key;
|
|
|
|
ID value;
|
|
|
|
VALUE ary;
|
|
|
|
{
|
|
|
|
rb_ary_push(ary, ID2SYM(value));
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_sym_all_symbols()
|
|
|
|
{
|
|
|
|
VALUE ary = rb_ary_new2(sym_tbl->num_entries);
|
|
|
|
|
|
|
|
st_foreach(sym_tbl, symbols_i, ary);
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
1999-11-17 10:30:37 +03:00
|
|
|
int
|
|
|
|
rb_is_const_id(id)
|
|
|
|
ID id;
|
|
|
|
{
|
1999-12-14 09:50:43 +03:00
|
|
|
if (is_const_id(id)) return Qtrue;
|
|
|
|
return Qfalse;
|
1999-11-17 10:30:37 +03:00
|
|
|
}
|
|
|
|
|
2000-02-18 09:59:36 +03:00
|
|
|
int
|
2000-03-23 11:37:35 +03:00
|
|
|
rb_is_class_id(id)
|
2000-02-18 09:59:36 +03:00
|
|
|
ID id;
|
|
|
|
{
|
2000-03-23 11:37:35 +03:00
|
|
|
if (is_class_id(id)) return Qtrue;
|
2000-02-18 09:59:36 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
int
|
|
|
|
rb_is_instance_id(id)
|
|
|
|
ID id;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (is_instance_id(id)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-09-20 10:23:50 +04:00
|
|
|
int
|
|
|
|
rb_is_local_id(id)
|
|
|
|
ID id;
|
|
|
|
{
|
|
|
|
if (is_local_id(id)) return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
|
|
|
special_local_set(c, val)
|
|
|
|
char c;
|
|
|
|
VALUE val;
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
int cnt;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
top_local_init();
|
|
|
|
cnt = local_cnt(c);
|
|
|
|
top_local_setup();
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_scope->local_vars[cnt] = val;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-09-20 10:23:50 +04:00
|
|
|
VALUE *rb_svar _((int cnt));
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_backref_get()
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-09-20 10:23:50 +04:00
|
|
|
VALUE *var = rb_svar(1);
|
|
|
|
if (var) {
|
|
|
|
return *var;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_backref_set(val)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE val;
|
|
|
|
{
|
2001-09-20 10:23:50 +04:00
|
|
|
VALUE *var = rb_svar(1);
|
|
|
|
if (var) {
|
|
|
|
*var = val;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
special_local_set('~', val);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_lastline_get()
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-09-20 10:23:50 +04:00
|
|
|
VALUE *var = rb_svar(0);
|
|
|
|
if (var) {
|
|
|
|
return *var;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_lastline_set(val)
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE val;
|
|
|
|
{
|
2001-09-20 10:23:50 +04:00
|
|
|
VALUE *var = rb_svar(0);
|
|
|
|
if (var) {
|
|
|
|
*var = val;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
special_local_set('_', val);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|