mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
libSyntax: teach parser to parse dictionary and array literals. (#12821)
This commit also adds ArrayExpr and DictionaryExpr to the libSyntax nodes family. Also, it refactors the original parser code for these two expressions to better fit to the design of SyntaxParsingContext. This commit has also fixed two crashers.
This commit is contained in:
@@ -19,6 +19,12 @@ EXPR_NODES = [
|
||||
Node('FunctionCallArgumentList', kind='SyntaxCollection',
|
||||
element='FunctionCallArgument'),
|
||||
|
||||
Node('ArrayElementList', kind='SyntaxCollection',
|
||||
element='ArrayElement'),
|
||||
|
||||
Node('DictionaryElementList', kind='SyntaxCollection',
|
||||
element='DictionaryElement'),
|
||||
|
||||
# The try operator.
|
||||
# try foo()
|
||||
# try? foo()
|
||||
@@ -89,6 +95,22 @@ EXPR_NODES = [
|
||||
Child('RightParen', kind='RightParenToken'),
|
||||
]),
|
||||
|
||||
# Array literal, e.g. [1, 2, 3]
|
||||
Node('ArrayExpr', kind='Expr',
|
||||
children=[
|
||||
Child('LeftSquare', kind='LeftSquareToken'),
|
||||
Child('Elements', kind='ArrayElementList'),
|
||||
Child('RightSquare', kind='RightSquareToken'),
|
||||
]),
|
||||
|
||||
# Dictionary literal, e.g. [1:1, 2:2, 3:3]
|
||||
Node('DictionaryExpr', kind='Expr',
|
||||
children=[
|
||||
Child('LeftSquare', kind='LeftSquareToken'),
|
||||
Child('Elements', kind='DictionaryElementList'),
|
||||
Child('RightSquare', kind='RightSquareToken'),
|
||||
]),
|
||||
|
||||
# function-call-argument -> label? ':'? expression ','?
|
||||
Node('FunctionCallArgument', kind='Syntax',
|
||||
children=[
|
||||
@@ -101,6 +123,22 @@ EXPR_NODES = [
|
||||
is_optional=True),
|
||||
]),
|
||||
|
||||
# element inside an array expression: expression ','?
|
||||
Node('ArrayElement', kind='Syntax',
|
||||
children=[
|
||||
Child('Expression', kind='Expr'),
|
||||
Child('TrailingComma', kind='CommaToken', is_optional=True),
|
||||
]),
|
||||
|
||||
# element inside an array expression: expression ','?
|
||||
Node('DictionaryElement', kind='Syntax',
|
||||
children=[
|
||||
Child('KeyExpression', kind='Expr'),
|
||||
Child('Colon', kind='ColonToken'),
|
||||
Child('ValueExpression', kind='Expr'),
|
||||
Child('TrailingComma', kind='CommaToken', is_optional=True),
|
||||
]),
|
||||
|
||||
# An integer literal.
|
||||
# 3
|
||||
# +3_400
|
||||
|
||||
Reference in New Issue
Block a user