4

I want clang-format to not modify comment lines I use to separate functions from each other. I think commentPragmas is the right option for that, but I can't find info on the clang-format regex format.

I tried commentPragmas: '^/\*-.*' to capture my separator lines that look like this

/*------------------------------------------------------------------*/

But the above regex did not work... Where can I look up the syntax for regexes for clang-format?

lo tolmencre
  • 3,804
  • 3
  • 30
  • 60

1 Answers1

5

TL/DR: The flavor is POSIX ERE


As far as I can tell, the regex flavor isn't documented in ClangFormat docs, that's pretty unhelpful.

Let's dig into the source code to find out.

There's a class named ContinuationIndenter, which has a CommentPragmasRegex field, of type... llvm::Regex right here. Well, that's not really helpful either but maybe it's just a wrapper...

Turns out llvm::Regex is a wrapper around... llvm_regex. The header includes this comment though:

This file implements a POSIX regular expression matcher. Both Basic and Extended POSIX regular expressions (ERE) are supported. EREs were extended to support backreferences in matches. This implementation also supports matching strings with embedded NUL chars.

In the header that defines llvm_regex we can also find this comment:

This code is derived from OpenBSD's libc/regex

Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
  • Thanks. However if I am not overlooking something my regex is compliant with posix ere, is it not? Because then I have to look for a different reason why this is not working. – lo tolmencre Oct 11 '16 at 21:14
  • Yes your pattern looks OK. I don't know ClangFormat so I'm not sure I can help further, but if I was to accuse something it would be the `^` - is it set to match on every line by default? – Lucas Trzesniewski Oct 12 '16 at 08:27
  • I already tried with and without, made no difference :/ But thanks anyway, I'll keep experimenting. – lo tolmencre Oct 12 '16 at 09:22