toml-lang / toml

Tom's Obvious, Minimal Language
https://toml.io
MIT License
19.55k stars 856 forks source link

Inconsistent comments #487

Closed ColinH closed 6 years ago

ColinH commented 7 years ago

Why are the rules for comments so inconsistent and complicated? For example take all the places where empty lines are allowed. In some cases there can be arbitrary many comment lines among the empty lines, in some cases only a single comment is allowed, and in others again there can be no comments.

[a]

# Here arbitrary many comments
# can

# be put.

d = [

# This comment is NOT allowed.

1,

# Here only ONE comment is possible.

3
]
ChristianSi commented 7 years ago

Does this refer to the ABNF? According to the written spec, comments are allowed anywhere in arrays, which is indeed the logical thing. If the ABNF says otherwise that's certainly a mistake.

ColinH commented 7 years ago

Yes, I used the ABNF since it is more precise. After converting it to PEGTL I tested with various inputs.

TheElectronWill commented 7 years ago

Hmm yes this should be allowed. A mistake in the ABNF or in the PEGTL conversion?

ColinH commented 7 years ago

It's the ABNF, the rule for array-values only allows a single comment after a value (and its comma, if present). And no comments before the first value.

array = array-open array-values array-close

array-open  = %x5B ws-newline  ; [
array-close = ws-newline %x5D  ; ]

array-values = [ ( val array-sep [ ( ws-newline comment ws-newlines) / ws-newlines ] array-values ) /
                 ( val [ array-sep ] [ ( ws-newline comment ws-newlines ) ] ) ]

array-sep = ws %x2C ws  ; , Comma

ws-newline       = *( wschar / newline )
ws-newlines      = newline *( wschar / newline )