Commit 29133b2f authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Use `mrb_intern_lit` if possible in `parse.y`

parent 37c8cbe7
...@@ -103,12 +103,7 @@ intern_gen(parser_state *p, const char *s, size_t len) ...@@ -103,12 +103,7 @@ intern_gen(parser_state *p, const char *s, size_t len)
} }
#define intern(s,len) intern_gen(p,(s),(len)) #define intern(s,len) intern_gen(p,(s),(len))
static inline mrb_sym #define intern_lit(s) mrb_intern_lit(p->mrb, s)
intern_gen_c(parser_state *p, const char c)
{
return mrb_intern(p->mrb, &c, 1);
}
#define intern_c(c) intern_gen_c(p,(c))
static void static void
cons_free_gen(parser_state *p, node *cons) cons_free_gen(parser_state *p, node *cons)
...@@ -875,7 +870,7 @@ new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b) ...@@ -875,7 +870,7 @@ new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
static node* static node*
new_imaginary(parser_state *p, node *imaginary) new_imaginary(parser_state *p, node *imaginary)
{ {
return new_call(p, new_const(p, intern_cstr("Kernel")), intern_cstr("Complex"), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1); return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Complex"), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1);
} }
#endif #endif
...@@ -883,7 +878,7 @@ new_imaginary(parser_state *p, node *imaginary) ...@@ -883,7 +878,7 @@ new_imaginary(parser_state *p, node *imaginary)
static node* static node*
new_rational(parser_state *p, node *rational) new_rational(parser_state *p, node *rational)
{ {
return new_call(p, new_const(p, intern_cstr("Kernel")), intern_cstr("Rational"), list1(list1(rational)), 1); return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Rational"), list1(list1(rational)), 1);
} }
#endif #endif
...@@ -1622,7 +1617,7 @@ command_asgn : lhs '=' command_rhs ...@@ -1622,7 +1617,7 @@ command_asgn : lhs '=' command_rhs
} }
| primary_value '[' opt_call_args ']' tOP_ASGN command_rhs | primary_value '[' opt_call_args ']' tOP_ASGN command_rhs
{ {
$$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6);
} }
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
{ {
...@@ -1851,7 +1846,7 @@ mlhs_node : variable ...@@ -1851,7 +1846,7 @@ mlhs_node : variable
} }
| primary_value '[' opt_call_args ']' | primary_value '[' opt_call_args ']'
{ {
$$ = new_call(p, $1, intern("[]",2), $3, '.'); $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
} }
| primary_value call_op tIDENTIFIER | primary_value call_op tIDENTIFIER
{ {
...@@ -1890,7 +1885,7 @@ lhs : variable ...@@ -1890,7 +1885,7 @@ lhs : variable
} }
| primary_value '[' opt_call_args ']' | primary_value '[' opt_call_args ']'
{ {
$$ = new_call(p, $1, intern("[]",2), $3, '.'); $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
} }
| primary_value call_op tIDENTIFIER | primary_value call_op tIDENTIFIER
{ {
...@@ -1974,36 +1969,36 @@ undef_list : fsym ...@@ -1974,36 +1969,36 @@ undef_list : fsym
} }
; ;
op : '|' { $$ = intern_c('|'); } op : '|' { $$ = intern_lit("|"); }
| '^' { $$ = intern_c('^'); } | '^' { $$ = intern_lit("^"); }
| '&' { $$ = intern_c('&'); } | '&' { $$ = intern_lit("&"); }
| tCMP { $$ = intern("<=>",3); } | tCMP { $$ = intern_lit("<=>"); }
| tEQ { $$ = intern("==",2); } | tEQ { $$ = intern_lit("=="); }
| tEQQ { $$ = intern("===",3); } | tEQQ { $$ = intern_lit("==="); }
| tMATCH { $$ = intern("=~",2); } | tMATCH { $$ = intern_lit("=~"); }
| tNMATCH { $$ = intern("!~",2); } | tNMATCH { $$ = intern_lit("!~"); }
| '>' { $$ = intern_c('>'); } | '>' { $$ = intern_lit(">"); }
| tGEQ { $$ = intern(">=",2); } | tGEQ { $$ = intern_lit(">="); }
| '<' { $$ = intern_c('<'); } | '<' { $$ = intern_lit("<"); }
| tLEQ { $$ = intern("<=",2); } | tLEQ { $$ = intern_lit("<="); }
| tNEQ { $$ = intern("!=",2); } | tNEQ { $$ = intern_lit("!="); }
| tLSHFT { $$ = intern("<<",2); } | tLSHFT { $$ = intern_lit("<<"); }
| tRSHFT { $$ = intern(">>",2); } | tRSHFT { $$ = intern_lit(">>"); }
| '+' { $$ = intern_c('+'); } | '+' { $$ = intern_lit("+"); }
| '-' { $$ = intern_c('-'); } | '-' { $$ = intern_lit("-"); }
| '*' { $$ = intern_c('*'); } | '*' { $$ = intern_lit("*"); }
| tSTAR { $$ = intern_c('*'); } | tSTAR { $$ = intern_lit("*"); }
| '/' { $$ = intern_c('/'); } | '/' { $$ = intern_lit("/"); }
| '%' { $$ = intern_c('%'); } | '%' { $$ = intern_lit("%"); }
| tPOW { $$ = intern("**",2); } | tPOW { $$ = intern_lit("**"); }
| tDSTAR { $$ = intern("**",2); } | tDSTAR { $$ = intern_lit("**"); }
| '!' { $$ = intern_c('!'); } | '!' { $$ = intern_lit("!"); }
| '~' { $$ = intern_c('~'); } | '~' { $$ = intern_lit("~"); }
| tUPLUS { $$ = intern("+@",2); } | tUPLUS { $$ = intern_lit("+@"); }
| tUMINUS { $$ = intern("-@",2); } | tUMINUS { $$ = intern_lit("-@"); }
| tAREF { $$ = intern("[]",2); } | tAREF { $$ = intern_lit("[]"); }
| tASET { $$ = intern("[]=",3); } | tASET { $$ = intern_lit("[]="); }
| '`' { $$ = intern_c('`'); } | '`' { $$ = intern_lit("`"); }
; ;
reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
...@@ -2030,7 +2025,7 @@ arg : lhs '=' arg_rhs ...@@ -2030,7 +2025,7 @@ arg : lhs '=' arg_rhs
} }
| primary_value '[' opt_call_args ']' tOP_ASGN arg_rhs | primary_value '[' opt_call_args ']' tOP_ASGN arg_rhs
{ {
$$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6);
} }
| primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
{ {
...@@ -2915,11 +2910,11 @@ method_call : operation paren_args ...@@ -2915,11 +2910,11 @@ method_call : operation paren_args
} }
| primary_value call_op paren_args | primary_value call_op paren_args
{ {
$$ = new_call(p, $1, intern("call",4), $3, $2); $$ = new_call(p, $1, intern_lit("call"), $3, $2);
} }
| primary_value tCOLON2 paren_args | primary_value tCOLON2 paren_args
{ {
$$ = new_call(p, $1, intern("call",4), $3, tCOLON2); $$ = new_call(p, $1, intern_lit("call"), $3, tCOLON2);
} }
| keyword_super paren_args | keyword_super paren_args
{ {
...@@ -2931,7 +2926,7 @@ method_call : operation paren_args ...@@ -2931,7 +2926,7 @@ method_call : operation paren_args
} }
| primary_value '[' opt_call_args ']' | primary_value '[' opt_call_args ']'
{ {
$$ = new_call(p, $1, intern("[]",2), $3, '.'); $$ = new_call(p, $1, intern_lit("[]"), $3, '.');
} }
; ;
...@@ -4818,7 +4813,7 @@ parser_yylex(parser_state *p) ...@@ -4818,7 +4813,7 @@ parser_yylex(parser_state *p)
case '*': case '*':
if ((c = nextc(p)) == '*') { if ((c = nextc(p)) == '*') {
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern("**",2); pylval.id = intern_lit("**");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -4836,7 +4831,7 @@ parser_yylex(parser_state *p) ...@@ -4836,7 +4831,7 @@ parser_yylex(parser_state *p)
} }
else { else {
if (c == '=') { if (c == '=') {
pylval.id = intern_c('*'); pylval.id = intern_lit("*");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -4952,7 +4947,7 @@ parser_yylex(parser_state *p) ...@@ -4952,7 +4947,7 @@ parser_yylex(parser_state *p)
} }
if (c == '<') { if (c == '<') {
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern("<<",2); pylval.id = intern_lit("<<");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -4974,7 +4969,7 @@ parser_yylex(parser_state *p) ...@@ -4974,7 +4969,7 @@ parser_yylex(parser_state *p)
} }
if (c == '>') { if (c == '>') {
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern(">>",2); pylval.id = intern_lit(">>");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5082,7 +5077,7 @@ parser_yylex(parser_state *p) ...@@ -5082,7 +5077,7 @@ parser_yylex(parser_state *p)
if ((c = nextc(p)) == '&') { if ((c = nextc(p)) == '&') {
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern("&&",2); pylval.id = intern_lit("&&");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5094,7 +5089,7 @@ parser_yylex(parser_state *p) ...@@ -5094,7 +5089,7 @@ parser_yylex(parser_state *p)
return tANDDOT; return tANDDOT;
} }
else if (c == '=') { else if (c == '=') {
pylval.id = intern_c('&'); pylval.id = intern_lit("&");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5121,7 +5116,7 @@ parser_yylex(parser_state *p) ...@@ -5121,7 +5116,7 @@ parser_yylex(parser_state *p)
if ((c = nextc(p)) == '|') { if ((c = nextc(p)) == '|') {
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern("||",2); pylval.id = intern_lit("||");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5129,7 +5124,7 @@ parser_yylex(parser_state *p) ...@@ -5129,7 +5124,7 @@ parser_yylex(parser_state *p)
return tOROP; return tOROP;
} }
if (c == '=') { if (c == '=') {
pylval.id = intern_c('|'); pylval.id = intern_lit("|");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5153,7 +5148,7 @@ parser_yylex(parser_state *p) ...@@ -5153,7 +5148,7 @@ parser_yylex(parser_state *p)
return '+'; return '+';
} }
if (c == '=') { if (c == '=') {
pylval.id = intern_c('+'); pylval.id = intern_lit("+");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5181,7 +5176,7 @@ parser_yylex(parser_state *p) ...@@ -5181,7 +5176,7 @@ parser_yylex(parser_state *p)
return '-'; return '-';
} }
if (c == '=') { if (c == '=') {
pylval.id = intern_c('-'); pylval.id = intern_lit("-");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5515,7 +5510,7 @@ parser_yylex(parser_state *p) ...@@ -5515,7 +5510,7 @@ parser_yylex(parser_state *p)
return tREGEXP_BEG; return tREGEXP_BEG;
} }
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern_c('/'); pylval.id = intern_lit("/");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5534,7 +5529,7 @@ parser_yylex(parser_state *p) ...@@ -5534,7 +5529,7 @@ parser_yylex(parser_state *p)
case '^': case '^':
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern_c('^'); pylval.id = intern_lit("^");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
...@@ -5711,7 +5706,7 @@ parser_yylex(parser_state *p) ...@@ -5711,7 +5706,7 @@ parser_yylex(parser_state *p)
} }
} }
if ((c = nextc(p)) == '=') { if ((c = nextc(p)) == '=') {
pylval.id = intern_c('%'); pylval.id = intern_lit("%");
p->lstate = EXPR_BEG; p->lstate = EXPR_BEG;
return tOP_ASGN; return tOP_ASGN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment