Skip to content

Fix places where grammar.md doesn't match the parser - #635

Open
qodelicious wants to merge 2 commits into
ron-rs:masterfrom
qodelicious:docs-grammar-match-parser
Open

qodelicious wants to merge 2 commits into
ron-rs:masterfrom
qodelicious:docs-grammar-match-parser

Conversation

@qodelicious

Copy link
Copy Markdown
Contributor

Fixes #614

Updates docs/grammar.md so it matches what the parser actually accepts. I checked each case against Deserializer::from_str + IgnoredAny + end() on master.

  • Strings and byte strings. A \ always starts an escape, so "a\c" is rejected. The plain character class now excludes the backslash too.
  • Unicode escapes need braces, so \u{41} works and \u0041 doesn't. Also added a note that it takes 1 to 6 hex digits and has to be a valid scalar value.
  • Chars take the same escapes as strings ('\n', '\x41', '\u{41}' all parse), just without line continuations, and a \x escape in a char has to be ASCII.
  • Ranges don't allow whitespace around .. or ..= (1 .. 2 and .. 5 are rejected), so I dropped the ws from those rules.
  • Whitespace and comments are allowed before #![enable(...)], so RON now starts with ws.

I left out the bare ''' char and the 1e_+0 exponent cases from the issue, since they look more like parser quirks than something the grammar should promise.

  • I've included my change in CHANGELOG.md

Comment thread docs/grammar.md

```ebnf
char = "'", (no_apostrophe | "\\\\" | "\\'"), "'";
char = "'", (no_apostrophe_or_backslash | char_escape), "'";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are no_double_quotation_marks_or_backslash or no_apostrophe_or_backslash defined? If they aren't yet, they should be given an explicit rule similar to nested_block_comment

This branch has not been deployed

No deployments
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.

docs/grammar.md diverges from the parser in 6 places (string/char escapes, ranges, exponent)

2 participants