On 1/23/13, David A. Wheeler <[email protected]> wrote:
> 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
>
I assume scomment here is an "in-line" comment like #; or #| ... |#
> === 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 '.) */ )
By my understanding the caller of head assumes that the port has just
finished eating a newline. However the above case does not seem to do
so. I guess ANTLR can transform it somehow, but the Scheme code we
derive might need to put the checker here.
That or I got confused. LOL.
By my understanding, this is the expected source transformation:
. n(expr)
==>
(. (n expr))
==>
(n expr)
... and by my understanding, this should yield an error:
. n(expr) n(expr 2)
However there's no error signalled explicitly at this stage, and
although ANTLR might handle this correctly, I'm not so certain that a
naive Scheme translation would.
We could also try looking at the Java output of ANTLR, though...
> | 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;} )
This bit here confuses me. How does it handle a case like:
foo
\\ ; comment_eol
; same followed by comment_eol
foo
...?
...thinking...
You know, after a bit of thinking, I guess it's because INDENT and
DEDENT are tokens in this case, and my initial understanding was that
t_expr would be entered only when the port is at the start of a line.
Is this correct or have I become horribly confused?
Again, possibly a problem with a naive translation from ANTLR to Scheme.
> | dedent error ))
Yeah. this one looks correct to me. I think this case wasn't handled
in the current Scheme code.
> | 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/readable-discuss
>
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/readable-discuss