Permalink
Browse files

perlito5 - parser - fix "sub _" should be in package "main"

  • Loading branch information...
1 parent 09cc8db commit caf3b30085167b9e315f380989d0bec7f1d730cd @fglock committed Nov 9, 2012
Showing with 30 additions and 29 deletions.
  1. +19 −17 TODO-perlito5
  2. +3 −6 html/perlito5.js
  3. +2 −5 perlito5.pl
  4. +6 −1 src5/lib/Perlito5/Grammar/Block.pm
View
@@ -32,15 +32,6 @@ TODO list for Perlito5
* Parser
--- defined-or vs. m// (2012/9/25 Конрад Боровски <notifications@github.com>)
- Note: fixed; see test t5/01-perlito/25-syntax-defined-or.t
-
- $ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift // 2 '
- Number or Bareword found where operator expected
-
- $ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift / 2 '
- Can't find string terminator '/' anywhere before EOF
-
-- quotes vs. hash lookups:
$ perl -e ' q}} '
@@ -56,13 +47,6 @@ TODO list for Perlito5
-- create __DATA__
--- "sub _" should be in package "main"
- $ perl -MO=Deparse -e ' package X; sub _ { 123 } '
- package X;
- sub main::_ {
- 123;
- }
-
-- "given" statement not implemented
-- "default" statement not implemented
@@ -127,7 +111,25 @@ TODO list for Perlito5
-- add tests for fixed bugs:
- filetest operators special case:
+ add test for "sub _" should be in package "main"
+ $ perl -MO=Deparse -e ' package X; sub _ { 123 } '
+ package X;
+ sub main::_ {
+ 123;
+ }
+
+ ---
+ add test for defined-or vs. m// (2012/9/25 Конрад Боровски <notifications@github.com>)
+ Note: fixed; see test t5/01-perlito/25-syntax-defined-or.t
+
+ $ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift // 2 '
+ Number or Bareword found where operator expected
+
+ $ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift / 2 '
+ Can't find string terminator '/' anywhere before EOF
+
+ ---
+ add test for filetest operators special case:
' -f($file).".bak" ' should be equivalent to -f "$file.bak"
parses as -(f($file)).".bak"
but: ' -f ($file).".bak" '
View
@@ -111,7 +111,7 @@ function p5get_class_for_method(method, class_name, seen) {
var isa = p5pkg[class_name].List_ISA;
for (var i = 0; i < isa.length; i++) {
if (!seen[isa[i]]) {
- var m = p5get_class_for_method(method, isa[i]);
+ var m = p5get_class_for_method(method, isa[i], seen);
if (m) {
return m
}
@@ -10491,11 +10491,8 @@ return r;
(v_namespace = (p5pkg["Perlito5::Match"].flat(p5list_to_a((v_MATCH || (v_MATCH = new p5HashRef({})))._hash_.p5hget('Perlito5::Grammar.optional_namespace_before_ident')), 0)));
if ( p5bool(v_name) ) {
(function () {
- if ( p5bool(v_namespace) ) {
- null;
- }
- else {
- (v_namespace = (p5pkg["Perlito5"]["v_PKG_NAME"]));
+ if ( !( p5bool(v_namespace)) ) {
+ (v_namespace = (( (p5str(v_name) == '_') ? 'main' : p5pkg["Perlito5"]["v_PKG_NAME"])));
};
var v_full_name;
(v_full_name = ((p5str(v_namespace) + '::' + p5str(v_name))));
View
@@ -5721,11 +5721,8 @@ sub Perlito5::Grammar::Block::named_sub_def {
};
((my $namespace) = Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'}));
if ($name) {
- if ($namespace) {
-
- }
- else {
- ($namespace = $Perlito5::PKG_NAME)
+ if (!($namespace)) {
+ ($namespace = (($name eq '_') ? 'main' : $Perlito5::PKG_NAME))
};
((my $full_name) = ($namespace . '::' . $name));
if (exists($Perlito5::PROTO->{$full_name})) {
@@ -107,7 +107,12 @@ token named_sub_def {
my $namespace = Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.optional_namespace_before_ident"});
if ( $name ) {
# say "sub $Perlito5::PKG_NAME :: $name ( $sig )";
- $namespace = $Perlito5::PKG_NAME unless $namespace;
+ if (!$namespace) {
+ # perl -MO=Deparse -e ' package X; sub _ { 123 } ' # sub main::_
+ $namespace = $name eq '_'
+ ? 'main'
+ : $Perlito5::PKG_NAME;
+ }
my $full_name = "${namespace}::$name";
warn "Subroutine $full_name redefined"

0 comments on commit caf3b30

Please sign in to comment.