diff options
| author | Daniel Jasper <djasper@google.com> | 2015-10-12 03:13:48 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2015-10-12 03:13:48 +0000 |
| commit | 8d0e223498ab523a7668a5e2f3b0cb4849678347 (patch) | |
| tree | 3cd45674fcb88cb96ad5ea4db229b704e6d4e404 /clang/lib | |
| parent | d79eec97fcfeac61cd4f8d38dd4d6ce27ee4a36c (diff) | |
| download | bcm5719-llvm-8d0e223498ab523a7668a5e2f3b0cb4849678347.tar.gz bcm5719-llvm-8d0e223498ab523a7668a5e2f3b0cb4849678347.zip | |
clang-format: [JS] handle character classes in regexes.
Slashes in regular expressions do not need to be escaped and do not
terminate the regular expression even without a preceding backslash.
Patch by Martin Probst. Thank you.
llvm-svn: 250009
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 6bfd9cb5cec..0afa9aa9ce2 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -876,12 +876,23 @@ private: return false; unsigned TokenCount = 0; + bool InCharacterClass = false; for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) { ++TokenCount; auto Prev = I + 1; while (Prev != E && Prev[0]->is(tok::comment)) ++Prev; - if (I[0]->isOneOf(tok::slash, tok::slashequal) && + // Slashes in character classes (delimited by [ and ]) do not need + // escaping. Escaping of the squares themselves is already handled by + // \c tryMergeEscapeSequence(), a plain tok::r_square must be non-escaped. + if (I[0]->is(tok::r_square)) + InCharacterClass = true; + if (I[0]->is(tok::l_square)) { + if (!InCharacterClass) + return false; + InCharacterClass = false; + } + if (!InCharacterClass && I[0]->isOneOf(tok::slash, tok::slashequal) && (Prev == E || ((Prev[0]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace, tok::exclaim, tok::l_square, |

