aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 15:00:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-31 15:00:37 +0000
commit67c574736912003c377218153f9d3b9c0c96a17b (patch)
tree558aea841613b06f6913d1ab22942aecc531a317 /parse.y
parent4a6f7633303f2d6eb5ec164dc656cf5d47531960 (diff)
downloadruby-67c574736912003c377218153f9d3b9c0c96a17b.tar.gz
Method reference operator
Introduce the new operator for method reference, `.:`. [Feature #12125] [Feature #13581] [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y28
1 files changed, 27 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index 09afa6bedd..cf00b60b72 100644
--- a/parse.y
+++ b/parse.y
@@ -886,6 +886,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%token tRSHFT RUBY_TOKEN(RSHFT) ">>"
%token <id> tANDDOT RUBY_TOKEN(ANDDOT) "&."
%token <id> tCOLON2 RUBY_TOKEN(COLON2) "::"
+%token <id> tMETHREF RUBY_TOKEN(METHREF) ".:"
%token tCOLON3 ":: at EXPR_BEG"
%token <id> tOP_ASGN /* +=, -= etc. */
%token tASSOC "=>"
@@ -2710,6 +2711,13 @@ primary : literal
/*% %*/
/*% ripper: retry! %*/
}
+ | primary_value tMETHREF operation2
+ {
+ /*%%%*/
+ $$ = NEW_METHREF($1, $3, &@$);
+ /*% %*/
+ /*% ripper: methref!($1, $3) %*/
+ }
;
primary_value : primary
@@ -8060,12 +8068,30 @@ parser_yylex(struct parser_params *p)
case '.':
SET_LEX_STATE(EXPR_BEG);
- if ((c = nextc(p)) == '.') {
+ switch (c = nextc(p)) {
+ case '.':
if ((c = nextc(p)) == '.') {
return tDOT3;
}
pushback(p, c);
return tDOT2;
+ case ':':
+ switch (c = nextc(p)) {
+ default:
+ if (!parser_is_identchar(p)) break;
+ /* fallthru */
+ case '!': case '%': case '&': case '*': case '+':
+ case '-': case '/': case '<': case '=': case '>':
+ case '[': case '^': case '`': case '|': case '~':
+ pushback(p, c);
+ SET_LEX_STATE(EXPR_DOT);
+ return tMETHREF;
+ case -1:
+ break;
+ }
+ pushback(p, c);
+ c = ':';
+ break;
}
pushback(p, c);
if (c != -1 && ISDIGIT(c)) {