gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

Indenting by 2 #116

Closed KimBruce closed 7 years ago

KimBruce commented 8 years ago

The latest version of the spec (beginning of layout section) says: "Grace uses braces for grouping. Code layout must be consistent with grouping: indentation must increase by at least two spaces after a brace. Statements are terminated by line breaks when the following line has the same or lesser indentation than the indentation of the line containing the start of the current statement. Statements may optionally be terminated by semicolons."

However, I believe we intended also to require continuation lines to be indented by at least two characters. I originally thought minigrace was inconsistent with the spec because of the following two examples, but by carefully reading the spec see that indenting by one is allowed.

Can we change it to requite an indentation of al least two characters for a continuation to be legal? I.e., an indentation by 1 more than the previous line is illegal in all circumstances.

Minigrace does not enforce indenting of continuations by at least two. The following program is legal:

print
 "hello"

The following gives an error message about a continuation line rather than complaining about what I want to characterize as improper indenting (which students would find more helpful if they do this accidentally):

print "hello"
 print "there"

produces

Syntax error: no method print(_)print(_)
    in "test" (line 1, column 1)

This error message is correct if the single indent is allowed, but I'd rather see a complaint about indenting.

apblack commented 7 years ago

I think that our intention was always to require indentation changes to be by a minimum of two spaces, both for continuation lines and for inner blocks. We should clarify the above wording.

I'm not surprised that minigrace gets this wrong; the parser is full of unexplained +1s, and I have no way of knowing which of these should be +2s. But that's a separate issue.

apblack commented 7 years ago

This was fixed in commit 9077d52