Skip to content

Support comments everywhere newline is treated as whitespace #924

@SitiSchu

Description

@SitiSchu
Contributor

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:
      ]

Activity

krader1961

krader1961 commented on Feb 24, 2020

@krader1961
Contributor

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.

changed the title [-]Support comments inside lists[/-] [+]Support comments inside multiline lists[/+] on Feb 24, 2020
changed the title [-]Support comments inside multiline lists[/-] [+]Support comments inside lists and maps[/+] on Feb 24, 2020
SitiSchu

SitiSchu commented on Feb 24, 2020

@SitiSchu
ContributorAuthor

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

xiaq commented on Apr 4, 2020

@xiaq
Member

@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.

added this to the 0.14 milestone on Apr 4, 2020
krader1961

krader1961 commented on Apr 10, 2020

@krader1961
Contributor

@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.

changed the title [-]Support comments inside lists and maps[/-] [+]Support comments everywhere newline is treated as whitespace[/+] on May 2, 2020
xiaq

xiaq commented on May 2, 2020

@xiaq
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xiaq@krader1961@SitiSchu

        Issue actions

          Support comments everywhere newline is treated as whitespace · Issue #924 · elves/elvish