Skip to content

Clarify single-line comment behavior in documentation - #24

Closed
chirsz-ever wants to merge 1 commit into
JSONC-org:mainfrom
chirsz-ever:patch-2
Closed

Clarify single-line comment behavior in documentation#24
chirsz-ever wants to merge 1 commit into
JSONC-org:mainfrom
chirsz-ever:patch-2

Conversation

@chirsz-ever

Copy link
Copy Markdown
Contributor

According to ECMA-262, a single-line comment consists of // followed by characters which are not line terminators.

Therefore, a line comment can be placed at the end of a file, string, or input without being followed by a newline character.

@DecimalTurn

Copy link
Copy Markdown
Member

I think the current wording is already clear enough. The comment still continues until a line ending is reached, it's just that when comment is at the end of the file with no EOL at the end, we stop at EOF while we are still inside the comment.

@DecimalTurn

Copy link
Copy Markdown
Member

I think a better option would be:

Single-line comments start with // and continue until a line ending, a line seperator (U+2028) or a paragraph seperator (U+2029) is encountered.

Thoughts?

@chirsz-ever

Copy link
Copy Markdown
Contributor Author

I'm glad we're on the same page.

The PR has been revised to match your wording.

With the ABNF description, the importance of natural language description is reduced; it's OK to edit or close this PR.

@DecimalTurn

Copy link
Copy Markdown
Member

Based on the updated discussions in #23 (comment), I'll close this PR for now since we are not likely to allow U+2028 and U+2029 for security reasons.

Regarding the comment added at the end of the code snippet to illustrate that a comment at the end of the file is still valid even if it doesn't have a line ending after it, I don't thing this is something that the average JSONC user is worried about and it goes without saying I'd say.

However, it's something that has to be clear in the ABNF:
https://jsonc.org/grammar/railroad-diagram.html

Having the option to skip the single-line-comment-end rule to match with nothing allows to match the end of the file.
Matching with nothing is otherwise impossible assuming that the ABNF is interpreted "greedily".

image

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.

2 participants