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:
Xi Ge
2017-11-27 16:33:48 -08:00
parent 36a08ec1bd
commit 036321546b
5 changed files with 42 additions and 4 deletions

View File

@@ -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=[