Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added grouping to ambiguous alternatives, allow leading newlines inside arrays and spaces after newlines before array elements and newlines and spaces before comments in arrays #378

Merged
merged 6 commits into from
Jan 4, 2017

Conversation

joelself
Copy link
Contributor

RFC 4234 Section 3.5 advises the use of grouping notation rather than "bare" alternation when alternatives consist of multiple rules or literals, e.g. "( int float ) / ( bool char )" instead of "int float / bool char".

I might've gotten the grouping wrong, which just serves to illustrate the importance of using grouping notation.

RFC 4234 Section 3.5 advises the use of grouping notation rather than "bare" alternation when alternatives consist of multiple rules or literals, e.g. "( int float ) / ( bool char )" instead of "int float / bool char".

I might've gotten the grouping wrong, which just serves to illustrate the importance of using grouping notation.
The README.md has this at the end of the first TOML example:
```toml
hosts = [
  "alpha",
  "omega"
]
```
And later says:
>...arrays also ignore newlines....
But the ABNF doesn't allow for a newline to precede the first element.

I wasn't sure if the grammar should allow more than one newline preceding the first element, but given that an arbitrary number of whitespaces are allowed and the readme says that newlines are ignored in general I figured allowing an arbitrary number of newlines best matches your intent. It also won't break anyone that happens to have multiple leading newlines in their arrays.
The array-values production already allows for an arbitrary amount of newlines before the closing brace. It doesn't, however, allow any whitespace after the newlines that don't come just before the closing brace so:
```toml
[5, 6
\t\t]
```
is valid, but
```toml
[5, 6
\t\t
]
```
is invalid. Probably not a big deal.
@joelself
Copy link
Contributor Author

joelself commented Jan 2, 2016

I guess this automatically added my new commits to this pull request.

The documentation states that newlines are ignored in arrays and gives examples of arrays with newlines before the first element, however the ABNF doesn't allow for newlines before the first element. I've added a production for multiple whitespaces or newlines, "ws-newline", and changed the "ws" after the array opening brace to "ws-newline".

@joelself joelself changed the title Added grouping to ambiguous alternatives Added grouping to ambiguous alternatives and alllow leading newlines inside arrays Jan 2, 2016
Back to the README example:
```toml
hosts = [
  "alpha",
  "omega"
]
```
The ABNF allows spaces after an element, but before any newlines, the examples in the README have spaces before elements after a newline which isn't allowed in the grammar. I've added a new production "ws-newlines" which is just like "ws-newline" except it requires at least one newline like the production it replaces("newlines"). With "ws-newlines" it makes it legal to to put whitespace before an element after a newline.
@joelself
Copy link
Contributor Author

joelself commented Jan 2, 2016

Added another new production to allow whitespace before an array element after a newline. The examples in the README do this, but it isn't allowed by the grammar.

@joelself joelself changed the title Added grouping to ambiguous alternatives and alllow leading newlines inside arrays Added grouping to ambiguous alternative, allow leading newlines inside arrays and spaces after newlines before array elements Jan 2, 2016
@joelself joelself changed the title Added grouping to ambiguous alternative, allow leading newlines inside arrays and spaces after newlines before array elements Added grouping to ambiguous alternatives, allow leading newlines inside arrays and spaces after newlines before array elements Jan 2, 2016
Going over your hard example I found I couldn't parse this:
```toml
        multi_line_array = [
            "]",
            # ] Oh yes I did
            ]
```
It turns out that the grammar doesn't allow newlines and whitespaces after the array-sep. I've modified the production again to accommodate newlines and whitespace after the array separator.
@joelself
Copy link
Contributor Author

joelself commented Jan 2, 2016

Going over your hard example I found I couldn't parse this:

        multi_line_array = [
            "]",
            # ] Oh yes I did
            ]

It turns out that the grammar doesn't allow newlines and whitespaces after the array-sep before the comment. I've modified the production again to accommodate newlines and whitespace after the array separator before the comment.

@joelself joelself changed the title Added grouping to ambiguous alternatives, allow leading newlines inside arrays and spaces after newlines before array elements Added grouping to ambiguous alternatives, allow leading newlines inside arrays and spaces after newlines before array elements and newlines and spaces before comments in arrays Jan 2, 2016
after the last element without a leading newline.
@joelself joelself closed this Feb 20, 2016
@joelself joelself deleted the abnf branch February 20, 2016 04:26
@joelself joelself restored the abnf branch February 20, 2016 04:35
@joelself joelself reopened this Feb 20, 2016
@mojombo mojombo merged commit 9882e88 into toml-lang:abnf Jan 4, 2017
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