tminor / jsonnet-mode

Emacs major mode for editing Jsonnet files.
GNU General Public License v3.0
46 stars 17 forks source link

Object field name highlighting breaks when field value contains colon characters #33

Open risset opened 2 weeks ago

risset commented 2 weeks ago

For example, in

{
  a: 'b:c'
}

a will not be highlighted.

Adding a space after the colon in the following pattern in jsonnet-font-lock-keywords-1 seems to fix this, but not 100% sure if this would break anything else.

- '("[[:space:]].+:" . font-lock-keyword-face)
+ '("[[:space:]].+: " . font-lock-keyword-face)

Edit: actually since { a:'b:c' } is valid jsonnet, adding a space after the colon in the pattern wouldn't be a great solution :(

tminor commented 1 week ago

I can reproduce this with your example, thanks!

It seems the original intent of this regular expression was to match object keys that are also identifiers (i.e. not strings). If that's the case, this is just a bad way to match those cases. Having a look at Jsonnet's specification, it seems this is perhaps an inappropriate use for font-lock-keyword-face which should instead be reserved for real keywords, e.g. assert, else, etc. I was hoping to avoid another regex problem but it seems font-lock-builtin-face is already used for those cases. Like #31, this would be much more nicely solved with tree-sitter, but I assume that's a whole lot of work (at least as involved as converting indentation to SMIE [q.v. #17]).