Skip to content
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

Support comments everywhere newline is treated as whitespace #924

Closed
SitiSchu opened this issue Feb 24, 2020 · 5 comments
Closed

Support comments everywhere newline is treated as whitespace #924

SitiSchu opened this issue Feb 24, 2020 · 5 comments
Labels
Milestone

Comments

@SitiSchu
Copy link
Contributor

@SitiSchu SitiSchu commented Feb 24, 2020

Currently this:

[
    value
    # comment
    value2
]

fails with:

Multiple parse errors:
  should be ']'
    /home/sitischu/.elvish/lib/github.com/mojurasu/riku/test.elv, line 8:
          # comment
  unexpected rune ']'
    /home/sitischu/.elvish/lib/github.com/mojurasu/riku/test.elv, line 10:
      ]
@krader1961
Copy link
Contributor

@krader1961 krader1961 commented Feb 24, 2020

A variation on the above example:

~> put [x #y ]
parse error: 7-8 in [interactive]: should be ']'
parse error: should be ']'
[tty], line 1: put [x #y ]

That illustrates why such syntax is problematic. It's not enough to support comments on lines without any other expression of syntactically significant tokens. Note that even without the trailing ] in that example it fails using current parsing behavior. Which is another road block to changing the behavior since doing so is something that can only be done in a major release.

@SitiSchu SitiSchu changed the title Support comments inside lists Support comments inside multiline lists Feb 24, 2020
@SitiSchu SitiSchu changed the title Support comments inside multiline lists Support comments inside lists and maps Feb 24, 2020
@SitiSchu
Copy link
Contributor Author

@SitiSchu SitiSchu commented Feb 24, 2020

Breaking changes should be fine since we're still below 1.0. Interestingly enough it behaves as expected with lambdas:

~> { put 1 # comment }
   }
▶ 1 
@xiaq
Copy link
Member

@xiaq xiaq commented Apr 4, 2020

@krader1961 I am not sure what's the problem with put [x #y ]. In this case, it is the same as put [x; the closing bracket needs to appear on a second line.

Currently having # inside lists is a syntax error. Making an invalid program valid does not break backward compatibility.

@xiaq xiaq added this to the 0.14 milestone Apr 4, 2020
@xiaq xiaq added the A:Language label Apr 4, 2020
@krader1961
Copy link
Contributor

@krader1961 krader1961 commented Apr 10, 2020

@xiaq, Yes, you're right regarding backward compatibility. I was mislead by the failure of the put [x #y ] example. I expected it to be equivalent to put ['x' '#y'] since I expected # to not be special inside a list.

@xiaq xiaq changed the title Support comments inside lists and maps Support comments everywhere newline is treated as whitespace May 2, 2020
@xiaq
Copy link
Member

@xiaq xiaq commented May 2, 2020

I widened the scope of the issue a bit. There are in fact more places where comments should be allowed but currently aren't, such as argument lists (in a lambda) and braced lists.

@xiaq xiaq closed this in 6fc83a0 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.