[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Handling scomments after "."



In the process of fiddling with ". $" I've noticed that the grammar doesn't
handle scomments after "." at all.  For those just tuning in,
"scomments" are special comments (such as #|....|#), and they're normally handled
by other conventions in the productions.  But after "." is a special situation, and
they aren't handled there.  So we need to fix that.

I've tweaked the BNF grammar to add support for scomments after ".",
as noted below. It's getting ugly, especially for "rest";
it might make sense to pull this out as its own separate
production just for this case (!).  If we do that,
we might as well regularize head vs. rest.  So the changes below
are almost certainly not the last word... just a heads-up that we need
to tweak the rules to make them work cleanly.

--- David A. Wheeler

==============================================


head returns [Object v]
  : PERIOD /* Leading ".": escape following datum like an n-expression. */
      (hspace+ (scomment hspace*)*
        (pn=n_expr hspace* (scomment hspace)* (n_expr error)? {$v = list($pn.v);}
         | /*empty*/  {$v = list(".");} )
       | /*empty*/    {$v = list(".");} )
...


rest returns [Object v]
  : PERIOD /* Improper list */
      (hspace+  (scomment hspace*)*
        (pn=n_expr hspace* (scomment hspace+)* (n_expr error)? {$v = $pn.v;}
         | COLLECTING hspace* pc=collecting_tail hspace*
           (scomment hspace+)* (n_expr error)? {$v = $pc.v;}
         | SUBLIST hspace* ps=rest {$v = $ps.v;}
         | /*empty*/ {$v = list(".");})
       | /*empty*/   {$v = list(".");})