Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rubyish slurpy params
  • Loading branch information
dwarring committed Oct 31, 2013
1 parent d7151b3 commit 4f69419
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
12 changes: 10 additions & 2 deletions examples/rubyish/rubyish.nqp
Expand Up @@ -81,7 +81,10 @@ grammar Rubyish::Grammar is HLL::Grammar {
rule comma { [','|'=>'] }

rule signature {
:my $*IN_PARENS := 1; <param>* %% <comma>
:my $*IN_PARENS := 1;
<param>* % <comma>
[ ',' '*' <slurpy=.param> ]?
','?
}

token param { <ident> }
Expand Down Expand Up @@ -357,7 +360,7 @@ class Rubyish::Actions is HLL::Actions {

method TOP($/) {
$*CUR_BLOCK.push($<stmtlist>.ast);
make $*CUR_BLOCK;
make QAST::CompUnit.new( $*CUR_BLOCK );
}

method stmtlist($/) {
Expand Down Expand Up @@ -570,6 +573,11 @@ class Rubyish::Actions is HLL::Actions {
:name(~$_), :scope('lexical'), :decl('param')
));
}

@params.push(QAST::Var.new(
:name(~$<slurpy>), :scope('lexical'), :decl('param'), :slurpy<1>
)) if $<slurpy>;

make @params;
}

Expand Down
12 changes: 11 additions & 1 deletion examples/rubyish/t/arrays.t
@@ -1,4 +1,4 @@
puts "1..10"
puts "1..13"
a=[10,18+2 , 30]
a[3] = 40
puts "#{a[0] == 10? 'ok' : 'nok'} 1 - a[0]"
Expand All @@ -15,3 +15,13 @@ end

puts "#{%w{nok ok nok}[1]} 9 - quote words"
puts "#{['nok',['nok','nok','ok']][1][2]} 10 - 2d array"

def slurpy_arg_tests(x, *arg_arr)
puts "ok #{x} - fixed arg"
for t in arg_arr do
puts "ok #{t} - slurpy arg array"
end
end

slurpy_arg_tests(11, 12, 13)

2 changes: 1 addition & 1 deletion examples/rubyish/t/contextual.t
Expand Up @@ -22,4 +22,4 @@ puts "ok #{three} - parameterless method"
puts "ok #{three + 1} - parameterless method arithmetic"
puts "ok #{three() +2} - parameterless method + paren arithmetic"
puts "ok #{zz 2} - method with methods"
puts "ok #{zz 2} - method with args"
4 changes: 2 additions & 2 deletions examples/rubyish/t/interpolation.t
Expand Up @@ -10,8 +10,8 @@ puts %q<ok> " #{tst}" ' - adjacent' ' strings'
puts %Q{ok #{a*=3} - expression - side affect}
puts %Q{ok #{(a+=2)-1} - expression - side affect}
puts "#{if a==8 then 'ok' else 'nok' end} #{a} - nested statement"
puts "ok 9 # todo nested starters / stoppers"
##puts "#{'#{tst}' == '#{' 'tst}'? 'ok' : 'nok'} 9 - nested starters / stoppers"
puts "ok 9 # skip nested starters / stoppers"
##puts "#{'#{tst}' eq '#' '{' 'tst}'? 'ok' : 'nok'} 9 - nested starters / stoppers"
puts "ok #{
x = 4; x+= 1
x+5
Expand Down
2 changes: 1 addition & 1 deletion examples/rubyish/t/line-spanning.t
Expand Up @@ -31,7 +31,7 @@ tricky(

5,

"multiline call"
"multi-line call"

)

Expand Down

0 comments on commit 4f69419

Please sign in to comment.