-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SyntaxParse] Parse PoundAssertStmt #27460
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
Also added parseExpressionSyntax as an intermediate syntax parser until expression parsing is completely implemented.
@swift-ci please test |
if (!hasExpr(CondLoc)) | ||
return nullptr; | ||
|
||
Expr *CondExpr = getExpr(CondLoc); |
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.
Once we have generate(ExprSyntax)
, this block should be like
auto CondExpr = generate(Stmt.getCondition(), Loc);
if (! CondExpr)
// Don't form a PoundAssertStmt without a condition.
return nullptr;
@@ -98,6 +98,12 @@ llvm::Optional<Syntax> Syntax::getChild(const size_t N) const { | |||
return Syntax {Root, ChildData.get()}; | |||
} | |||
|
|||
Optional<Syntax> Syntax::getPreviousNode() const { | |||
if (auto prev = getData().getPreviousNode()) | |||
return TokenSyntax(Root, prev.get()); |
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.
I believe this should be Syntax
instead of TokenSyntax
.
@@ -34,6 +34,18 @@ | |||
using namespace swift; | |||
using namespace swift::syntax; | |||
|
|||
ParsedSyntaxResult<ParsedExprSyntax> Parser::parseExpressionSyntax(Diag<> ID) { | |||
SourceLoc ExprLoc = Tok.getLoc(); | |||
SyntaxParsingContext ExprParsingContext(SyntaxContext, SyntaxContextKind::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.
nitpick: 80 columns
if (!Tok.isFollowingLParen()) { | ||
diagnose(Tok.getLoc(), diag::pound_assert_expected_lparen); | ||
status.setIsParseError(); | ||
builder.useCondition(ParsedSyntaxRecorder::makeUnknownExpr({}, *SyntaxContext)); |
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.
80 columns.
auto conditionExprResult = parseExpr(diag::pound_assert_expected_expression); | ||
if (conditionExprResult.isParseError()) | ||
return ParserStatus(conditionExprResult); | ||
auto conditionExprResult = parseExpressionSyntax(diag::pound_assert_expected_expression); |
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.
80 columns
auto MessageLoc = Tok.getLoc(); | ||
// FIXME: Support extended escaping string literal. | ||
if (Tok.getCustomDelimiterLen()) { | ||
diagnose(MessageLoc, diag::forbidden_extended_escaping_string, "'#assert' message"); |
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.
ditto
L->getStringLiteralSegments(Tok, Segments); | ||
if (Segments.size() != 1 || | ||
Segments.front().Kind == Lexer::StringSegment::Expr) { | ||
diagnose(MessageLoc, diag::forbidden_interpolated_string, "'#assert' message"); |
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.
ditto
Build failed |
Also added parseExpressionSyntax as an intermediate syntax parser until
expression parsing is completely implemented.