diff --git a/lib/Yapsi.pm b/lib/Yapsi.pm index 0126328..2d4dd99 100644 --- a/lib/Yapsi.pm +++ b/lib/Yapsi.pm @@ -44,7 +44,8 @@ grammar Yapsi::Perl6::Grammar { token expression { || || || || || || - || || || } + || || || || + } token lvalue { || || } token value { || || || || } @@ -59,6 +60,7 @@ grammar Yapsi::Perl6::Grammar { rule assignment { '=' } rule binding { ':=' } rule saycall { 'say' } # very temporary solution + rule subcall { $=[\w+]'()'? } rule increment { '++' } rule decrement { '--' } rule invocation { [||]'()' } @@ -240,8 +242,8 @@ class Yapsi::Perl6::Actions { } method expression($/) { - hoist $/, ; + hoist $/, ; } method lvalue($/) { @@ -305,6 +307,11 @@ class Yapsi::Perl6::Actions { make FUTURE::Call.new(:name('&say'), :children($.ast)); } + method subcall($/) { + make FUTURE::Call.new(:name('&' ~ $), + :children()); + } + method increment($/) { make FUTURE::Call.new(:name('&prefix:<++>'), :children($.ast)); } @@ -400,7 +407,9 @@ class Yapsi::Compiler { } multi process(FUTURE::Call $call) { - process $call.children[0]; # a FUTURE::Expression + if $call.children.elems { + process $call.children[0]; # a FUTURE::Expression + } given $call.name { when '&say' { @@ -425,7 +434,10 @@ class Yapsi::Compiler { push @blocksic, "call $register"; } default { - die "Don't know how to handle $call.name()"; + # This is slightly cannibalistic, but still better than + # code duplication + process FUTURE::Var.new(:name($call.name)); + push @blocksic, "call $register"; } } } @@ -560,7 +572,7 @@ class Yapsi::Compiler { } multi process(Any $node) { - die "No multi defined for {$node.WHAT.perl}, sorry :/"; + die "No multi 'process' defined for {$node.WHAT.perl}, sorry :/"; } sub declutter(@instructions) { diff --git a/t/compiler.t b/t/compiler.t index df46e48..eb25aee 100644 --- a/t/compiler.t +++ b/t/compiler.t @@ -41,6 +41,8 @@ my @programs-that-compile = 'sub foo {}', 'my sub foo {}', 'our sub foo {}', + 'sub foo {}; foo', + 'sub foo {}; foo()', ; sub escape($string) { $string.subst("\n", "\\n", :g) } @@ -75,6 +77,7 @@ my @programs-that-don't-compile = # ' 'unless a {}' => 'could not parse', 'my $a = 1; { say $a; my $a = 2 }' => 'reference to outer variable', 'sub foo' => 'could not parse', + 'foo' => 'undefined subroutine', ; for @programs-that-don't-compile -> $pair { # '