[PATCH] D156429: [TableGen] Add new bang operator !format

Simon Tatham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 07:54:13 PDT 2023


simon_tatham added inline comments.


================
Comment at: llvm/lib/TableGen/Record.cpp:2091-2093
+      // FIXME: This is a really simple string substitution. Shoule we make it
+      // just like std::format?
+      Res = replaceAll(Res, "{" + utostr(I) + "}", Arg->getAsUnquotedString());
----------------
I think it would at least be a good idea to add an escaping system, so that there's no literal text that can't be expressed at all.

Surely the right escaping system is the one that (as far as I can see) Python and `std::format` already agree on: `{{` means a literal `{`, and `}}` means a literal `}`. In particular, `{{{1}}}` ought to expand to a literal `{`, then parameter 1, then a literal `}`.

If you do that, then the syntax has room for future enhancements (by putting more elaborate format specifiers inside the braces), but any format string that starts off valid will continue to be valid and do the same thing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156429/new/

https://reviews.llvm.org/D156429



More information about the llvm-commits mailing list