in reply to Using Perl6 patterns/grammar definition for 'output'?
After substituting the values into the captures we then are left with:rule foo:w { $a := (\d+) = $b := (\w+) [ , | and ] $c := (\w+) }; dump( rule=>"foo"; a=>7, b=>"hello", c=>"world" );
So the dumper now needs to make two sets of decisions: what whitespace to substitute for the \ss; and whether to use a comma or the word "and" as the final separator. The whitespace issue could be defined as a standard pretty-print policy. But in the absence of any further hints, the dump function can probably do no better than choose an arbitrary (e.g. always first) member of an uncaptured alternation\s+ 7 \s+ hello [ \s* , \s* | \s+ and \s+ ] world
So yes, I definitely think it could be done; but we may want a mechanism to set the policy for the unconstrained parts of a rule. A simple set of rules, such as "generate as little text as possible"; and "choose first option on alternations" would probably be enough for simple expressions. But what about look-ahead assertions; or embedded code: these things would be much harder to define simple rules for. Perhaps our dump function would require anything non-trivial to be captured.
An XML grammar would probably be a nice thing to use to play with the idea: more complex than your pack/unpack (BTW: I like that idea); but much simpler than, say, a full Perl6 grammar. --Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using Perl6 patterns/grammar definition for <I>output</I>?
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 | |
by John M. Dlugosz (Monsignor) on Sep 06, 2002 at 15:49 UTC |