// followed by a curly.
if (FormatTok->is(TT_JsFatArrow)) {
nextToken();
- if (FormatTok->is(tok::l_brace)) {
+ if (FormatTok->is(tok::l_brace))
parseChildBlock();
- }
break;
}
return;
// Parse formal parameter list.
- parseBalanced(tok::l_paren, tok::r_paren);
+ parseParens();
if (FormatTok->is(tok::colon)) {
// Parse a type definition.
// Eat the type declaration. For braced inline object types, balance braces,
// otherwise just parse until finding an l_brace for the function body.
- if (FormatTok->is(tok::l_brace)) {
- parseBalanced(tok::l_brace, tok::r_brace);
- } else {
- while(FormatTok->isNot(tok::l_brace) && !eof()) {
+ if (FormatTok->is(tok::l_brace))
+ tryToParseBracedList();
+ else
+ while(FormatTok->isNot(tok::l_brace) && !eof())
nextToken();
- }
- }
}
parseChildBlock();
}
-void UnwrappedLineParser::parseBalanced(tok::TokenKind OpenKind,
- tok::TokenKind CloseKind) {
- assert(FormatTok->is(OpenKind));
- nextToken();
- int Depth = 1;
- while (Depth > 0 && !eof()) {
- // Parse the formal parameter list.
- if (FormatTok->is(OpenKind)) {
- ++Depth;
- } else if (FormatTok->is(CloseKind)) {
- --Depth;
- }
- nextToken();
- }
-}
-
bool UnwrappedLineParser::tryToParseBracedList() {
if (FormatTok->BlockKind == BK_Unknown)
calculateBraceTypes();
if (FormatTok->is(Keywords.kw_function)) {
tryToParseJSFunction();
continue;
- } else if (FormatTok->is(TT_JsFatArrow)) {
+ }
+ if (FormatTok->is(TT_JsFatArrow)) {
nextToken();
// Fat arrows can be followed by simple expressions or by child blocks
// in curly braces.
bool tryToParseLambda();
bool tryToParseLambdaIntroducer();
void tryToParseJSFunction();
- /// \brief Parses tokens until encountering the CloseKind token, but balances
- /// tokens when encountering more OpenKind tokens. Useful for e.g. parsing a
- /// curly brace delimited block that can contain nested blocks.
- /// The parser must be positioned on a token of OpenKind.
- void parseBalanced(tok::TokenKind OpenKind, tok::TokenKind CloseKind);
void addUnwrappedLine();
bool eof() const;
void nextToken();