Skip to content

Commit 606cb55

Browse files
Merge pull request #1017 from bazzaar/roundrobin-edits
Grammar Tutorial : attempt to tighten up the description of how the proto token works.
2 parents 547469a + d1d5f70 commit 606cb55

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

doc/Language/grammar_tutorial.pod6

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ This results in any URI coming in getting checked; where the second string betwe
187187
188188
There is another way, though, that can give you far greater flexibility to do interesting or unholy things with your regexes, and provide some better readability when options grow large. These are proto-regexes.
189189
190-
To utilize these multimethods (here called protoregexes) to constrain our command to the same values we had above, we'll replace "token command" with the following:
190+
To utilize these multimethods (here called proto-regexes) to constrain our command to the same values we had above, we'll replace "token command" with the following:
191191
192192
=begin code
193193
proto token command {*}
@@ -197,7 +197,23 @@ To utilize these multimethods (here called protoregexes) to constrain our comman
197197
token command:sym<delete> { <sym> }
198198
=end code
199199
200-
Using protoregexes like this gives us some greater flexibility. For example, instead of returning <sym>, which is the string that was matched, we could instead enter our own string, or do other funny stuff. We could do the same with the "token subject" method, and limit it also to only parsing correctly on valid subjects (like 'part' or 'people', etc.).
200+
The 'sym' keyword is used to create the various proto-regex options. Each option
201+
is named (ie. sym<update>), and for that option's use, a special <sym> token is
202+
auto-generated, that is the case-sensitive string-literal of the name assigned.
203+
204+
The <sym> token, as well as other user-defined tokens, may be used in the proto-
205+
regex option block to define the specific 'match condition'. Regex tokens are
206+
compiled forms, and once defined cannot subsequently be modified by adverb
207+
actions (eg. :i). Therefore, as it's auto-generated, the special <sym> token is
208+
useful only where an exact match of the option name is required.
209+
210+
If, for one of the proto-regex options, a match condition occurs, then the whole
211+
proto's search terminates. The matching data, in the form of a match object, is
212+
assigned to the parent proto token. If the special <sym> token was employed, and
213+
formed all or part of the actual match, then it is preserved as a sublevel in
214+
the match object, otherwise it is absent.
215+
216+
Using proto-regexes like this gives us some greater flexibility. For example, instead of returning <sym>, which in this case is the entire string that was matched, we could instead enter our own string, or do other funny stuff. We could do the same with the "token subject" method, and limit it also to only parsing correctly on valid subjects (like 'part' or 'people', etc.).
201217
202218
=head2 Putting our RESTful grammar together so far
203219
@@ -342,7 +358,7 @@ To do this, all we have to do is add the method TOP to our action class, and in
342358
{
343359
method TOP ($/) {
344360
make { subject => $<subject>.Str,
345-
command => $<command><sym>.Str,
361+
command => $<command>.Str,
346362
data => $<data>.made }
347363
}
348364
@@ -386,7 +402,7 @@ Oh, did we forget to get rid of that ugly array element number? Hmm. Let's make
386402
{
387403
method TOP ($/) {
388404
make { subject => $<subject>.Str,
389-
command => $<command><sym>.Str,
405+
command => $<command>.Str,
390406
data => $<data>.made,
391407
subject-id => $<data>.made[0] }
392408
}
@@ -430,7 +446,7 @@ And this is the grammar and grammar actions that got us there, to recap:
430446
{
431447
method TOP ($/) {
432448
make { subject => $<subject>.Str,
433-
command => $<command><sym>.Str,
449+
command => $<command>.Str,
434450
data => $<data>.made,
435451
subject-id => $<data>.made[0] }
436452
}

0 commit comments

Comments
 (0)