diff options
author | Daniel Jasper <djasper@google.com> | 2014-05-08 09:25:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-05-08 09:25:39 +0000 |
commit | c03e16a7bcd4644db6e1bacddd47d9fd47669840 (patch) | |
tree | d63d1517cbe4dc47f72922f6cdfbd858e9f36305 /clang/lib/Format | |
parent | 5ee9fd5f45e73cc52f11f46325c29e205ee9353e (diff) | |
download | bcm5719-llvm-c03e16a7bcd4644db6e1bacddd47d9fd47669840.tar.gz bcm5719-llvm-c03e16a7bcd4644db6e1bacddd47d9fd47669840.zip |
clang-format: [JS] support closures in container literals.
Before:
return {body: {setAttribute: function(key, val) {this[key] = val;
}
, getAttribute : function(key) { return this[key]; }
, style : {
direction:
''
}
}
}
;
After:
return {
body: {
setAttribute: function(key, val) { this[key] = val; },
getAttribute: function(key) { return this[key]; },
style: {direction: ''}
}
};
llvm-svn: 208292
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.h | 1 |
2 files changed, 22 insertions, 3 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 5b6727bf9e4..940fcc8ae2f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -886,6 +886,22 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() { return false; } +void UnwrappedLineParser::tryToParseJSFunction() { + nextToken(); + if (FormatTok->isNot(tok::l_paren)) + return; + nextToken(); + while (FormatTok->isNot(tok::l_brace)) { + // Err on the side of caution in order to avoid consuming the full file in + // case of incomplete code. + if (!FormatTok->isOneOf(tok::identifier, tok::comma, tok::r_paren, + tok::comment)) + return; + nextToken(); + } + parseChildBlock(); +} + bool UnwrappedLineParser::tryToParseBracedList() { if (FormatTok->BlockKind == BK_Unknown) calculateBraceTypes(); @@ -903,9 +919,11 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { // FIXME: Once we have an expression parser in the UnwrappedLineParser, // replace this by using parseAssigmentExpression() inside. do { - // FIXME: When we start to support lambdas, we'll want to parse them away - // here, otherwise our bail-out scenarios below break. The better solution - // might be to just implement a more or less complete expression parser. + if (Style.Language == FormatStyle::LK_JavaScript && + FormatTok->TokenText == "function") { + tryToParseJSFunction(); + continue; + } switch (FormatTok->Tok.getKind()) { case tok::caret: nextToken(); diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h index 8f0c5a3ef41..9eb56011629 100644 --- a/clang/lib/Format/UnwrappedLineParser.h +++ b/clang/lib/Format/UnwrappedLineParser.h @@ -100,6 +100,7 @@ private: void parseObjCProtocol(); bool tryToParseLambda(); bool tryToParseLambdaIntroducer(); + void tryToParseJSFunction(); void addUnwrappedLine(); bool eof() const; void nextToken(); |