percent_i.patch

percent i and percent I - Aaron Patterson, 08/04/2011 09:26 AM

Download (7.2 KB)

View differences:

ext/ripper/eventids2.c
38 38
static ID ripper_id_tstring_end;
39 39
static ID ripper_id_words_beg;
40 40
static ID ripper_id_qwords_beg;
41
static ID ripper_id_qsymbols_beg;
41 42
static ID ripper_id_words_sep;
42 43
static ID ripper_id_regexp_beg;
43 44
static ID ripper_id_regexp_end;
......
91 92
    ripper_id_tstring_end = rb_intern_const("on_tstring_end");
92 93
    ripper_id_words_beg = rb_intern_const("on_words_beg");
93 94
    ripper_id_qwords_beg = rb_intern_const("on_qwords_beg");
95
    ripper_id_qsymbols_beg = rb_intern_const("on_qsymbols_beg");
94 96
    ripper_id_words_sep = rb_intern_const("on_words_sep");
95 97
    ripper_id_regexp_beg = rb_intern_const("on_regexp_beg");
96 98
    ripper_id_regexp_end = rb_intern_const("on_regexp_end");
......
230 232
    {tOROP,		&ripper_id_op},
231 233
    {tPOW,		&ripper_id_op},
232 234
    {tQWORDS_BEG,	&ripper_id_qwords_beg},
235
    {tQSYMBOLS_BEG,	&ripper_id_qsymbols_beg},
233 236
    {tREGEXP_BEG,	&ripper_id_regexp_beg},
234 237
    {tREGEXP_END,	&ripper_id_regexp_end},
235 238
    {tRPAREN,		&ripper_id_rparen},
parse.y
683 683

  
684 684
%type <node> singleton strings string string1 xstring regexp
685 685
%type <node> string_contents xstring_contents regexp_contents string_content
686
%type <node> words qwords word_list qword_list word
686
%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
687 687
%type <node> literal numeric dsym cpath
688 688
%type <node> top_compstmt top_stmts top_stmt
689 689
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
......
734 734
%token tSTAR		/* * */
735 735
%token tAMPER		/* & */
736 736
%token tLAMBDA		/* -> */
737
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
737
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG
738 738
%token tSTRING_DBEG tSTRING_DVAR tSTRING_END tLAMBEG
739 739

  
740 740
/*
......
2619 2619
		| regexp
2620 2620
		| words
2621 2621
		| qwords
2622
		| symbols
2623
		| qsymbols
2622 2624
		| var_ref
2623 2625
		| backref
2624 2626
		| tFID
......
4025 4027
		    }
4026 4028
		;
4027 4029

  
4030
symbols	        : tSYMBOLS_BEG ' ' tSTRING_END
4031
		    {
4032
		    /*%%%*/
4033
			$$ = NEW_ZARRAY();
4034
		    /*%
4035
			$$ = dispatch0(qsymbols_new);
4036
			$$ = dispatch1(array, $$);
4037
		    %*/
4038
		    }
4039
		| tSYMBOLS_BEG symbol_list tSTRING_END
4040
		    {
4041
		    /*%%%*/
4042
			$$ = $2;
4043
		    /*%
4044
			$$ = dispatch1(array, $2);
4045
		    %*/
4046
		    }
4047
		;
4048

  
4049
symbol_list	: /* none */
4050
		    {
4051
		    /*%%%*/
4052
			$$ = 0;
4053
		    /*%
4054
			$$ = dispatch0(words_new);
4055
		    %*/
4056
		    }
4057
		| symbol_list word ' '
4058
		    {
4059
		    /*%%%*/
4060
			$2 = evstr2dstr($2);
4061
			nd_set_type($2, NODE_DSYM);
4062
			$$ = list_append($1, $2);
4063
		    /*%
4064
			$$ = dispatch2(words_add, $1, $2);
4065
		    %*/
4066
		    }
4067
		;
4068

  
4028 4069
qwords		: tQWORDS_BEG ' ' tSTRING_END
4029 4070
		    {
4030 4071
		    /*%%%*/
......
4044 4085
		    }
4045 4086
		;
4046 4087

  
4088
qsymbols	: tQSYMBOLS_BEG ' ' tSTRING_END
4089
		    {
4090
		    /*%%%*/
4091
			$$ = NEW_ZARRAY();
4092
		    /*%
4093
			$$ = dispatch0(qsymbols_new);
4094
			$$ = dispatch1(array, $$);
4095
		    %*/
4096
		    }
4097
		| tQSYMBOLS_BEG qsym_list tSTRING_END
4098
		    {
4099
		    /*%%%*/
4100
			$$ = $2;
4101
		    /*%
4102
			$$ = dispatch1(array, $2);
4103
		    %*/
4104
		    }
4105
		;
4106

  
4047 4107
qword_list	: /* none */
4048 4108
		    {
4049 4109
		    /*%%%*/
......
4062 4122
		    }
4063 4123
		;
4064 4124

  
4125
qsym_list	: /* none */
4126
		    {
4127
		    /*%%%*/
4128
			$$ = 0;
4129
		    /*%
4130
			$$ = dispatch0(qsymbols_new);
4131
		    %*/
4132
		    }
4133
		| qsym_list tSTRING_CONTENT ' '
4134
		    {
4135
		    /*%%%*/
4136
			VALUE lit;
4137
			lit = $2->nd_lit;
4138
			$2->nd_lit = ID2SYM(rb_intern_str(lit));
4139
			nd_set_type($2, NODE_LIT);
4140
			$$ = list_append($1, $2);
4141
		    /*%
4142
			$$ = dispatch2(qsymbols_add, $1, $2);
4143
		    %*/
4144
		    }
4145
		;
4146

  
4065 4147
string_contents : /* none */
4066 4148
		    {
4067 4149
		    /*%%%*/
......
7599 7681
		pushback(c);
7600 7682
		return tQWORDS_BEG;
7601 7683

  
7684
	      case 'I':
7685
		lex_strterm = NEW_STRTERM(str_dword, term, paren);
7686
		do {c = nextc();} while (ISSPACE(c));
7687
		pushback(c);
7688
		return tSYMBOLS_BEG;
7689

  
7690
	      case 'i':
7691
		lex_strterm = NEW_STRTERM(str_sword, term, paren);
7692
		do {c = nextc();} while (ISSPACE(c));
7693
		pushback(c);
7694
		return tQSYMBOLS_BEG;
7695

  
7602 7696
	      case 'x':
7603 7697
		lex_strterm = NEW_STRTERM(str_xquote, term, paren);
7604 7698
		return tXSTRING_BEG;
test/ripper/test_parser_events.rb
749 749
    assert_equal true, thru_qwords_add
750 750
  end
751 751

  
752
  def test_qsymbols_add
753
    thru_qsymbols_add = false
754
    parse('%i[a]', :on_qsymbols_add) {thru_qsymbols_add = true}
755
    assert_equal true, thru_qsymbols_add
756
  end
757

  
758
  def test_symbols_add
759
    thru_symbols_add = false
760
    parse('%I[a]', :on_symbols_add) {thru_symbols_add = true}
761
    assert_equal true, thru_symbols_add
762
  end
763

  
752 764
  def test_qwords_new
753 765
    thru_qwords_new = false
754 766
    parse('%w[]', :on_qwords_new) {thru_qwords_new = true}
755 767
    assert_equal true, thru_qwords_new
756 768
  end
757 769

  
770
  def test_qsymbols_new
771
    thru_qsymbols_new = false
772
    parse('%i[]', :on_qsymbols_new) {thru_qsymbols_new = true}
773
    assert_equal true, thru_qsymbols_new
774
  end
775

  
776
  def test_symbols_new
777
    thru_symbols_new = false
778
    parse('%I[]', :on_symbols_new) {thru_symbols_new = true}
779
    assert_equal true, thru_symbols_new
780
  end
781

  
758 782
  def test_redo
759 783
    thru_redo = false
760 784
    parse('redo', :on_redo) {thru_redo = true}
test/ripper/test_scanner_events.rb
607 607
                 scan('qwords_beg', '%w( w w w )')
608 608
  end
609 609

  
610
  def test_qsymbols_beg
611
    assert_equal [],
612
                 scan('qsymbols_beg', '')
613
    assert_equal ['%i('],
614
                 scan('qsymbols_beg', '%i()')
615
    assert_equal ['%i('],
616
                 scan('qsymbols_beg', '%i(w w w)')
617
    assert_equal ['%i( '],
618
                 scan('qsymbols_beg', '%i( w w w )')
619
  end
620

  
610 621
  # FIXME: Close paren must not present (`words_end' scanner event?).
611 622
  def test_words_sep
612 623
    assert_equal [],
test/ruby/test_array.rb
12 12
    $VERBOSE = @verbose
13 13
  end
14 14

  
15
  def test_percent_i
16
    assert_equal([:foo, :bar], %i[foo bar])
17
    assert_equal([:"\"foo"], %i["foo])
18
  end
19

  
20
  def test_percent_I
21
    x = 10
22
    assert_equal([:foo, :b10], %I[foo b#{x}])
23
    assert_equal([:"\"foo10"], %I["foo#{x}])
24
  end
25

  
15 26
  def test_0_literal
16 27
    assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
17 28
    assert_equal([1, 2, 1, 2], [1, 2] * 2)