The YAML_ALIAS function creates a new YAML_Alias object, which can be used to hold an alias (reference) to a YAML anchor. YAML_Alias objects will automatically be returned from the YAML_PARSE function when the PRESERVE_ALIAS keyword is set.
Examples
Create a YAML_Value containing a scalar float value and anchor, and a YAML_Alias that references it:
yvalue = YAML_Value(1.234, ANCHOR='myanchor')
yalias = YAML_Alias('myanchor')
mymap = YAML_Map('key1', yvalue, 'key2', yalias)
print, yaml_serialize(mymap)
IDL prints:
key1: &myanchor 1.23400
key2: *myanchor
Now call YAML_PARSE with the PRESERVE_ALIAS keyword and examine the map keys:
yaml = [ $
'key1: &myanchor 1.23400', $
'key2: *myanchor']
yp = yaml_parse(yaml, /preserve_alias)
help, yp['key1'], yp['key2']
print, yp['key1'].value
IDL prints:
<Expression> YAML_VALUE <ID=5> VALUE='myanchor' VALUE='1.23400'
<Expression> YAML_ALIAS <ID=6> ALIAS='myanchor'
1.23400
Note: If YAML_PARSE is called without the PRESERVE_ALIAS keyword, then all anchors and aliases will be resolved and will not be returned.
Syntax
Result = YAML_Alias( [Alias] )
Return Value
Returns a reference to the newly-created YAML_Alias.
Arguments
Alias
Set this argument to a string giving the alias. Do not include the "*" in front of the alias; it will be added automatically when serializing to YAML.
Keywords
None
Properties
All properties can be set and retrieved using the dot "." operator.
ALIAS
Set this property to a string containing the YAML alias. Do not include the "*" in front of the alias; it will be added automatically when serializing to YAML. This alias must refer to an anchor somewhere else in the YAML stream. Conversely, when a YAML stream gets parsed with the PRESERVE_ALIAS keyword, if there is a YAML alias, then the resulting YAML_Alias will have the ALIAS property set. See the example above.
Variable Information
HELP
The HELP procedure provides general information:
yaml = [ $
'key1: &myanchor 1.23400', $
'key2: *myanchor']
yp = yaml_parse(yaml, /preserve_alias)
help, yp['key2']
IDL prints:
<Expression> YAML_ALIAS <ID=6> ALIAS='myanchor'
PRINT and Implied Print
The PRINT procedure and Implied Print serialize the output in YAML format:
IDL> yalias = YAML_Alias('myanchor')
IDL> print, yanchor
IDL> yanchor
In both cases IDL prints:
*myanchor
Version History
See Also
YAML_Value, YAML_PARSE, YAML_SERIALIZE