Here are the key BNF definitions.  These change FF/VT processing based on John 
Cowan's recent comment.
Now uncommented FF/VT have to be on their own line, and they terminate any 
current t-expression.

Again: Are we done?  Any improvements or recommended changes?

--- David A. Wheeler

=== Sweet-expression BNF ====

restart_tail returns [Object v]
  : it_expr more=restart_tail {$v = cons($it_expr.v, $more.v);}
  | comment_eol    retry1=restart_tail {$v = $retry1.v;}
  | (FF | VT)+ EOL retry2=restart_tail {$v = $retry2.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 */
                   /* Handle #!sweet EOL EOL t_expr */
                   | comment_eol restart=t_expr {$v = $restart.v;} )
          | dedent error ))
  | SUBLIST hspace* is_i=it_expr {$v=list($is_i.v);} /* "$" first on line */
  | abbrevh hspace* abbrev_i_expr=it_expr
      {$v=list($abbrevh.v, $abbrev_i_expr.v);} ;

t_expr returns [Object v]
  : comment_eol    retry1=t_expr {$v=$retry1.v;}
  | (FF | VT)+ EOL retry2=t_expr {$v=$retry2.v;}
  | (initial_indent_no_bang | hspace+ )
    (n_expr {$v = $n_expr.v;} /* indent processing disabled */
     | comment_eol retry3=t_expr {$v=$retry3.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. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to