File tree Expand file tree Collapse file tree 2 files changed +50
-13
lines changed Expand file tree Collapse file tree 2 files changed +50
-13
lines changed Original file line number Diff line number Diff line change 1515from .StmtNodes import STMT_NODES # noqa: I201
1616from .Trivia import TRIVIAS # noqa: I201
1717from .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
Original file line number Diff line number Diff line change 11SYNTAX_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}
You can’t perform that action at this time.
0 commit comments