According to https://en.wikipedia.org/wiki/YAML#Repeated_nodes you can do the following in YAML
- step: &id001 # defines anchor label &id001
instrument: Lasik 2000
pulseEnergy: 5.4
pulseDuration: 12
repetition: 1000
spotSize: 1mm
- step: &id002
instrument: Lasik 2000
pulseEnergy: 5.0
pulseDuration: 10
repetition: 500
spotSize: 2mm
- step: *id001 # refers to the first step (with anchor &id001)
- step: *id002 # refers to the second step
- step: *id001
spotSize: 2mm # redefines just this key, refers rest from &id001
- step: *id002
Although when you try to override spotSize key of step with reference *id001 you get
yaml.parser.ParserError: while parsing a block mapping
in "C:\Users\...\test.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "C:\Users\...\test.yaml", line 29, column 5
The Wikipedia example is wrong; the parser is correct. You can only reference named nodes; not override values.
@petmakris I believe you want the following:
- step: &id001 # defines anchor label &id001
instrument: Lasik 2000
pulseEnergy: 5.4
pulseDuration: 12
repetition: 1000
spotSize: 1mm
- step: &id002
instrument: Lasik 2000
pulseEnergy: 5.0
pulseDuration: 10
repetition: 500
spotSize: 2mm
- step: *id001 # refers to the first step (with anchor &id001)
- step: *id002 # refers to the second step
- step:
<< : *id001
spotSize: 2mm # redefines just this key, refers rest from &id001
- step: *id002
thanks @DylanYoung :)
I think we can close this then.
@petmakris please reopen if necessary.
Most helpful comment
@petmakris I believe you want the following: