diff --git a/src/NQP/Actions.pm b/src/NQP/Actions.pm index 3aeb573..508327e 100644 --- a/src/NQP/Actions.pm +++ b/src/NQP/Actions.pm @@ -142,6 +142,24 @@ method variable($/) { } method package_declarator:sym($/) { make $.ast; } +method package_declarator:sym($/) { + my $classinit := + PAST::Op.new( + PAST::Op.new( + :inline( ' %r = get_root_global ["parrot"], "P6metaclass"') + ), + ~$, + :name('new_class'), + :pasttype('callmethod') + ); + if $ { + $classinit.push( PAST::Val.new( + :value( ~$[0] ), + :named('parent') ) ); + } + @BLOCK[0].loadinit.push($classinit); + make $.ast; +} method package_def($/) { my $past := $ ?? $.ast !! $.ast; @@ -187,6 +205,14 @@ method variable_declarator($/) { } method routine_declarator:sym($/) { make $.ast; } +method routine_declarator:sym($/) { + my $past := $.ast; + if $past.isa(PAST::Var) { $past := $past.viviself(); } + $past.blocktype('method'); + $past[0].unshift( PAST::Op.new( :inline(' .lex "self", self') ) ); + $past.symbol('self', :scope('lexical') ); + make $past; +} method routine_def($/) { my $past := $.ast; @@ -195,7 +221,6 @@ method routine_def($/) { if $ { my $name := ~$[0]; $past.name($name); - $past.nsentry(''); $past := PAST::Var.new( :name($name), :isdecl(1), :viviself($past), :scope('lexical') ); $past := 1; @@ -254,6 +279,13 @@ method named_param($/) { make $past; } +method dotty($/) { + my $past := $ ?? $[0].ast !! PAST::Op.new( :node($/) ); + $past.name( ~$ ); + $past.pasttype('callmethod'); + make $past; +} + method term:sym($/) { my $past := $.ast; $past.name(~$); @@ -360,6 +392,8 @@ method nulltermish($/) { make $ ?? $.ast !! 0; } +method postfix:sym<.>($/) { make $.ast; } + method postfix:sym<++>($/) { make PAST::Op.new( :name('postfix:<++>'), :inline(' clone %r, %0', ' inc %0'), diff --git a/src/NQP/Grammar.pm b/src/NQP/Grammar.pm index 088d595..e7f7ec1 100644 --- a/src/NQP/Grammar.pm +++ b/src/NQP/Grammar.pm @@ -130,6 +130,7 @@ token twigil { <[*]> } proto token package_declarator { <...> } token package_declarator:sym { } +token package_declarator:sym { } rule package_def { @@ -153,7 +154,8 @@ rule scoped { token variable_declarator { } proto token routine_declarator { <...> } -token routine_declarator:sym { } +token routine_declarator:sym { } +token routine_declarator:sym { } rule routine_def { ? @@ -184,6 +186,15 @@ token named_param { rule default_value { '=' } +token dotty { + '.' + [ + | + | ':' \s + ]? +} + + proto token term { <...> } token term:sym { @@ -201,7 +212,7 @@ token args { token arglist { <.ws> [ - | + | | ] } @@ -248,6 +259,8 @@ token postcircumfix:sym { } +token postfix:sym<.> { } + token prefix:sym<++> { ')> } token prefix:sym<--> { ')> } token postfix:sym<++> { } # see Actions.pm diff --git a/t/nqp/25-class.t b/t/nqp/25-class.t new file mode 100644 index 0000000..0512a7d --- /dev/null +++ b/t/nqp/25-class.t @@ -0,0 +1,15 @@ +#!./parrot nqp.pbc + +# class + +plan(1); + +class XYZ { + method foo($x) { + say($x); + } +} + +my $xyz := XYZ.new(); + +$xyz.foo('ok 1');