|
12 | 12 | CallBlock, |
13 | 13 | CodeBlock, |
14 | 14 | ContributeTarget, |
| 15 | + ContributeValue, |
15 | 16 | DataBlock, |
16 | 17 | EmptyBlock, |
17 | 18 | ErrorBlock, |
@@ -82,6 +83,8 @@ def block_to_dict(block: pdl_ast.BlockType, json_compatible: bool) -> DumpedBloc |
82 | 83 | d["kind"] = str(block.kind) |
83 | 84 | if block.description is not None: |
84 | 85 | d["description"] = block.description |
| 86 | + if block.role is not None: |
| 87 | + d["role"] = block.role |
85 | 88 | if block.spec is not None: |
86 | 89 | d["spec"] = block.spec |
87 | 90 | if block.defs is not None: |
@@ -205,7 +208,7 @@ def block_to_dict(block: pdl_ast.BlockType, json_compatible: bool) -> DumpedBloc |
205 | 208 | if block.assign is not None: |
206 | 209 | d["def"] = block.assign |
207 | 210 | if set(block.contribute) != {ContributeTarget.RESULT, ContributeTarget.CONTEXT}: |
208 | | - d["contribute"] = block.contribute |
| 211 | + d["contribute"] = contribute_to_list(block.contribute) |
209 | 212 | if block.result is not None: |
210 | 213 | if isinstance(block.result, FunctionBlock): |
211 | 214 | d["result"] = "" |
@@ -266,6 +269,18 @@ def location_to_dict(location: LocationType) -> dict[str, Any]: |
266 | 269 | return {"path": location.path, "file": location.file, "table": location.table} |
267 | 270 |
|
268 | 271 |
|
| 272 | +def contribute_to_list( |
| 273 | + contribute: Sequence[ContributeTarget | dict[str, ContributeValue]] |
| 274 | +) -> list[str | dict[str, Any]]: |
| 275 | + acc: list[str | dict[str, Any]] = [] |
| 276 | + for contrib in contribute: |
| 277 | + if isinstance(contrib, str): |
| 278 | + acc.append(str(contrib)) |
| 279 | + elif isinstance(contrib, dict): |
| 280 | + acc.append({str(k): v.model_dump() for k, v in contrib.items()}) |
| 281 | + return acc |
| 282 | + |
| 283 | + |
269 | 284 | # def scope_to_dict(scope: ScopeType) -> dict[str, Any]: |
270 | 285 | # d = {} |
271 | 286 | # for x, v in scope.items(): |
|
0 commit comments