-
Notifications
You must be signed in to change notification settings - Fork 288
Add example "Add actions directly", review needed #1635
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
Conversation
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!
doc/Language/grammar_tutorial.pod6
Outdated
@@ -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 |
There was a problem hiding this comment.
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".
doc/Language/grammar_tutorial.pod6
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"?
doc/Language/grammar_tutorial.pod6
Outdated
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. |
There was a problem hiding this comment.
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".
There was a problem hiding this 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!
doc/Language/grammar_tutorial.pod6
Outdated
grammar G { | ||
rule TOP { <function-define> } | ||
rule function-define { | ||
'sub' <identifier> { |
There was a problem hiding this comment.
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; }
There was a problem hiding this comment.
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!
doc/Language/grammar_tutorial.pod6
Outdated
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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this 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.
doc/Language/grammar_tutorial.pod6
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ifself" → "itself"
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!