This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] nested and tagged template strings.
ClosedPublic

Authored by mprobst on Jul 15 2016, 5:41 PM.

Diff Detail

Event Timeline

mprobst updated this revision to Diff 64214.Jul 15 2016, 5:41 PM
mprobst retitled this revision from to clang-format: [JS] nested and tagged template strings..
mprobst updated this object.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
mprobst added inline comments.Jul 15 2016, 5:45 PM
lib/Format/TokenAnnotator.cpp
1821

I've chosen 100 by fair dice roll. Please advise on how to pick a reasonable penalty :-)

Prazek added a project: Restricted Project.Jul 16 2016, 9:23 AM
djasper added inline comments.Jul 18 2016, 7:00 AM
lib/Format/FormatTokenLexer.cpp
231

I think, this could now use an elaborate comment on what it is actually trying to parse. And part of that should probably make it into the patch description.

236

Indent seems off.

246

Maybe use "Offset[1]" instead of "*(Offset + 1)"?

lib/Format/TokenAnnotator.cpp
1821

In what cases would you actually want to put a line break here? Presumably, if otherwise the column limit is violated. Are there any other cases?

mprobst marked an inline comment as done.Jul 20 2016, 6:25 PM
mprobst added inline comments.
lib/Format/FormatTokenLexer.cpp
231

Done. Also, it turns out my attempt here was overly optimistic, I actually need a proper state stack to handle this correctly.

246

Is somePointer[1] idiomatic C for "the next element after this pointer"? To me + 1 seemed like a better expression of intent, if a bit more wordy. Done in any case.

lib/Format/TokenAnnotator.cpp
1821

No, I think breaking in the template string should probably be a last resort. It's IMHO conceptually tighter than string concatenation using +. That being said, I have no idea what number that should translate into :-)

mprobst updated this revision to Diff 64803.Jul 20 2016, 6:26 PM
  • Use a stack to parse nested template strings.
  • move docs

Friendly ping :-)

djasper added inline comments.Aug 2 2016, 4:49 AM
lib/Format/FormatTokenLexer.cpp
243

I'd use Offset[0]

lib/Format/FormatTokenLexer.h
69

Should we also use this for GreaterStashed and LessStashed?

mprobst updated this revision to Diff 68687.Aug 19 2016, 7:39 AM
  • Use a stack to parse nested template strings.
  • move docs
  • Fold GreaterStashed, LessStashed into TOKEN_STASHED lexer state.
mprobst marked 9 inline comments as done.Aug 19 2016, 7:42 AM
mprobst updated this revision to Diff 68851.Aug 22 2016, 6:29 AM
  • Test escaped dollar sign.
lib/Format/FormatTokenLexer.cpp
245

Question by @ygao in the other diff:

What happens if the '${' is immediately after a backslash (the if statement above), should the '${' get escaped?

A template like foo\${bar} is the literal string 'foo\${bar}', i.e. the \ acts as an escape for the '$' sign. I've added a test to validate that.

mprobst updated this revision to Diff 68853.Aug 22 2016, 6:34 AM
  • Fix escaping issue.
djasper accepted this revision.Aug 24 2016, 3:42 PM
djasper edited edge metadata.

Looks good. Sorry for the delay!

lib/Format/FormatTokenLexer.h
60

.. in turn.

This revision is now accepted and ready to land.Aug 24 2016, 3:42 PM

No worries, thanks for the review.

This revision was automatically updated to reflect the committed changes.