The file "sweet.g" in the development branch is coming together as a reasonable
BNF for sweet-expressions.
I intend to post 1-2 productions at a time, for review and comment. Here's the
first one, the top-level production that defines sweet-expressions. This
production handles special cases (initial indents, blank lines that precede the
sweet-expression, etc.), then calls the production i_expr ("indented
expression") for normal cases.
Comments?
Feel free to look at the whole file, sweet.g in the develop branch, which
defines some of the terminals and non-terminals, such as:
* comment_eol: End-of-line, optionally preceded by a ";..." comment.
* INITIAL_INDENT_NO_BANG: An initial indent without "!"
* n_expr: Neoteric-expression
For EOF handling, for now I'm assuming that the system will insert an extra EOL
at the end of a non-empty file if there isn't one already.
--- David A. Wheeler
=============================
// Top-level sweet-expression production, t_expr.
// This production handles special cases, then in the normal case
// drops to the i_expr production.
// The rule for "indent processing disabled on initial top-level hspace"
// is a very simple (and clever) BNF construction by Alan Manuel K. Gloria.
// If there is an indent it simply reads a single n-expression and returns.
// If there is more than one on an initially-indented line, the later
// horizontal space will not have have been read, so this production will
// fire again on the next invocation, doing the right thing.
// Although "!" is an indent character, it's an error to use it at the
// topmost level. The only reason to indent at the top is to disable
// indent processing, for backwards compatibility. Detecting this as
// an error should detect some mistakes.
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 */
| i_expr {$v = $i_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/learnmore_122712
_______________________________________________
Readable-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/readable-discuss