Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Oct 1, 2019

Also added parseExpressionSyntax as an intermediate syntax parser until
expression parsing is completely implemented.

Also added parseExpressionSyntax as an intermediate syntax parser until
expression parsing is completely implemented.
@nathawes nathawes requested a review from rintaro October 1, 2019 17:14
@nathawes
Copy link
Contributor Author

nathawes commented Oct 1, 2019

@swift-ci please test

if (!hasExpr(CondLoc))
return nullptr;

Expr *CondExpr = getExpr(CondLoc);
Copy link
Member

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());
Copy link
Member

@rintaro rintaro Oct 1, 2019

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);
Copy link
Member

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));
Copy link
Member

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);
Copy link
Member

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");
Copy link
Member

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@swift-ci
Copy link
Contributor

swift-ci commented Oct 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 1b2b70e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants