Skip to content

[SyntaxBuilder] Add default conformance to syntax collection elements #40120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions utils/gyb_syntax_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .StmtNodes import STMT_NODES # noqa: I201
from .Trivia import TRIVIAS # noqa: I201
from .TypeNodes import TYPE_NODES # noqa: I201
from .kinds import syntax_buildable_child_type


# Re-export global constants
Expand Down Expand Up @@ -179,3 +180,42 @@ def _digest_trivia(trivia):
_digest_trivia(trivia)

return digest.hexdigest()


def syntax_collection_element_to_collection_mapping():
"""
Generates a lookup table to find syntax collection type by syntax collection
element type.

Example:
{
'SyntaxBuildable': [
'StringLiteralSegments',
'PrecedenceGroupAttributeList',
'AttributeList',
'SpecializeAttributeSpecList',
'SwitchCaseList'
],
'IfConfigClause': [
'IfConfigClauseList'
],
}
"""
collection_map = {}

for node in SYNTAX_NODES:
if node.is_syntax_collection():
syntax_collection_syntax_kind = node.syntax_kind

syntax_child_type = syntax_buildable_child_type(
node.collection_element_type,
node.collection_element,
node.is_token())

if syntax_child_type not in collection_map:
collection_map[syntax_child_type] = []

collection_map[syntax_child_type] \
.append(syntax_collection_syntax_kind)

return collection_map
23 changes: 10 additions & 13 deletions utils/gyb_syntax_support/protocolsMap.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES = {
'ExpressibleAsConditionElement': [
'ExpressibleAsConditionElementList'
'DeclBuildable': [
'CodeBlockItem',
'MemberDeclListItem',
'SyntaxBuildable'
],
'ExpressibleAsDeclBuildable': [
'ExpressibleAsCodeBlockItem',
'ExpressibleAsMemberDeclListItem',
'ExpressibleAsSyntaxBuildable'
'StmtBuildable': [
'CodeBlockItem',
'SyntaxBuildable'
],
'ExpressibleAsStmtBuildable': [
'ExpressibleAsCodeBlockItem',
'ExpressibleAsSyntaxBuildable'
],
'ExpressibleAsExprList': [
'ExpressibleAsConditionElement',
'ExpressibleAsSyntaxBuildable'
'ExprList': [
'ConditionElement',
'SyntaxBuildable'
]
}