Tag Validation¶
In the validation phase, the parsed YAML tags are checked for conformance with the BLADE input schema. This includes checking that types in arrays and mappings meet expectations (for example only an array of !Enum tags is a valid value for the enum parameter on a !Field).
Note
This stage does not check for design “correctness”, i.e. an incorrect hookup could be specified for a missing port on a child block and this will not be detected in the validation phase. Only syntax errors such as using the wrong type for an attribute will be detected.
API¶
Unlike other stages, there is not a single API available for validation - instead each tag that inherits from TagBase carries a validate function which can be called to check syntactical correctness. Every tag generated by the parsing stage should have its validate routine called.
For nested tags (where a tag like !Enum is used as the value for the enum attribute of a !Field), the parent tag will call the validate routine of any children.
Example¶
For a file top_file.yaml:
- !Field
name: my_field
enum:
- !Enum
# Construct a Preprocessor instance and attach a scope, files, etc.
pre = Preprocessor()
...
# Pickup the top-level file from the scope and kick-off the validation
pre_top = pre.get_scope("main").get_file("top_file.yaml")
pre_top.evaluate()
# Parse the output buffer of the evaluation into a list of YAML tag objects
all_docs = parse_phhidle_file(pre_top.path, prefile=pre_top, buffer=pre_top.get_result())
# Iterate through the list of tag, calling 'validate' on each one
for doc in all_docs: doc.validate()