10 Comments

RON comments use the DUST comment rules. A comment starts with ; and continues to the end of the line. The ; starts a comment at the start of a line, after a space or tab, or directly after an opening [, { or < that starts a token. In all other positions, ; is text. A semicolon in a quoted string is always text.

A $comment key is ordinary data. JSON and TRON keep the comments in one root $comment member, as the DUST comment rules show.

Each value has a maximum of one comment text. These rules give each comment to a value:

  • A comment after a value on the same line belongs to that value.
  • A comment on its own line belongs to the next value.
  • A comment directly after an opening bracket belongs to the next value.
  • When closing brackets come before the comment on a line, the comment belongs to the outermost value that these brackets close.

When a value has more than one comment, the reader joins the texts in source order, with a line feed between them. In this example, /a has the text first, /b has second and third on two lines, and /c has fourth:

a 1 ; first
; second
b 2 ; third
; fourth
c 3

In this example, the comment c belongs to the list item 1:

fields [; c
  1 2]

The reader refuses a comment that no value can own, with an Invalid_Comment error at the offset of the first ; that has no value. These comments are refused:

  • A comment before a closing bracket or in an empty container.
  • A comment after the last value of a document, and a document that contains only comments.
  • A comment inside a tag group.
  • A comment between a tag and its payload. Write the comment above the tagged value.

A #template payload holds no comment. A comment among its literal pieces or embedded forms is an Invalid_Comment error at the comment. A comment after the payload's closing bracket belongs to the template as a whole.

Canonical formatting writes each comment as ; lines directly above its value. A text with line feeds gives one ; line for each line of the text. A blank line goes above each comment block. There is no blank line at the start of the document or directly after an opening bracket.

For example, canonical formatting writes the example with four comments above as:

; first
a 1

; second
; third
b 2

; fourth
c 3
RON
; A person
name Ada ; Display name
→
Canonical RON
; A person
; Display name
name Ada
→
{} JSON
{
  "$comment": "{\"/name\":\"A person\\nDisplay name\"}",
  "name": "Ada"
}
RON
fields [
  id ; identifier
]
→
Canonical RON
fields [
  ; identifier
  id]
→
{} JSON
{
  "$comment": "{\"/fields/0\":\"identifier\"}",
  "fields": [
    "id"
  ]
}