Skip to content

Commit 3b307b7

Browse files
committed
[SyntaxBuilder] Add default conformance to syntax collection elements
1 parent 7f0130d commit 3b307b7

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

utils/gyb_syntax_support/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .StmtNodes import STMT_NODES # noqa: I201
1616
from .Trivia import TRIVIAS # noqa: I201
1717
from .TypeNodes import TYPE_NODES # noqa: I201
18+
from .kinds import syntax_buildable_child_type
1819

1920

2021
# Re-export global constants
@@ -179,3 +180,42 @@ def _digest_trivia(trivia):
179180
_digest_trivia(trivia)
180181

181182
return digest.hexdigest()
183+
184+
185+
def syntax_collection_element_to_collection_mapping():
186+
"""
187+
Generates a lookup table to find syntax collection type by syntax collection
188+
element type.
189+
190+
Example:
191+
{
192+
'SyntaxBuildable': [
193+
'StringLiteralSegments',
194+
'PrecedenceGroupAttributeList',
195+
'AttributeList',
196+
'SpecializeAttributeSpecList',
197+
'SwitchCaseList'
198+
],
199+
'IfConfigClause': [
200+
'IfConfigClauseList'
201+
],
202+
}
203+
"""
204+
collection_map = {}
205+
206+
for node in SYNTAX_NODES:
207+
if node.is_syntax_collection():
208+
syntax_collection_syntax_kind = node.syntax_kind
209+
210+
syntax_child_type = syntax_buildable_child_type(
211+
node.collection_element_type,
212+
node.collection_element,
213+
node.is_token())
214+
215+
if syntax_child_type not in collection_map:
216+
collection_map[syntax_child_type] = []
217+
218+
collection_map[syntax_child_type] \
219+
.append(syntax_collection_syntax_kind)
220+
221+
return collection_map
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES = {
2-
'ExpressibleAsConditionElement': [
3-
'ExpressibleAsConditionElementList'
2+
'DeclBuildable': [
3+
'CodeBlockItem',
4+
'MemberDeclListItem',
5+
'SyntaxBuildable'
46
],
5-
'ExpressibleAsDeclBuildable': [
6-
'ExpressibleAsCodeBlockItem',
7-
'ExpressibleAsMemberDeclListItem',
8-
'ExpressibleAsSyntaxBuildable'
7+
'StmtBuildable': [
8+
'CodeBlockItem',
9+
'SyntaxBuildable'
910
],
10-
'ExpressibleAsStmtBuildable': [
11-
'ExpressibleAsCodeBlockItem',
12-
'ExpressibleAsSyntaxBuildable'
13-
],
14-
'ExpressibleAsExprList': [
15-
'ExpressibleAsConditionElement',
16-
'ExpressibleAsSyntaxBuildable'
11+
'ExprList': [
12+
'ConditionElement',
13+
'SyntaxBuildable'
1714
]
1815
}

0 commit comments

Comments
 (0)