PackageDev icon indicating copy to clipboard operation
PackageDev copied to clipboard

Sublime Text Syntax Def (YAML) incorrectly handles brackets inside match string

Open sparr opened this issue 10 years ago • 5 comments

- comment: foo
  name: foo2
  match: "\\["
- comment: bar
  name: bar2
  match: "."

the open bracket here causes the close quote to not be recognized, and the remainder of the file is stuck in the meta.value.yaml-tmlanguge string.regexp.set scopes. I think the problem is that meta.value.yaml-tmlanguage includes source.oniregexp which tries to parse the contents of the quotes as an oni regex, but it's actually got one more level of YAML string escapes on top of it. \\[ as a YAML string represents \[ as a regex which represents a literal [. The YAML escaping step seems to be skipped in the syntax recognition.

sparr avatar Dec 08 '15 02:12 sparr

Yeah, I was lazy with that and didn't bother with double-escaped regular expressions, which is required in double-quoted strings.

However, you practically never want to use double-quoted strings in YAML anyway, because

  1. Most strings don't need quoting at all. Yours doesn't, for example. And neither does your second.
  2. Single-quoted strings have way better escape mechanisms, especially für regular expressions, in that you only need to escape a single-quote inside a string and nothing else -- especially no back-slashes.

So yeah, while this is indeed a bug, I'm very much on the "won't fix" side here because it's just not worth it imo. We might want to mention that in the docs too.

In other news, all syntax definitions in this package need a new pass and deserve to be using the new shiny .sublime-syntax format. From scratch. Problem is it's still only available for the dev channel.

FichteFoll avatar Dec 08 '15 03:12 FichteFoll

OK, thanks for the response. I'll try to use single or non-quoted strings when I can figure out how to escape them

sparr avatar Dec 08 '15 04:12 sparr

Closing in favor of #67.

FichteFoll avatar Dec 08 '15 12:12 FichteFoll

Reopening since I'm probably not going to rewrite these syntaxes (a lot of effort for legacy tech). I will revisit this later and re-consider whether I find fixing this worth it or not.

FichteFoll avatar Mar 24 '17 14:03 FichteFoll

Actually... I just realized that I already dismissed this in the new syntax for .sublime-syntax files as well because using single-quoted strings is simply superior over double-quoted, since I don't have to mess with string annoying escape sequences there.

So my recommendation will be to use single quotes for all YAML strings that cannot be plain, but I might fix this small issue just to not blow up.

FichteFoll avatar Mar 24 '17 14:03 FichteFoll

Closing as wontfix. I don't see myself (or anyone else) coming back to this and I also haven't seen a tmLanguage-YAML file in the wild for a while.

FichteFoll avatar Sep 02 '22 20:09 FichteFoll