Feeding
=======

Feeding is unique to **pacc**, and solves a problem with PEG parsing: if
the input is coming from an interactive stream, how do we know when to
prompt the user for more input? Note that since this is an interactive
stream, we need to give the user some idea that more input is needed,
for example the ``PS2`` prompt in the Bourne shell. (With a tokenized
LALR(1) parser, it is simple: when the parser asks the lexer for the
next token, it simply prompts the user for more input if it needs it.)

The approach taken by **pacc** is as follows. First, we need to identify
some *feed rule* that matches where a partial input may end. In a normal
interactive application, this rule will match ``"\n" *`` (i.e. zero or
more occurences of the newline character). Conventionally, this rule is
named ``__`` (two underscores), although another name can be given with
the ``-r`` flag.

When **pacc** is invoked with the ``-f=FILE`` option, it writes its
normal output as usual, then it writes an *additional* parser to the
specified ``FILE`` for a grammar which has been modified in the
following ways:

1. all semantic *expressions* have been removed;
2. wherever a call to the *feed rule* occurs, the rule and the rest of
   the sequence in which it occurs are optional.

For example, consider this trivial grammar, which sums two digits,
possibly on separate lines::

  Sum :: int ← a:Digit __ b:Digit "\n" → { a + b }
  Digit ← [0-9]  → { *ref_ptr(ref()) - '0' }
  __ ← "\n" *

In the extra parser generated when feeding is enabled, the first line
will effectively be this::

  Sum :: int ← a:Digit (__ b:Digit "\n" / ε)
