[PATCH] D13765: clang-format: [JS] Handle string literals spanning character classes.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 17 05:02:15 PDT 2015


djasper added inline comments.

================
Comment at: lib/Format/Format.cpp:828
@@ +827,3 @@
+  // Returns \c true if \p Tok can only be followed by an operand in JavaScript.
+  bool PrecedesOperand(FormatToken *Tok) {
+    // NB: This is not entirely correct, as an r_paren can introduce an operand
----------------
lowerCamelCase for function names in LLVM.

================
Comment at: lib/Format/Format.cpp:860
@@ +859,3 @@
+    }
+    if (Prev) {
+      if (Prev->isOneOf(tok::plusplus, tok::minusminus)) {
----------------
I understand and I actually find that hard to understand. I think a better solution might be to pull out a function for this logic. So that you just call:

  if (!canPrecedeRegexLiteral(Prev))
    return;

and then

  bool canPrecedeRegeLiteral(const FormatToken *Prev) {
    if (!Prev)
      return true;
    ..
  }


================
Comment at: unittests/Format/FormatTestJS.cpp:609
@@ -603,1 +608,3 @@
+  // directly following a closing parenthesis.
+  verifyFormat("if (foo) / bar /.exec(baz);");
 }
----------------
This case we could actually fix, right? Because we know that the ")" belongs to the if and if the following token isn't a comment or an open brace, it starts a new statement. Probably shouldn't be done in the same patch, but maybe add a FIXME.


http://reviews.llvm.org/D13765





More information about the cfe-commits mailing list