qsymbols.patch

symbol patch - Aaron Patterson, 07/07/2011 01:00 PM

Download (5.82 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
681 681

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

  
738 738
/*
......
2604 2604
		| regexp
2605 2605
		| words
2606 2606
		| qwords
2607
		| qsymbols
2607 2608
		| var_ref
2608 2609
		| backref
2609 2610
		| tFID
......
4029 4030
		    }
4030 4031
		;
4031 4032

  
4033
qsymbols	: tQSYMBOLS_BEG ' ' tSTRING_END
4034
		    {
4035
		    /*%%%*/
4036
			$$ = NEW_ZARRAY();
4037
		    /*%
4038
			$$ = dispatch0(qsymbols_new);
4039
			$$ = dispatch1(array, $$);
4040
		    %*/
4041
		    }
4042
		| tQSYMBOLS_BEG sym_list tSTRING_END
4043
		    {
4044
		    /*%%%*/
4045
			$$ = $2;
4046
		    /*%
4047
			$$ = dispatch1(array, $2);
4048
		    %*/
4049
		    }
4050
		;
4051

  
4032 4052
qword_list	: /* none */
4033 4053
		    {
4034 4054
		    /*%%%*/
......
4047 4067
		    }
4048 4068
		;
4049 4069

  
4070
sym_list	: /* none */
4071
		    {
4072
		    /*%%%*/
4073
			$$ = 0;
4074
		    /*%
4075
			$$ = dispatch0(qsymbols_new);
4076
		    %*/
4077
		    }
4078
		| sym_list tSTRING_CONTENT ' '
4079
		    {
4080
		    /*%%%*/
4081
			VALUE lit;
4082
                        lit = $2->nd_lit;
4083
                        $2->nd_lit = ID2SYM(rb_intern_str(lit));
4084
                        nd_set_type($2, NODE_LIT);
4085
			$$ = list_append($1, $2);
4086
		    /*%
4087
			$$ = dispatch2(qsymbols_add, $1, $2);
4088
		    %*/
4089
		    }
4090
		;
4091

  
4050 4092
string_contents : /* none */
4051 4093
		    {
4052 4094
		    /*%%%*/
......
7561 7603
		pushback(c);
7562 7604
		return tQWORDS_BEG;
7563 7605

  
7606
	      case 'S':
7607
		lex_strterm = NEW_STRTERM(str_sword, term, paren);
7608
		do {c = nextc();} while (ISSPACE(c));
7609
		pushback(c);
7610
		return tQSYMBOLS_BEG;
7611

  
7564 7612
	      case 'x':
7565 7613
		lex_strterm = NEW_STRTERM(str_xquote, term, paren);
7566 7614
		return tXSTRING_BEG;
test/ripper/test_parser_events.rb
745 745
    assert_equal true, thru_qwords_add
746 746
  end
747 747

  
748
  def test_qsymbols_add
749
    thru_qsymbols_add = false
750
    parse('%S[a]', :on_qsymbols_add) {thru_qsymbols_add = true}
751
    assert_equal true, thru_qsymbols_add
752
  end
753

  
748 754
  def test_qwords_new
749 755
    thru_qwords_new = false
750 756
    parse('%w[]', :on_qwords_new) {thru_qwords_new = true}
751 757
    assert_equal true, thru_qwords_new
752 758
  end
753 759

  
760
  def test_qsymbols_new
761
    thru_qsymbols_new = false
762
    parse('%S[]', :on_qsymbols_new) {thru_qsymbols_new = true}
763
    assert_equal true, thru_qsymbols_new
764
  end
765

  
754 766
  def test_redo
755 767
    thru_redo = false
756 768
    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 ['%S('],
614
                 scan('qsymbols_beg', '%S()')
615
    assert_equal ['%S('],
616
                 scan('qsymbols_beg', '%S(w w w)')
617
    assert_equal ['%S( '],
618
                 scan('qsymbols_beg', '%S( 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_S
16
    assert_equal([:foo, :bar], %S[foo bar])
17
    assert_equal([:"\"foo"], %S["foo])
18
  end
19

  
15 20
  def test_0_literal
16 21
    assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
17 22
    assert_equal([1, 2, 1, 2], [1, 2] * 2)