Alan Manuel Gloria:
> I assume scomment here is an "in-line" comment like #; or #| ... |#
Yes, you're right. "scomment" is short for "special comment".
The file "sweet.g" in the "develop" branch has the details; here's an extract:
BLOCK_COMMENT : '#|' // This is #| ... #|
(options {greedy=false;} : (BLOCK_COMMENT | .))*
'|#' ;
DATUM_COMMENT_START : '#;' ;
// SRFI-105 notes that "implementations could trivially support
// (simultaneously) markers beginning with #! followed by a letter
// (such as the one to identify support for curly-infix-expressions),
// the SRFI-22 #!+space marker as an ignored line, and the
// format #!/ ... !# and #!. ... !# as a multi-line comment."
// We'll implement that approach for maximum flexibility.
SRFI_22_COMMENT : '#! ' NOT_EOL_CHAR* ;
SHARP_BANG_FILE : '#!' ('/' | '.')
(options {greedy=false;} : .)*
'!#' (SPACE|TAB)* ;
// These match #!fold-case, #!no-fold-case, #!sweet, and #!curly-infix;
// it also matches a lone "#!". The "#!"+space case is handled above,
// in SRFI_22_COMMENT, overriding this one:
SHARP_BANG_MARKER : '#!' (('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'-')*)? (SPACE|TAB)* ;
scomment : BLOCK_COMMENT
| DATUM_COMMENT_START hspace* n_expr
| sharp_bang_comments ;
>
> > === 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.
Sortof. The caller of head assumes that the port has just:
1. Eaten the EOL *OR* is starting at the beginning of the file, and then
2. Eaten all the indentation, too.
Basically, "head" isn't called until we're at a possibly-indented n-expression,
or something that might be an n-expression (like anything beginning with "#").
It's important that all the indentation has been consumed and turned into
INDENT/DEDENT as needed. This is actually the same as with SRFI-49, our "head"
is even basically the same. The main difference in the BNF is that we're being
much more explicit about horizontal space.
> . n(expr)
>
> ==>
>
> (. (n expr))
>
> ==>
>
> (n expr)
Yes. I just fed this into the implementation, and it even worked :-).
> ... and by my understanding, this should yield an error:
>
> . n(expr) n(expr 2)
Correct.
> 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.
ANTLR does indeed handle this correctly; since no production would match this,
it'll detect the problem, whine, and try to auto-resync.
I actually had this as an explicitly-documented error case earlier, but it's
not strictly necessary, so to simplify things I removed it.
If you think we should specifically document this as an error case, I can
re-add it, no problem. I don't want to try to list "all ways to have an
error", but identifying a few important ones is useful (we just have to decide
which ones need doing).
> > 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
That is just "(foo foo)". The indented "\\" reads the rest of the line
(nothing), skips the ;-only line, and then executes the "same" case with the
comment "plausible separator". It might be easier to compare this to:
foo
a
\\
b
=> (foo a b)
I do this in part so that \\ "just works" in the same way as when you do "a \\
b".
The relevant production is here:
> > | (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 */
> 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?
You're correct.
> 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.
--- David A. Wheeler
------------------------------------------------------------------------------
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