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

Grammar doc discusses action classes but doesn't explain make/made #897

Closed
shadowcat-mst opened this issue Sep 7, 2016 · 5 comments
Closed

Comments

@shadowcat-mst
Copy link

@shadowcat-mst shadowcat-mst commented Sep 7, 2016

Possibly wants a link to https://docs.perl6.org/type/Match#method_make (thanks FROGGS for pointing me at the right FM) plus a note about it?

@shadowcat-mst
Copy link
Author

@shadowcat-mst shadowcat-mst commented Sep 7, 2016

Also, actually, having read that I still hae no idea what e.g. method calc-op:sym ($/) { make [+] $; } actually does :(

@AlexDaniel AlexDaniel added the docs label Sep 10, 2016
@zoffixznet
Copy link
Contributor

@zoffixznet zoffixznet commented Sep 19, 2016

Also, actually, having read that I still hae no idea what e.g. method calc-op:sym ($/) { make [+] $; } actually does :(

make is sugar for $/.make, which lets you attach arbitrary data to $/, which is the current Match object. And you'd attach that data for the purposes of using it elsewhere. That's all there is to it. A storage place for arbitrary data.

The method calc-op:sym<add> ($/) { make [+] $<num>; } gets called when the rule calc-op:sym<add> { <num> '+' <num> } finishes parsing. Notice how it has two <num> tokens in it. Those end up as a 2-item array in $<num>. The [+] is a meta operator that uses + between each of the elements of the list, so in this case, it's equvalent of $<num>[0] + $<num>[1]. We use that result as the argument to make, so that means the $/ that method calc-op:sym<add> got called with now has that value attached to it.

The .made method (or its alias .ast), lets you access that arbitrary data that you stored. So when in the calculator example we have this: method TOP ($/) { make $<calc-op>.made; }, the TOP's Match object will have calc-op named capture with the Match object to which we attached calculation's result, so we just access that result (with .made) and store it in TOP's Match object (with make).

When the parsing is done with say Calculator.parse('2 + 3', actions => Calculations), it returns the Match object (the same we worked on in method TOP). And we did attach the calculation's result to it, so by calling .made on that Match object we get the result of the calculation after parsing.

@zakame
Copy link
Contributor

@zakame zakame commented Sep 4, 2017

This confused me a lot too when first learning about Grammars, at least until the Grammar Tutorial came out. I'd still like to see a simpler grammar/action example illustrating make/made though.

Let me see if I can write one...

@TisonKun
Copy link
Collaborator

@TisonKun TisonKun commented Nov 4, 2017

@zoffixznet it can be easy adding a section in /language/grammar to point it out, but do we really need it? Note that we already have something involved mentioned in /type/Match#method_make.

Besides I find issues such like #114, #1646 talking about organizing the whole documentation to be neat and in distinct levels. Should we combine these issues and put forward a workable TODO list?

Anyway, in my opinion, make/made is basic usage, so they should be at least mentioned at the /language part.

@TisonKun TisonKun added the LHF label Nov 4, 2017
@JJ
Copy link
Contributor

@JJ JJ commented Mar 23, 2018

Actions in general, and in particular make and made, are now discussed in this section about Action objects. So I guess this is hanging so low it can be closed. :-)

@JJ JJ closed this Mar 23, 2018
@JJ JJ added the TPF Grant label Mar 23, 2018
@coke coke added good first issue and removed LHF labels Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants