Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions grammar/JSONC.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ comment = single-line-comment / multi-line-comment
; Single-line comment: starts with //, continues until line ending
; Note that the single-line-comment-end is optional, allowing comments to end at the end of the file without a line terminator.
single-line-comment-start = %x2F.2F ; // double solidus
single-line-comment-end = %x0D.0A / %x0A / %x0D
single-line-comment = single-line-comment-start *single-line-comment-char [ single-line-comment-end ]
single-line-comment-char = %x00-09 / %x0B-0C / %x0E-10FFFF ; Any source character except CR and LF (line terminator)
single-line-comment = single-line-comment-start *single-line-comment-char ; Note that this rule should be greedy to consume all characters until the end of the line or the end of the input.
single-line-comment-char = %x00-09 / %x0B-0C / %x0E-2027 / %x2029-10FFFF ; Any source character except CR, LF, LS and PS (line terminator)

; Multi-line comment: /* ... */
; Cannot be nested. The first */ closes the comment.
Expand Down
8 changes: 5 additions & 3 deletions grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ npm run railroad -- grammar/JSONC.abnf grammar/railroad-diagram.html --title "JS

### Notes on EOF for single-line comments

The grammar already allows inline comments to terminate at end-of-file because the line terminator is optional:
The grammar already allows inline comments to terminate at end-of-file because the `single-line-comment` rule does not contain the line terminator:

```abnf
single-line-comment = "//" *single-line-comment-char [ comment-terminator ]
single-line-comment = "//" *single-line-comment-char
```

So diagrams generated from this ABNF should not imply a mandatory line ending.
ABNF (RFC 5234) does not specify whether greedy matching should be used for repetitive syntax. However, greedy matching is mandatory in the `single-line-comment` rule to ensure correct behavior.

Additionally, when LS (U+2028) or PS (U+2029) appears in a single-line comment, it will end the comment and be used as the next input, thus causing parsing failure as an illegal character.