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

Allow single-quoted strings as keys #354

Closed
lambda-fairy opened this issue Sep 26, 2015 · 7 comments
Closed

Allow single-quoted strings as keys #354

lambda-fairy opened this issue Sep 26, 2015 · 7 comments

Comments

@lambda-fairy
Copy link

The following constructs don't work:

[foo.'bar']
# ...
[foo]
'bar' = 42

But this does:

[foo]
bar = 'baz'

Since key names look a lot like strings, I think it'd be more consistent if they accepted the full string syntax.

@alexcrichton
Copy link
Contributor

I ended up running across this today as well, currently the spec allows for basic strings (e.g. double quotes) in key names, but I'd at least find it useful as well to include literal strings as well!

In terms of just writing TOML it's quite handy to have a rule of thumb that basic and literal strings are accepted in the same locations. I suppose it also kinda brings up the question of whether multi-line literal strings are accepted in keys but I'd be personally fine saying that's niche enough that I wouldn't want to add it just yet.

@BurntSushi
Copy link
Member

I also think it'd be a good idea to allow literal strings as keys. It feels like disallowing them violates the principle of least surprise.

@BurntSushi
Copy link
Member

cc @mojombo A close reading of the spec and the ABNF do seem to explicitly only permit double quoted strings. Was this intentional? What do you think about expanding it to allow literal strings?

@mojombo
Copy link
Member

mojombo commented Jan 23, 2016

I agree with allowing literal strings in table keys. I'm guessing the explicit language comes from a time before literal strings existed. I'll get some changed language in shortly.

@alexcrichton
Copy link
Contributor

Awesome, thanks @mojombo! If you're short on time I also wouldn't mind trying to send a PR, just want to make sure I don't step on any toes!

@mojombo
Copy link
Member

mojombo commented Jan 23, 2016

@alexcrichton Sure, that would be awesome, thanks!

alexcrichton added a commit to alexcrichton/toml that referenced this issue Jan 23, 2016
This clarifies the definition of "quoted keys" in the section about tables to
indicate that keys can either be basic strings (surrounded by double quotes) or
literal strings (surrounded by single quotes).

Closes toml-lang#354
alexcrichton added a commit to alexcrichton/toml that referenced this issue Jan 23, 2016
This clarifies the definition of "quoted keys" in the section about tables to
indicate that keys can either be basic strings (surrounded by double quotes) or
literal strings (surrounded by single quotes).

Closes toml-lang#354
@nroi
Copy link

nroi commented Oct 8, 2017

Are there any plans to update the ABNF? If I read it correctly, the ABNF still prohibits single quotes in keys used for tables.

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

No branches or pull requests

5 participants