summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-24 18:10:35 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-24 18:10:35 +0000
commit91bd6e711db3418baa287e936d4b0fac99927711 (patch)
tree4a605159d1d3f8327ee5775ede377c35d2867723 /parse.y
parent1a5773a8682e685c87652f02df167f697f9413f9 (diff)
* parse.y: added symbols and qsymbols productions for %i and %I
support. %i{ .. } returns a list of symbols without interpolation, %I{ .. } returns a list of symbols with interpolation. Thanks to Josh Susser for inspiration of this feature. [Feature #4985] * ext/ripper/eventids2.c: added ripper events for %i and %I. * test/ripper/test_parser_events.rb: ripper tests * test/ripper/test_scanner_events.rb: ditto * test/ruby/test_array.rb: test for %i and %I behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y98
1 files changed, 96 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index 049e356276..cc0bae59b8 100644
--- a/parse.y
+++ b/parse.y
@@ -715,7 +715,7 @@ static void token_info_pop(struct parser_params*, const char *token);
%type <node> singleton strings string string1 xstring regexp
%type <node> string_contents xstring_contents regexp_contents string_content
-%type <node> words qwords word_list qword_list word
+%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
%type <node> literal numeric dsym cpath
%type <node> top_compstmt top_stmts top_stmt
%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
@@ -769,7 +769,7 @@ static void token_info_pop(struct parser_params*, const char *token);
%token tDSTAR /* ** */
%token tAMPER /* & */
%token tLAMBDA /* -> */
-%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
+%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG
%token tSTRING_DBEG tSTRING_DEND tSTRING_DVAR tSTRING_END tLAMBEG
/*
@@ -2672,6 +2672,8 @@ primary : literal
| regexp
| words
| qwords
+ | symbols
+ | qsymbols
| var_ref
| backref
| tFID
@@ -4105,6 +4107,45 @@ word : string_content
}
;
+symbols : tSYMBOLS_BEG ' ' tSTRING_END
+ {
+ /*%%%*/
+ $$ = NEW_ZARRAY();
+ /*%
+ $$ = dispatch0(symbols_new);
+ $$ = dispatch1(array, $$);
+ %*/
+ }
+ | tSYMBOLS_BEG symbol_list tSTRING_END
+ {
+ /*%%%*/
+ $$ = $2;
+ /*%
+ $$ = dispatch1(array, $2);
+ %*/
+ }
+ ;
+
+symbol_list : /* none */
+ {
+ /*%%%*/
+ $$ = 0;
+ /*%
+ $$ = dispatch0(symbols_new);
+ %*/
+ }
+ | symbol_list word ' '
+ {
+ /*%%%*/
+ $2 = evstr2dstr($2);
+ nd_set_type($2, NODE_DSYM);
+ $$ = list_append($1, $2);
+ /*%
+ $$ = dispatch2(symbols_add, $1, $2);
+ %*/
+ }
+ ;
+
qwords : tQWORDS_BEG ' ' tSTRING_END
{
/*%%%*/
@@ -4124,6 +4165,25 @@ qwords : tQWORDS_BEG ' ' tSTRING_END
}
;
+qsymbols : tQSYMBOLS_BEG ' ' tSTRING_END
+ {
+ /*%%%*/
+ $$ = NEW_ZARRAY();
+ /*%
+ $$ = dispatch0(qsymbols_new);
+ $$ = dispatch1(array, $$);
+ %*/
+ }
+ | tQSYMBOLS_BEG qsym_list tSTRING_END
+ {
+ /*%%%*/
+ $$ = $2;
+ /*%
+ $$ = dispatch1(array, $2);
+ %*/
+ }
+ ;
+
qword_list : /* none */
{
/*%%%*/
@@ -4142,6 +4202,28 @@ qword_list : /* none */
}
;
+qsym_list : /* none */
+ {
+ /*%%%*/
+ $$ = 0;
+ /*%
+ $$ = dispatch0(qsymbols_new);
+ %*/
+ }
+ | qsym_list tSTRING_CONTENT ' '
+ {
+ /*%%%*/
+ VALUE lit;
+ lit = $2->nd_lit;
+ $2->nd_lit = ID2SYM(rb_intern_str(lit));
+ nd_set_type($2, NODE_LIT);
+ $$ = list_append($1, $2);
+ /*%
+ $$ = dispatch2(qsymbols_add, $1, $2);
+ %*/
+ }
+ ;
+
string_contents : /* none */
{
/*%%%*/
@@ -7796,6 +7878,18 @@ parser_yylex(struct parser_params *parser)
pushback(c);
return tQWORDS_BEG;
+ case 'I':
+ lex_strterm = NEW_STRTERM(str_dword, term, paren);
+ do {c = nextc();} while (ISSPACE(c));
+ pushback(c);
+ return tSYMBOLS_BEG;
+
+ case 'i':
+ lex_strterm = NEW_STRTERM(str_sword, term, paren);
+ do {c = nextc();} while (ISSPACE(c));
+ pushback(c);
+ return tQSYMBOLS_BEG;
+
case 'x':
lex_strterm = NEW_STRTERM(str_xquote, term, paren);
return tXSTRING_BEG;