Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Saturday, June 5, 2010

Incremental Operator in Rubinius

plusplus

patch:

diff --git a/lib/ext/melbourne/grammar.y b/lib/ext/melbourne/grammar.y
index 0536bda..43c9570 100644
--- a/lib/ext/melbourne/grammar.y
+++ b/lib/ext/melbourne/grammar.y
@@ -368,6 +368,7 @@ static NODE *extract_block_vars(rb_parse_state *parse_state, NODE* node, var_tab
%type <id> cname fname op f_rest_arg
%type <num> f_norm_arg f_arg
%token tUPLUS /* unary+ */
+%token tINCR /* ++var */
%token tUMINUS /* unary- */
%token tUBS /* unary\ */
%token tPOW /* ** */
@@ -1042,6 +1043,7 @@ op : '|' { $$ = '|'; }
| tPOW { $$ = tPOW; }
| '~' { $$ = '~'; }
| tUPLUS { $$ = tUPLUS; }
+ | tINCR { $$ = tINCR; }
| tUMINUS { $$ = tUMINUS; }
| tAREF { $$ = tAREF; }
| tASET { $$ = tASET; }
@@ -2386,6 +2388,11 @@ var_ref : variable
{
$$ = gettable($1);
}
+ | tINCR variable
+ {
+ $$ = assignable($2, 0, vps);
+ $$->nd_value = NEW_CALL(gettable($$->nd_vid), rb_parser_sym("succ"), 0);
+ }
;
var_lhs : variable
@@ -3959,6 +3966,9 @@ yylex(void *yylval_v, void *vstate)
case '+':
c = nextc();
+ if (c == '+') {
+ return tINCR;
+ }
if (parse_state->lex_state == EXPR_FNAME || parse_state->lex_state == EXPR_DOT) {
parse_state->lex_state = EXPR_ARG;
if (c == '@') {
@@ -5023,6 +5033,7 @@ static const struct {
{'%', "%"},
{tPOW, "**"},
{tUPLUS, "+@"},
+ {tINCR, "++@"},
{tUMINUS, "-@"},
{tUPLUS, "+(unary)"},
{tUMINUS, "-(unary)"},
@@ -5411,6 +5422,7 @@ void_expr0(NODE *node, rb_parse_state *parse_state)
case '%':
case tPOW:
case tUPLUS:
+ case tINCR:
case tUMINUS:
case '|':
case '^':
view raw gistfile1.txt hosted with ❤ by GitHub

Followers