mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
libSyntax: Support tuple expression.
Tuple expression essentially has the same underlying structure as function call arguments in libSyntax. However, we separate them as different libSyntax kinds for better usability. Different from AST, libSyntax currently allows single-child, label-free tuple expressions (represented as ParenExpr in AST). This is subject to change if we need to adopt the same differentiation in libSyntax in the future.
This commit is contained in:
@@ -19,6 +19,9 @@ EXPR_NODES = [
|
||||
Node('FunctionCallArgumentList', kind='SyntaxCollection',
|
||||
element='FunctionCallArgument'),
|
||||
|
||||
Node('TupleElementList', kind='SyntaxCollection',
|
||||
element='TupleElement'),
|
||||
|
||||
Node('ArrayElementList', kind='SyntaxCollection',
|
||||
element='ArrayElement'),
|
||||
|
||||
@@ -131,6 +134,13 @@ EXPR_NODES = [
|
||||
Child('RightParen', kind='RightParenToken'),
|
||||
]),
|
||||
|
||||
Node('TupleExpr', kind='Expr',
|
||||
children=[
|
||||
Child('LeftParen', kind='LeftParenToken'),
|
||||
Child('ElementList', kind='TupleElementList'),
|
||||
Child('RightParen', kind='RightParenToken'),
|
||||
]),
|
||||
|
||||
# Array literal, e.g. [1, 2, 3]
|
||||
Node('ArrayExpr', kind='Expr',
|
||||
children=[
|
||||
@@ -159,6 +169,18 @@ EXPR_NODES = [
|
||||
is_optional=True),
|
||||
]),
|
||||
|
||||
# An element inside a tuple element list
|
||||
Node('TupleElement', kind='Syntax',
|
||||
children=[
|
||||
Child('Label', kind='IdentifierToken',
|
||||
is_optional=True),
|
||||
Child('Colon', kind='ColonToken',
|
||||
is_optional=True),
|
||||
Child('Expression', kind='Expr'),
|
||||
Child('TrailingComma', kind='CommaToken',
|
||||
is_optional=True),
|
||||
]),
|
||||
|
||||
# element inside an array expression: expression ','?
|
||||
Node('ArrayElement', kind='Syntax',
|
||||
children=[
|
||||
|
||||
Reference in New Issue
Block a user