Skip to content

Print double breaks after statements to avoid ambiguity #4689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2018

Conversation

nicolasstucki
Copy link
Contributor

For example, the first snippet is foo.apply(...) and the second is
eval foo and then eval the block.

foo
{
 ...
}
foo;
{
 ...
}

liufengyun
liufengyun previously approved these changes Jun 20, 2018
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM

this += ";"
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a blank line instead of ;?

Also, it seems it's only needed if the previous tree may cause ambiguity. This can be an improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be implemented but it would require knowing which is the next tree is printed and how it will be printed. This solution is much simpler, homogenous and less bug-prone. I will try to remove them in the future once I have a complete test suite.

Using by default an additional blank line add too many lines. I would consider if we only print it when needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add ; all the time? Looking at the diff, I find it a bit weird that sometime a statement ends with ; and sometime not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it at the end of all statements. The expression at the end of the block does not need it. Look at it as a separator.

Still later I will work on making the format nicer to look at. For now the main goal is corecness.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a blank line instead. Writing semicolons is just so weird when looking at Scala code. I believe there is an easy way to add blank lines: When you print a statement sequence, add blank line in front of every Block node, except if it is the first statement.

@nicolasstucki nicolasstucki force-pushed the add-colon-to-statement branch 2 times, most recently from c91c182 to 57b9a51 Compare June 21, 2018 06:13
@nicolasstucki nicolasstucki changed the title Print ; at the end of statements to avoid ambiguity Print double breaks after statements to avoid ambiguity Jun 21, 2018
@nicolasstucki nicolasstucki force-pushed the add-colon-to-statement branch from 57b9a51 to daea935 Compare June 21, 2018 06:14
@nicolasstucki nicolasstucki dismissed stale reviews from odersky and liufengyun June 21, 2018 06:15

Changed to line breaks

@nicolasstucki nicolasstucki requested a review from liufengyun June 21, 2018 06:16
@nicolasstucki
Copy link
Contributor Author

@liufengyun could you re-review this PR

For example, the first snippet is `foo.apply(...)` and the second is
eval `foo` and then eval the block.

```scala
foo
{
 ...
}
```

```scala
foo

{
 ...
}
```
@nicolasstucki nicolasstucki force-pushed the add-colon-to-statement branch from daea935 to d5d991d Compare June 21, 2018 07:03
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolasstucki nicolasstucki merged commit 998de24 into scala:master Jun 21, 2018
@Blaisorblade Blaisorblade deleted the add-colon-to-statement branch June 21, 2018 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants