-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SyntaxParse] Parse collection expression #27565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2fbce85
to
888fabc
Compare
@swift-ci Please test |
@swift-ci Please test |
Build failed |
Build failed |
Optimize for libSyntax parsing. The new 'parseListSyntax()' receives a vector storage, passes element builder to the callback for populating the elements, then automatically parses trailing commas. Also, it performs automatic recovery if the element has an error (e.g. Skip until ',' or ')').
(Implemented by Nathan Hawes @nathawes)
(implemented by Nathan Hawes @nathawes) Advance \p Loc to the last non-missing token of the specified or, if it doesn't contain any, the last non-missing token preceding it in the tree.
For non-migrated expression / decl attributes. Clean-up the slot after the use. Assert there's no existing element at the location.
In AST token range, string literal token must be treated as a single token.
888fabc
to
fa991ba
Compare
void ASTGen::addExpr(Expr *E, const SourceLoc Loc) { | ||
assert(!hasExpr(Loc)); | ||
Exprs[Loc] = E; | ||
} | ||
|
||
bool ASTGen::hasExpr(const SourceLoc Loc) const { | ||
return Exprs.find(Loc) != Exprs.end(); | ||
} | ||
|
||
Expr *ASTGen::takeExpr(const SourceLoc Loc) { | ||
auto I = Exprs.find(Loc); | ||
assert(I != Exprs.end()); | ||
auto expr = I->second; | ||
Exprs.erase(I); | ||
return expr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathawes To deal with backtracking, I modified this to erase the slot in the map after the use.
CharSourceRange getDeferredLayoutRange(bool includeTrivia) const { | ||
CharSourceRange getDeferredLayoutRange() const { | ||
assert(DK == DataKind::DeferredLayout); | ||
auto HasValidRange = [includeTrivia](const ParsedRawSyntaxNode &Child) { | ||
return !Child.isNull() && !Child.isMissing() && | ||
Child.getDeferredRange(includeTrivia).isValid(); | ||
}; | ||
auto first = llvm::find_if(getDeferredChildren(), HasValidRange); | ||
if (first == getDeferredChildren().end()) | ||
return CharSourceRange(); | ||
auto last = llvm::find_if(llvm::reverse(getDeferredChildren()), | ||
HasValidRange); | ||
auto firstRange = first->getDeferredRange(includeTrivia); | ||
firstRange.widen(last->getDeferredRange(includeTrivia)); | ||
return firstRange; | ||
return DeferredLayout.Range; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function used to be exponential.
if (!Node.isMissing()) { | ||
// NOTE: We cannot use 'getLastToken()' because it doesn't take string | ||
// literal expressions into account. | ||
if (Node.isToken() || Node.is<StringLiteralExprSyntax>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since StringLiteralExprSyntax
is like { quote (literal-segment | interpolation-segment)* quote }
,
This used to return the location of the end quote. In this case, we have to return the location of the start quote instead.
@swift-ci Please test |
Build failed |
Build failed |
…xparse-exprcollection"" This reverts commit 2f40f24.
super
expressionparseListSyntax()
and updateparseTypeTupleBody()
for thatParser::parseExpressionSyntax()
ASTGen::advanceLocEnd()
ArrayExpr
/DictionaryExpr