[Grace-core] Indentation in Grace
Andrew P. Black
black at cs.pdx.edu
Tue Jul 30 16:37:58 PDT 2013
On 17 Jul 2013, at 16:59 , Andrew P. Black wrote:
I've added in our decisions, as of the telecom on 30 July 2013
> I've just had an enlightening conversation with Michael Adams about indentation-sensitive parsing. The executive summary is
>
> -- It's much more complicated than I thought
> -- depending on th details of the rules that we adopt for Grace, we can probably avoid a lot of the complexity
> -- There are a number of decisions that we need to make about what we WANT indentation to do in Grace
>
> Unfortunately, the details of what sort of indentation we want will affect (to some extent) the combinators that we need to implement indentation.
>
> The decisions that we need to make include:
>
> - What productions in Grace's grammar start new indentation scopes:
> method
> object
> class
> block
> argument-list
> Are there any others?
That's all (for now!)
>
> - When the indentation increases, does it increase relative to the line on which the indentation scope starts, or relative to the enclosing indentation scope?
> Michael's mail message dated 12 July 2013 08:34 discusses these alternatives. For example, consider
>
> object { method doit {
> foobar(x)
> }
> }
>
> Is this legal? foobar(x) is syntactically inside the method doit, so it should be indented with respect to that method. It is indented with respect to
> the indentation of the line on which the method starts, but not with respect to the indentation of the enclosing indentation scope, which starts
> with the keyword method.
>
> One problem with line-based indentation is that adding newlines matters, so while the above would be accepted, the following would be rejected:
>
> object {
> method doit {
> foobar(x)
> }
> }
Indentation is with respect to the whole line on which the current indentation scope starts.
>
> - Another choice is whether to require a newline after the token that starts a new indentation scope, unless the end of the scope is on the same line.
> this would outlaw
>
> object { method doit {
>
> altogether, and force us to write
>
> object {
> method doit {
>
> although it would still allow single-line objects and single-line methods if everything fits on one line. The main objection to this is that it may make it
> harder to fit code snippets into papers with a hard page limit! It's a good idea if you like to use proportionally-spaced fonts for your programs
> (because all indentations are now determined by the number of leading spaces, and all spaces have equal width). It also means that the
> distinction between "current indentation scope" and "current line" goes away.
We can't really require a new line for each unit that starts a new indentation scope, because blocks and arg list start a new scope.
>
> - Do we allow semicolons at all, in multi-line layout, or do we require one statement on each line? So can I write:
>
> method doIt {
> stmt1
> stmt2; stmt3
> stmt4
> }
Yes we allow semicolons.
>
> If we allow semicolons, is a trailing semicolon allowed?
Yes, they are allowed. Horrible, but they should be allowed.
> - Do we want to get rid of the braces around class, object and method? As Michael pointed out, we can't make them optional, because that
> introduces an ambiguity.
I think that for now, at lead, we keep the braces.
> - Are there any productions in Grace's grammar that "forget" about indentation. An example is Landin's "except possibly for [parenthesized]
> subsegments" rule, enclosed by Adam's circle-star combinator, which allows
>
> x + v where
> x = -(
> y + z) + w
>
There is no such construct in Grace!
> That may be all for now
So all we need to do now is to write the grammar!
Andrew
More information about the Grace-core
mailing list