Skip to content

Conversation

tisonkun
Copy link
Member

@tisonkun tisonkun commented Oct 28, 2017

Since this tutorial shows actions in grammar only by associating a action object, I add an example to introduce write actions directly.

As I am a nonnative, maybe there is some improper expression in the text.

Thanks for your review!

Since this tutorial shows actions in grammar only by associating a action object, I add an example to introduce write actions directly.

As a nonnative, maybe there is some improper expression in the text.

Thank for your review!
@@ -567,6 +567,41 @@ Here's the final code:
}
=end code

=head2 Add actions directly

Above we see how to associate grammars with a action objects and perform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave off the "a", so it becomes "with action objects".

it shows.

First, we can add actions inside the grammar ifself, and such actions are
performed once the match arrive them. Note that action object's method will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"once the match arrive them", might want to rewrite it as "arrives at them". I'm not sure if a match "arrives" at a certain action either.

Copy link
Member Author

@tisonkun tisonkun Oct 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar G {
  rule TOP {
    | a { say "42" } b
    | a { say "12" } c
  }
}

G.parse("a c");

@Tyil I want to show that both say "42" and say "12" are reached, as the example above.
How can I express this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"once their [corresponding] patterns are matched"?

performed after the whole regex item matched, while actions inside the grammar
are more flexible. Second, it shows what C<make> really does, which is no more
than a sugar of C<$/.made = ...>. And this trick introduces a way how we pass
message within a regex item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"how we pass messages" or "how we pass a message".

@tisonkun tisonkun requested a review from moritz October 28, 2017 18:41
Copy link
Collaborator

@moritz moritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like this pull request. The two points mentioned inline could be improved, but even if not, it's certainly a net win for the docs.

Thanks!

grammar G {
rule TOP { <function-define> }
rule function-define {
'sub' <identifier> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like the indentation of the code block here, as it suggests a relation to the previous regex atoms that isn't there.

Most regexes/grammars I've seen or written put the curly braces of multi-line blocks on separate lines, which makes them stand out as they should.

For single-line code blocks, it's ok to put the curlies on the same line as the code block itself:

    { say "end " ~ $/.made; }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to rewrite it following the style at https://github.com/moritz/perl-6-regex-code/blob/master/chapter-09-grammars/08-symbol-table.p6

BTW, looking forward to your new book!

it shows.

First, we can add actions inside the grammar ifself, and such actions are
performed once the match arrives at them. Note that action object's method will
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it's not the match that arrives at the actions, but rather the control flow of the regex. (The match is related to the position in the string, not directly to the position within the regex).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I want to express

Copy link
Member

@Tyil Tyil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this typo I see now, it's good otherwise.

This example is a reduced portion of a parser. Let's focus more on the feature
it shows.

First, we can add actions inside the grammar ifself, and such actions are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ifself" → "itself"

@tisonkun tisonkun merged commit 02b3c73 into master Oct 29, 2017
@tisonkun tisonkun deleted the W4anD0eR96-patch-1 branch October 29, 2017 03:53
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

Successfully merging this pull request may close these issues.

4 participants