Feature #4985 » qsymbols.patch
| ext/ripper/eventids2.c | ||
|---|---|---|
|
static ID ripper_id_tstring_end;
|
||
|
static ID ripper_id_words_beg;
|
||
|
static ID ripper_id_qwords_beg;
|
||
|
static ID ripper_id_qsymbols_beg;
|
||
|
static ID ripper_id_words_sep;
|
||
|
static ID ripper_id_regexp_beg;
|
||
|
static ID ripper_id_regexp_end;
|
||
| ... | ... | |
|
ripper_id_tstring_end = rb_intern_const("on_tstring_end");
|
||
|
ripper_id_words_beg = rb_intern_const("on_words_beg");
|
||
|
ripper_id_qwords_beg = rb_intern_const("on_qwords_beg");
|
||
|
ripper_id_qsymbols_beg = rb_intern_const("on_qsymbols_beg");
|
||
|
ripper_id_words_sep = rb_intern_const("on_words_sep");
|
||
|
ripper_id_regexp_beg = rb_intern_const("on_regexp_beg");
|
||
|
ripper_id_regexp_end = rb_intern_const("on_regexp_end");
|
||
| ... | ... | |
|
{tOROP, &ripper_id_op},
|
||
|
{tPOW, &ripper_id_op},
|
||
|
{tQWORDS_BEG, &ripper_id_qwords_beg},
|
||
|
{tQSYMBOLS_BEG, &ripper_id_qsymbols_beg},
|
||
|
{tREGEXP_BEG, &ripper_id_regexp_beg},
|
||
|
{tREGEXP_END, &ripper_id_regexp_end},
|
||
|
{tRPAREN, &ripper_id_rparen},
|
||
| parse.y | ||
|---|---|---|
|
%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 qwords qsymbols word_list qword_list sym_list word
|
||
|
%type <node> literal numeric dsym cpath
|
||
|
%type <node> top_compstmt top_stmts top_stmt
|
||
|
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
||
| ... | ... | |
|
%token tSTAR /* * */
|
||
|
%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 tQSYMBOLS_BEG
|
||
|
%token tSTRING_DBEG tSTRING_DVAR tSTRING_END tLAMBEG
|
||
|
/*
|
||
| ... | ... | |
|
| regexp
|
||
|
| words
|
||
|
| qwords
|
||
|
| qsymbols
|
||
|
| var_ref
|
||
|
| backref
|
||
|
| tFID
|
||
| ... | ... | |
|
}
|
||
|
;
|
||
|
qsymbols : tQSYMBOLS_BEG ' ' tSTRING_END
|
||
|
{
|
||
|
/*%%%*/
|
||
|
$$ = NEW_ZARRAY();
|
||
|
/*%
|
||
|
$$ = dispatch0(qsymbols_new);
|
||
|
$$ = dispatch1(array, $$);
|
||
|
%*/
|
||
|
}
|
||
|
| tQSYMBOLS_BEG sym_list tSTRING_END
|
||
|
{
|
||
|
/*%%%*/
|
||
|
$$ = $2;
|
||
|
/*%
|
||
|
$$ = dispatch1(array, $2);
|
||
|
%*/
|
||
|
}
|
||
|
;
|
||
|
qword_list : /* none */
|
||
|
{
|
||
|
/*%%%*/
|
||
| ... | ... | |
|
}
|
||
|
;
|
||
|
sym_list : /* none */
|
||
|
{
|
||
|
/*%%%*/
|
||
|
$$ = 0;
|
||
|
/*%
|
||
|
$$ = dispatch0(qsymbols_new);
|
||
|
%*/
|
||
|
}
|
||
|
| sym_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 */
|
||
|
{
|
||
|
/*%%%*/
|
||
| ... | ... | |
|
pushback(c);
|
||
|
return tQWORDS_BEG;
|
||
|
case 'S':
|
||
|
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;
|
||
| test/ripper/test_parser_events.rb | ||
|---|---|---|
|
assert_equal true, thru_qwords_add
|
||
|
end
|
||
|
def test_qsymbols_add
|
||
|
thru_qsymbols_add = false
|
||
|
parse('%S[a]', :on_qsymbols_add) {thru_qsymbols_add = true}
|
||
|
assert_equal true, thru_qsymbols_add
|
||
|
end
|
||
|
def test_qwords_new
|
||
|
thru_qwords_new = false
|
||
|
parse('%w[]', :on_qwords_new) {thru_qwords_new = true}
|
||
|
assert_equal true, thru_qwords_new
|
||
|
end
|
||
|
def test_qsymbols_new
|
||
|
thru_qsymbols_new = false
|
||
|
parse('%S[]', :on_qsymbols_new) {thru_qsymbols_new = true}
|
||
|
assert_equal true, thru_qsymbols_new
|
||
|
end
|
||
|
def test_redo
|
||
|
thru_redo = false
|
||
|
parse('redo', :on_redo) {thru_redo = true}
|
||
| test/ripper/test_scanner_events.rb | ||
|---|---|---|
|
scan('qwords_beg', '%w( w w w )')
|
||
|
end
|
||
|
def test_qsymbols_beg
|
||
|
assert_equal [],
|
||
|
scan('qsymbols_beg', '')
|
||
|
assert_equal ['%S('],
|
||
|
scan('qsymbols_beg', '%S()')
|
||
|
assert_equal ['%S('],
|
||
|
scan('qsymbols_beg', '%S(w w w)')
|
||
|
assert_equal ['%S( '],
|
||
|
scan('qsymbols_beg', '%S( w w w )')
|
||
|
end
|
||
|
# FIXME: Close paren must not present (`words_end' scanner event?).
|
||
|
def test_words_sep
|
||
|
assert_equal [],
|
||
| test/ruby/test_array.rb | ||
|---|---|---|
|
$VERBOSE = @verbose
|
||
|
end
|
||
|
def test_percent_S
|
||
|
assert_equal([:foo, :bar], %S[foo bar])
|
||
|
assert_equal([:"\"foo"], %S["foo])
|
||
|
end
|
||
|
def test_0_literal
|
||
|
assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
|
||
|
assert_equal([1, 2, 1, 2], [1, 2] * 2)
|
||