libSyntax: create syntax nodes for closure signature. (#13415)

This patch also refactors the structure of function signature node so
that closure signature can re-use parts of function signature. For
instance, we group arrow and return type to be "ReturnClause". And we
group parenthesized parameter list to be "ParamClause".

This structure of closure signature also calls for a good way to
represent either-or node in libSyntax APIs, since we've two ways to
specify parameters in closure: one is as regular function parameter and
the other is dot-separated simple names.
This commit is contained in:
Xi Ge
2017-12-13 16:48:24 -08:00
committed by GitHub
parent 079796eb90
commit 9ddd60d4ef
7 changed files with 126 additions and 68 deletions

View File

@@ -26,25 +26,32 @@ DECL_NODES = [
Node('FunctionParameterList', kind='SyntaxCollection',
element='FunctionParameter'),
# function-signature ->
# '(' parameter-list? ')' (throws | rethrows)? '->'? attributes? type?
Node('FunctionSignature', kind='Syntax',
Node('ParameterClause', kind='Syntax',
children=[
Child('LeftParen', kind='LeftParenToken'),
Child('ParameterList', kind='FunctionParameterList'),
Child('RightParen', kind='RightParenToken'),
]),
# -> Type
Node('ReturnClause', kind='Syntax',
children=[
Child('Arrow', kind='ArrowToken'),
Child('ReturnType', kind='Type'),
]),
# function-signature ->
# '(' parameter-list? ')' (throws | rethrows)? '->'? type?
Node('FunctionSignature', kind='Syntax',
children=[
Child('Input', kind='ParameterClause'),
Child('ThrowsOrRethrowsKeyword', kind='Token',
is_optional=True,
token_choices=[
'ThrowsToken',
'RethrowsToken',
]),
Child('Arrow', kind='ArrowToken',
is_optional=True),
Child('ReturnTypeAttributes', kind='AttributeList',
is_optional=True),
Child('ReturnType', kind='Type',
is_optional=True),
Child('Output', kind='ReturnClause', is_optional=True),
]),
# else-if-directive-clause -> '#elseif' expr stmt-list