Well, what about pack? More generally, if I already have a grammar that states the way something should be arranged, why can't I use that to generate output?
A trivial example is a grammar that has no backtracking possible. <int><char><float> would be similar in meaning to "icf" as a pack control string. More usfully, given a definition of what goes where and how, and a list of named things, apply one to the other and produce output. A high-level nonterminal grammar production makes a very good definition of "what goes where and how", each item in the production being a name for the data and an output rule for how to do the formatting.
I think a Perl6 pattern can be at the very least bent to this end, by generating as a side-effect and not really consuming input. But maybe some feature designs could be involved to make this a cleaner concept, not a trick.
How introspective is the Perl6 pattern definition? Instead of matching against one, can I examine it to see what it's made of? It would be elegant if the pattern object itself had a parse tree, in the same form as the ones it builds.
—John
Edit kudra, 2002-09-05 Replaced I tags in title with '
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Using Perl6 patterns/grammar definition for <I>output</I>?
by merlyn (Sage) on Sep 04, 2002 at 23:10 UTC | |
|
Re: Using Perl6 patterns/grammar definition for <I>output</I>?
by dpuu (Chaplain) on Sep 05, 2002 at 00:07 UTC | |
by John M. Dlugosz (Monsignor) on Sep 05, 2002 at 14:49 UTC | |
by dpuu (Chaplain) on Sep 05, 2002 at 17:52 UTC | |
by John M. Dlugosz (Monsignor) on Sep 05, 2002 at 20:39 UTC | |
by dpuu (Chaplain) on Sep 05, 2002 at 21:28 UTC | |
|