Here's the latest updated BNF for sweet-expressions' main productions. I 
renamed i-expression into it-expression, so that they wouldn't be confused with 
SRFI-49. This uses the restart lists' new restart_tail.

I'm omitting the (voluminous) comments, so you can see the main productions at 
a glance.  There are only 6 productions (rules).  As formatted, it's 70 lines 
(65 ignoring blank lines).  I think it's relatively short and clear.

--- David A. Wheeler

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


restart_tail returns [Object v]:
  it_expr rt=restart_tail {$v = cons($it_expr.v, $rt.v);}
  | comment_eol retry=restart_tail {$v = $retry.v;}
  | restart_end {$v = null;} ;

head returns [Object v]
  : PERIOD /* Leading ".": escape following datum like an n-expression. */
      (hspace+
        (pn=n_expr hspace* {$v = list($pn.v);}
         | empty  {$v = list(".");} /*= (list '.) */ )
       | empty    {$v = list(".");} /*= (list '.) */ )
  | RESTART hspace* restart_tail hspace*
      (rr=rest    {$v = cons($restart_tail.v, $rr.v); }
       | empty    {$v = list($restart_tail.v); } )
  | basic=n_expr_first /* Only match n_expr_first */
      ((hspace+ (br=rest  {$v = cons($basic.v, $br.v);}
                 | empty     {$v = list($basic.v);} ))
       | empty               {$v = list($basic.v);} ) ;

rest returns [Object v]
  : PERIOD /* Improper list */
      (hspace+
        (pn=n_expr hspace* {$v = $pn.v;}
         | empty {$v = list(".");})
       | empty   {$v = list(".");})
  | RESTART hspace* restart_tail hspace*
    (rr=rest     {$v = cons($restart_tail.v, $rr.v);}
     | empty     {$v = list($restart_tail.v);} )
  | scomment hspace* (sr=rest {$v = $sr.v;} | empty {$v = null;} )
  | basic=n_expr
      ((hspace+ (br=rest {$v = cons($basic.v, $br.v);}
                 | empty    {$v = list($basic.v);} ))
       | empty              {$v = list($basic.v);} ) ;

body returns [Object v] :
  it_expr
    (same next_body=body  {$v = cons($it_expr.v, $next_body.v);}
     | dedent             {$v = list($it_expr.v);} ) ;

it_expr returns [Object v]
  : head
    (options {greedy=true;} : (
     GROUP_SPLICE hspace* /* Not initial; interpret as splice */
      (options {greedy=true;} :
        comment_eol error
        | empty {$v = monify($head.v);} )
     | SUBLIST hspace* sub_i=it_expr /* head SUBLIST it_expr case */
       {$v=append($head.v, list(monify($sub_i.v)));}
     | comment_eol // Normal case, handle child lines if any:
       (indent children=body {$v = append($head.v, $children.v);}
        | empty              {$v = monify($head.v);} /* No child lines */ )))
  | (GROUP_SPLICE | scomment) hspace* /* Initial; Interpet as group */
      (group_i=it_expr {$v = $group_i.v;} /* Ignore initial GROUP/scomment */
       | comment_eol
         (indent g_body=body {$v = $g_body.v;} /* Normal GROUP use */
          | same g_i=it_expr {$v = $g_i.v;} /* Plausible separator */
          | dedent error ))
  | SUBLIST hspace* is_i=it_expr /* "$" as first expression on line */
      {$v=list($is_i.v);}
  | abbrevh hspace* abbrev_i_expr=it_expr
      {$v=list($abbrevh.v, $abbrev_i_expr.v);} ;

t_expr returns [Object v]
  : comment_eol t_expr1=t_expr {$v=$t_expr1.v;} /* Initial lcomment, retry */
  | (initial_indent_no_bang | hspace+ )
    (n_expr {$v = $n_expr.v;} /* indent processing disabled */
     | comment_eol t_expr2=t_expr {$v=$t_expr2.v;} )
  | initial_indent_with_bang error
  | EOF {generate_eof();} /* End of file */
  | it_expr {$v = $it_expr.v;} /* Normal case */ ;

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to