Yaml mode does not highlight dict keys with spaces correctly #2695
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Ran into this bug when using brackets. The following code:
Parses correctly here
But it doesn't highlight correctly here (edited the css to make it clearer)
On the yaml spec I found this example that shows keys with spaces being used. I think keys should be highlighted from the beginning of the indentation to the ":" character.
Browser: Firefox 30, Windows. I use the yaml mode index.html from github master.
I know very little about YAML, and did not write the original mode. I also couldn't make much sense of the spec you linked (I never saw such a convoluted cfg), but the attached patch seems to help. Could you take a look to see whether it looks sane to you?
Thanks!
Actually, I didn't fully read the spec too when I first reported this, so I just picked an example that demonstrates the issue...
I've tested the new code, and it works for the common use cases, with two bugs: Indented YAML comments with a
:are parsed as a key-value pair, and some valid YAML are not highlighted.Source
After I found that, I started reading the YAML spec and found something that I think is a definition of a valid YAML key.
The previous YAML that don't highlight correctly are defined as flow plain scalar styles. Basically unquoted plain strings. And it says... (emphasis mine)
I've collected all the indicators that are not allowed (I think). They are:
This file contains some YAML that uses those characters.
The indicators may be included in the middle of a string. For example, this:
is valid YAML.
Also, they can be included in the beginning of a string if it is a quoted string.
One thing that might be a problem is comments:
I'm not good with regexes, so I can't contribute code to solve this problem (sorry!) but I can probably contribute a summary of a valid YAML key.
''or"", bypassing all the following rules.,[]{}#&*!|>'"%@#(with space before it) because that starts a YAML comment, preventing the colon and the value from being read.:(space after colon not optional)I've tried to improve the regexp. It seems the YAML mode does not handle quotes at all, and in generally is extremely primitive, though.
This last commit seems fine. Invalid keys are still highlighted as keys, but I don't think it's a big problem in actual use.