From: nobu.nakada@... Date: 2002-10-21T21:56:20+09:00 Subject: [ruby-dev:18547] Re: symbol literal with non-alphanumeric なかだです。 At Mon, 21 Oct 2002 14:14:46 +0900, Yukihiro Matsumoto wrote: > しばらく頭を冷やしたら以下の点を明確にする必要がある気がして > きました。 > > * :".."形式で式展開を許すか(許したほうが一貫性がある?) やっぱり使えたほうがいいでしょうか。NODEを追加したほうがいいの かも知れませんが、とりあえず[ruby-dev:18537]への追加です。 > * 現在internする文字列は\0を含むことができないことをどうす > るか うーん、これはそのままエラーでいいような気がするんですが。 --- parse.y~ Fri Oct 18 23:14:17 2002 +++ parse.y Mon Oct 21 21:41:34 2002 @@ -239,5 +239,5 @@ static void top_local_setup(); %type string_contents xstring_contents string_content %type words qwords word_list qword_list word -%type literal numeric +%type literal numeric dsym %type bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type expr_value arg_value primary_value @@ -1741,4 +1741,5 @@ literal : numeric $$ = NEW_LIT(ID2SYM($1)); } + | dsym ; @@ -1956,12 +1957,19 @@ sym : fname | tGVAR | tCVAR - | tSTRING_CONTENT tSTRING_END - { - $$ = rb_intern(RSTRING($1->nd_lit)->ptr); - rb_gc_force_recycle((VALUE)$1); - } - | tSTRING_END + ; + +dsym : tSYMBEG xstring_contents tSTRING_END { - yyerror("empty symbol literal"); + lex_state = EXPR_END; + if (!$2) { + yyerror("empty symbol literal"); + } + else if (nd_type($2) == NODE_STR) { + $2->nd_lit = ID2SYM(rb_intern(RSTRING($2->nd_lit)->ptr)); + $$ = $2; + } + else { + $$ = NEW_CALL($2, rb_intern("intern"), 0); + } } ; -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦