Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Str ~~ Grammar do not return Match object, but return strange hash #404

Closed
p6rt opened this issue Nov 10, 2008 · 10 comments
Closed

Str ~~ Grammar do not return Match object, but return strange hash #404

p6rt opened this issue Nov 10, 2008 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Nov 10, 2008

Migrated from rt.perl.org#60456 (status was 'resolved')

Searchable as RT60456$

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @ilyabelikin

grammar G {
  token TOP { '​:' <foo>+ };
  token foo { \d };
}

my $a = "​:123" ~~ G​::TOP;
say +$/; # 0 But match success. :(
say +$a; # 1

say $/.WHAT; # Match
say $a.WHAT; # Hash (!?)

# Hash, hmmm. I expect Match object.

say $/.perl; # {"foo" => [{}, {}, {}]}
say $a.perl; # {"foo" => [{}, {}, {}]}

# Strange hash

say $/<foo>.WHAT; # List
say $a<foo>.WHAT; # List

@p6rt
Copy link
Author

p6rt commented Nov 11, 2008

From @chrisdolan

I'm seeing this too. It happened in the last 3-5 days, I think, about
the same time as the ObjectRef overhaul. I thought it was a mistake I
introduced in my own code, so I did not report it...

@p6rt
Copy link
Author

p6rt commented Nov 11, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 11, 2008

From @pmichaud

On Mon, Nov 10, 2008 at 03​:21​:47AM -0800, Ilya Belikin wrote​:

grammar G {
token TOP { '​:' <foo>+ };
token foo { \d };
}

my $a = "​:123" ~~ G​::TOP;

The official syntax for matching against a rule or grammar
has not yet been determined. So, I'm marking this ticket
as "stalled" until we have that.

In the meantime, I suggest​:

  my $a = G​::TOP("​:123");

Pm

@p6rt
Copy link
Author

p6rt commented Nov 11, 2008

@pmichaud - Status changed from 'open' to 'stalled'

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

From @chrisdolan

I think I'm getting closer to the root cause of this regression -- the
smart match is not part of the problem. Instead there appears to be
something wrong in the recent ObjectRef overhaul. Consider this​:

  ./perl6 -e 'grammar Foo {token TOP {'foo'};}; say Foo​::TOP("foo").WHAT'
  Match

  ./perl6 -e 'grammar Foo {token TOP {'foo'};}; my $m=Foo​::TOP("foo");
say $m.WHAT'
  Hash

even more revealing​:

  ./perl6 -e 'say PGE​::Match.new("foo").WHAT'
  Match

  ./perl6 -e 'my $m = PGE​::Match.new("foo"); say $m.WHAT'
  Hash

Any guesses whether this is a bug in assignment or in PGE​::Match? I'm
guessing the latter, so I'll start looking there.

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

The RT System itself - Status changed from 'stalled' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

From @chrisdolan

More news​: using 'infix​::=' works around the regression.

  ./perl6 -e 'my $m := PGE​::Match.new("foo"); say $m.WHAT'
  Match

  ./perl6 -e 'my $m = PGE​::Match.new("foo"); say $m.WHAT'
  Hash

I now suspect the flaw is in assign.pir. I stuck a ton of debugging
"say" lines in there. The following code is in the 'infix​:=' method​:

  $I0 = can source, 'Scalar'
  unless $I0 goto have_source
  source = source.'Scalar'()

The $m is an ObjectRef and it does has a 'Scalar' method. After the
source.'Scalar'() invocation, the resulting source returns true to "isa
source, 'Perl6Hash'".

If I comment out the "source = source.'Scalar'()" line, then the code works

  ./perl6 -e 'my $m = PGE​::Match.new("foo"); say $m.WHAT'
  Match

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

From @pmichaud

This issue should now be fixed in r32597 so that PGE​::Match objects
correctly return an ObjectRef and assigns properly into scalar types.

Also, in order to help diagnose such issues in the future, I've added a
.PARROT method to rakudo that can be used to better diagnose what is
happening internally when difficulties arise. This should be a more
reliable indicator than trying to use .WHAT, which often hides such
differences. For example

  $ ./parrot perl6.pbc
  > my $a = 'foo' ~~ /./; say $a.WHAT; say $a.PARROT;
  Match
  ObjectRef->PGE;Match
  > my $a = 'foo' ~~ /./; say ($a).WHAT; say ($a).PARROT;
  Str
  String

Here we can see that even though .WHAT returns the expected Perl 6
protoobject, .PARROT shows us what is really happening beneath the surface.

I expect that most of the remaining discrepancies will resolve
themselves when we get HLL mapping in place.

Resolving ticket, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 13, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant