Class JSUtilities.YAML.TagSpec

java.lang.Object
org.bzdev.util.JSUtilities.YAML.TagSpec
Enclosing class:
JSUtilities.YAML

public static class JSUtilities.YAML.TagSpec extends Object
YAML tag for additional data types. This class is used to configure how YAML will handle additional data types. When ExpressionParser is used, the recommended tag is tag:bzdev.org,2021:esp and a suitable prefix is !bzdev! so that the prefix and tag combination is equivalent to the YAML declaration
%TAG !bzdev! tag:bzdev.org,2021:
and the string will be processed by ExpressionParser when a value starts with the sequence !bzdev!esp For example
- expressionList: - !bzdev!esp >- ...
If the constructor explicitly provides the prefix, the %TAG directive is not needed. For example
ExpressionParser ep = new ExpressionParser(...); ObjectParser.SourceParser sp = new ObjectParser.SourceParser(ep); TagSpec ts = new TagSpec("!bzdev!", "tag:bzdev.org,2021:esp", sp);
will create an ObjectParser.SourceParser for an expression parser that will encapsulate the content so it can be evaluated at a later time (this occurs in the ObjectNamerLauncher class which for implementation reasons has to control the order of evaluation when anchors are used.
  • Constructor Details

    • TagSpec

      public TagSpec(String prefix, String tag, ObjectParser objectParser)
      Constructor. The prefix is a string, which should start with "!", that will be replaced with the tag up to an including its final colon. The tag is a YAML-tag URL that names a data type (for example, tag:yaml.org,2002:int). The object parser is an instance of ObjectParser that will parse a string and return the appropriate object.

      With multiple instances, one can provide the prefix for one and not bother for ones where the mapping to a tag will be the same. It can also be null if the prefix will be defined in a YAML "%TAG" directive.

      A prefix is a string that represents the portion of the tag up to its final colon, and should start and end with exclamation points: for example if the prefix is !bzdev! and the tag is tag:bzdev.org,2021:esp, then !bzdev! will represent "tag:bzdev.org,2021:", providing a terser notation. That in turn will indicate which object parser to use. If the prefix is null, it should be defined previously or in a %TAG directive at the start of a YAML file.

      Parameters:
      prefix - the prefix; null if not used for this entry
      tag - the tag
      objectParser - the object parser for this data type.