mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
libSyntax: parse function argument syntax node. (#12803)
This commit teaches parser to parse two libSyntax nodes: FunctionCallArgument and FunctionCallArgumentList. Along with the change, some libSyntax parsing infrastructure changes as well: (1) parser doesn't directly insert token into the buffer for libSyntax node creation; instead, when creating a simple libSyntax node like integer literal expression, parser should indicate the location of the last token in the node; (2) implicit libSyntax nodes like empty statement list must contain a source location indicating where the implicit nodes should appear (immediately before the token at the given location).
This commit is contained in:
@@ -19,10 +19,15 @@
|
||||
#include "swift/AST/ASTWalker.h"
|
||||
#include "swift/AST/Initializer.h"
|
||||
#include "swift/Basic/StringExtras.h"
|
||||
#include "swift/Syntax/SyntaxFactory.h"
|
||||
#include "swift/Syntax/TokenSyntax.h"
|
||||
#include "swift/Syntax/SyntaxParsingContext.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/Support/SaveAndRestore.h"
|
||||
|
||||
using namespace swift;
|
||||
using namespace swift::syntax;
|
||||
|
||||
/// \brief Determine the kind of a default argument given a parsed
|
||||
/// expression that has not yet been type-checked.
|
||||
@@ -162,6 +167,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
||||
return parseList(tok::r_paren, leftParenLoc, rightParenLoc,
|
||||
/*AllowSepAfterLast=*/false,
|
||||
diag::expected_rparen_parameter,
|
||||
SyntaxKind::Unknown,
|
||||
[&]() -> ParserStatus {
|
||||
ParsedParameter param;
|
||||
ParserStatus status;
|
||||
@@ -795,7 +801,8 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
|
||||
/*isExprBasic=*/false,
|
||||
lParenLoc, args, argLabels,
|
||||
argLabelLocs, rParenLoc,
|
||||
trailingClosure);
|
||||
trailingClosure,
|
||||
SyntaxKind::Unknown);
|
||||
if (status.isSuccess()) {
|
||||
backtrack.cancelBacktrack();
|
||||
|
||||
@@ -947,6 +954,7 @@ ParserResult<Pattern> Parser::parsePatternTuple() {
|
||||
parseList(tok::r_paren, LPLoc, RPLoc,
|
||||
/*AllowSepAfterLast=*/false,
|
||||
diag::expected_rparen_tuple_pattern_list,
|
||||
SyntaxKind::Unknown,
|
||||
[&] () -> ParserStatus {
|
||||
// Parse the pattern tuple element.
|
||||
ParserStatus EltStatus;
|
||||
|
||||
Reference in New Issue
Block a user