Hi,

Your suggestions got me thinking further.  Thanks for the effort in
replying.

What I really want is a unified way of writing a rule so that its
output can either be returned as a single list value or possibly
multiple element pushed on a stream depending on the caller's context.
So, really, this kind of rule would only push things on a stream if
the rule was at the toplevel of the parser.

The Scheme semantics of unquote-splicing are somewhat similar to what
I want--the values are placed into a container provided by the parent
rule.  Abusing that notion in an imaginary grammar syntax inspired by
Ian's, say we have:

foo = bar :b           -> `,@b                  ;
bar = baz :a bot :b    -> `,@(list a ,@b "zot") ;
baz = "bingo"                                   ;
bot = "bottom"                                  ;

Then if you called the grammar's "foo" rule as the toplevel in a
stream context, "bingo", $b, $o, $t, $t, $o, $m, "zot" would be
written to the stream, only after the foo rule committed to a match.
In a value context, you would receive '("bingo" $b $o $t $t $o $m
"zot").

Alessandro Warth <[email protected]> writes:

> I'm not sure that what I've described completely solves your
> problem. The part that's missing is that if you want this to work
> well with concurrency, then you'll need a really good story for how
> the "corrections" that are made to the output stream (that happen
> upon backtracking) won't mess up the next parser/ matcher on the
> pipeline. But I think that can be worked out with some careful
> thinking.

My story for backtracking is that any rules that may be backtracked
don't output directly to the stream, rather they record their output
in a buffer until there's a commitment (i.e. the toplevel rule has no
remaining alternation and a subrule has matched successfully).  This
would work fine for grammars with some annotation.

start = header? :h expr* :e   -> `,@(list my-ast ,(process-header h) ,@e) ;

To parse that rule in a stream context shouldn't need to do anything
magical, except to track which output needs to be buffered until a
commitment, or which output is returned to the parent as a direct
value.

Anyway, that's my story, and I'm stickin' to it (until further
notice). ;)

Thanks,

-- 
Michael FIG <[email protected]> //\
   http://michael.fig.org/    \//

_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to