clang-format regex syntax reference

天涯浪子 提交于 2019-12-23 12:06:43

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/39986368/clang-format-regex-syntax-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!