Bug 14917 - Syntax error when using dicts in ${@...}
Summary: Syntax error when using dicts in ${@...}
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium normal
Target Milestone: 4.99
Assignee: Mark
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2022-09-26 10:05 UTC by Enrico Scholz
Modified: 2022-11-10 15:32 UTC (History)
3 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enrico Scholz 2022-09-26 10:05:19 UTC
```
LICENSE = "CLOSED"

IDX = "green"
VAL = "${@{ 'green': 1, 'blue': 2 }[d.getVar('IDX')]}"
```

fails to expand with

```
expansion of VAL threw ExpansionError: Failure expanding variable VAL, expression was ${@{ 'green': 1, 'blue': 2 }[d.getVar('IDX')]} which triggered exception SyntaxError: '{' was never closed (Var <VAL>, line 1)
```


A workaround could be something like

```
VAL = "${@dict((lambda x: zip(x,x))(iter([ \
    'green', 1, \
    'blue',  2, \
    ])))[d.getVar('IDX')]}"
```

but it is non trivial, difficulty to understand and error prone.
Comment 1 Mark 2022-11-03 00:47:24 UTC
The regex in use will not handle nested curly brackets, the first close curly it sees will end the match, even if it passes over an open curly along the way. It should be possible to ignore a single set of nested curly brackets so I will see if I can derive something that will do the trick. Attempting to have multiple levels of nesting would involve moving to something else, like pyparsing, so we will leave that to a later exercise, should a usecase pop up for it.
Comment 2 Mark 2022-11-10 15:32:37 UTC
Fixed by commit 94e49b9b9e409c29eb04603b1305d96ebe661a4b [data_smart: allow python snippets to include a dictionary]. Enrico please feel free to try it out and raise any issues.