Objective
It would be great to have YAML Schema support based on the existing YAML IO parser.
Motivation
When I was working on one llvm-based tool, I had to work with input YAML files with a complex structure. Since all the code was written using YAMLTraits.h
and in different files, it is quite difficult to see the full structure of this file. In addition, it would be convenient for users of this tool, writing these input files, to see hints on the format of this file from their IDE. And if you make support for generating the schema from YAML parser, then you will not have to change its schema manually when changing the file structure. This can be useful to see the full structure of the input YAML file for different llvm based tools that use existing YAML parser, for example clang-format, clang-tidy e.t.c.
How It Works
Reading the current code in YAMLTraits.h
, I found 2 classes: one for Input YAML and another for Output. I thought that I could create another yaml::IO
derived class, with the same interface, so that I could simply dump the schema into some raw_ostream
. At the same time, this derived class has access to all keys and types of the current mapping.
How It’s Structured
I prepared a patch that adds this new derived class (I named it GenerateSchema
and moved it to a separate file so as not to increase compilation time in cases where this functionality is not required). Internally, this class does two things: first, it builds a tree of schemas for YAML chunks of thr input file. And then it builds a tree of nodes to output the schema to a file in YAML format, using the existing YAMLParser.
Testing
The unit test for this functionality is designed in such a way that it dumps the schema of some simple YAML and then compares it with a previously known
Dear llvm community, please give me your feedback.