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

Mu methods cannot be used as grammar tokens due to default Actions class #5247

Closed
p6rt opened this issue Apr 21, 2016 · 12 comments
Closed

Mu methods cannot be used as grammar tokens due to default Actions class #5247

p6rt opened this issue Apr 21, 2016 · 12 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 21, 2016

Migrated from rt.perl.org#127945 (status was 'open')

Searchable as RT127945$

@p6rt
Copy link
Author

p6rt commented Apr 21, 2016

From @masak

<ugexe> m​: grammar Foo { token TOP { <return> }; token return { .+ };
}; Foo.parse(1); # bug? or dihwidt?
<camelia> rakudo-moar 6df7ff​: OUTPUT«Attempt to return outside of any
Routine� in any !cursor_pass [...]
<masak> ugexe​: surprising, at least. a token is a kind of method, so
why would that clash at all with `return` as a sub?
<masak> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1")
<camelia> rakudo-moar 6df7ff​: OUTPUT«Attempt to return outside of any
Routine� [...]
<masak> ugexe​: I think the problem isn't the declaration of `token
return`, but the call `<return>`, which looks both for subs and
methods... perhaps?
<masak> and since there is a lexical sub &return, it finds it
<jnthn> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1",
actions => class { method return($/) { } })
<camelia> rakudo-moar 6df7ff​: OUTPUT«Attempt to return outside of any
Routine [...]
<jnthn> masak​: But it's only meant to find things of type Regex, I thought...
* jnthn had suspected it was calling .return
<jnthn> As an action method
<jnthn> But apparently not, O did the action method wrong
* masak submits rakudobug

In summary, it seems to be calling &return, but it shouldn't do that.

@p6rt
Copy link
Author

p6rt commented Jul 10, 2016

From @zoffixznet

Still present in rakudo 405519, except now one of the errors mentions "any !reduce"

<Zoffix> m​: grammar Foo { token TOP { <return> }; token return { .+ }; }; Foo.parse(1);
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any Routineâ�¤ in any !reduce at /home/camelia/rakudo-m-inst-1/share/nqp/lib/QRegex.moarvm line 1â�¤ in any !cursor_pass at /home/camelia/rakudo-m-inst-1/share/nqp/lib/QRegex.moarvm line 1â�¤ in regex return at <tmp> line 1â�¦Â»
<Zoffix> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1", actions => class { method return($/) { } })
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any Routineâ�¤ in regex TOP at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»
<Zoffix> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1")
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any Routineâ�¤ in regex TOP at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

@p6rt
Copy link
Author

p6rt commented Jul 20, 2016

From @zoffixznet

�����������������������������������������������������������������������������
������������������������������������������

TODO-fudged tests added in Raku/roast@f4e2505dbc

������������������������������������������
�����������������������������������������������������������������������������

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Jul 20, 2016

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

@p6rt
Copy link
Author

p6rt commented Jul 21, 2016

From @jnthn

On Sat Jul 09 19​:02​:23 2016, cpan@​zoffix.com wrote​:

Still present in rakudo 405519, except now one of the errors mentions
"any !reduce"

<Zoffix> m​: grammar Foo { token TOP { <return> }; token return { .+ };
}; Foo.parse(1);
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any
Routine� in any !reduce at /home/camelia/rakudo-m-inst-
1/share/nqp/lib/QRegex.moarvm line 1� in any !cursor_pass at
/home/camelia/rakudo-m-inst-1/share/nqp/lib/QRegex.moarvm line 1� in
regex return at <tmp> line 1�»
<Zoffix> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1",
actions => class { method return($/) { } })
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any
Routine� in regex TOP at <tmp> line 1� in block <unit> at <tmp> line
1��»
<Zoffix> m​: grammar Foo { token TOP { <return> } }; Foo.parse("1")
<camelia> rakudo-moar 405519​: OUTPUT«Attempt to return outside of any
Routine� in regex TOP at <tmp> line 1� in block <unit> at <tmp> line
1��»

Ah, fun one. The problem is actually that after the return regex matches, it looks for actions. $*ACTIONS is likely set to Mu or Any if you don't supply an actions class. And Mu has a method return, which gets invoked.

@p6rt
Copy link
Author

p6rt commented Jan 23, 2017

From @AlexDaniel

Code​:
grammar A { token TOP { <so> }; token so { foo } }; say A.parse('foo')

Result​:
Too many positionals passed; expected 1 argument but got 2
  in any !reduce at /tmp/whateverable/rakudo-moar/58226059b53853134de0f265b6f46a923d2004e7/share/nqp/lib/QRegex.moarvm line 1
  in any !cursor_pass at /tmp/whateverable/rakudo-moar/58226059b53853134de0f265b6f46a923d2004e7/share/nqp/lib/QRegex.moarvm line 1
  in regex so at /tmp/1zrz_lKZXc line 1
  in regex TOP at /tmp/1zrz_lKZXc line 1
in block <unit> at /tmp/1zrz_lKZXc line 1

Code​:
grammar A { token TOP { <kuso> }; token kuso { foo } }; say A.parse('foo')

Result​:
ï½¢fooï½£
kuso => ï½¢fooï½£

@p6rt
Copy link
Author

p6rt commented Jan 24, 2017

From @zoffixznet

On Mon, 23 Jan 2017 01​:02​:07 -0800, alex.jakimenko@​gmail.com wrote​:

Code​:
grammar A { token TOP { <so> }; token so { foo } }; say A.parse('foo')

Result​:
Too many positionals passed; expected 1 argument but got 2
in any !reduce at /tmp/whateverable/rakudo-
moar/58226059b53853134de0f265b6f46a923d2004e7/share/nqp/lib/QRegex.moarvm
line 1
in any !cursor_pass at /tmp/whateverable/rakudo-
moar/58226059b53853134de0f265b6f46a923d2004e7/share/nqp/lib/QRegex.moarvm
line 1
in regex so at /tmp/1zrz_lKZXc line 1
in regex TOP at /tmp/1zrz_lKZXc line 1
in block <unit> at /tmp/1zrz_lKZXc line 1

Code​:
grammar A { token TOP { <kuso> }; token kuso { foo } }; say
A.parse('foo')

Result​:
ï½¢fooï½£
kuso => ï½¢fooï½£

This is a dupe of RT#​127945. Tokens with names of Mu methods invoke those on the default Actions class. The workaround is to override those in your own Actions class.

@p6rt
Copy link
Author

p6rt commented Jan 24, 2017

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

@p6rt
Copy link
Author

p6rt commented Jan 24, 2017

@zoffixznet - Status changed from 'open' to 'rejected'

@p6rt
Copy link
Author

p6rt commented Jul 7, 2018

From @zoffixznet

The aforementioned TODO fudge has been removed from the spec in Raku/roast@6bf5aaebdd
Re-add if this issue is resolved in the way the test expects it to.

@raiph
Copy link

raiph commented Nov 11, 2023

I didn't mean to close this. Fat fingers. That said, I think that the fix to the issue I just mentioned this in means this issue may, hopefully will, be closed.

@codesections
Copy link

Fixed in Raku/roast@31115d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants