From: Steve H. <sh...@zi...> - 2002-08-26 12:46:19
|
Rolf wrote: > Have you though about how operators can be expressed ? I'm thinking > about OR, for example. Lets say we have a schema where some key can > be either a scalar or a map, and if it is a map you want to specify its > structure. And directives, such as 'if' ? > Well, I thought a little bit about the OR scenario. Basically I would use a sequence to provide a list of alternative types. name: Name type: - type: map items: - name: firstname type: scalar - name: lastname type: scalar - type: scalar Pretty ugly, huh? This would validate either of these documents: Name: Rolf Veen --- Name: firstname: clark lastname: evans > A different thing is that if we finally have an event tree representing > the schema, then we can build a validating parser even with the push > parser, at least in Java. Code could be something like: > > YamlSchema schema = new YamlSchema("schema.yml"); > > try { > Object graph = Yaml.load("aFile.yml", schema); > } > catch ( SyntaxException e) { ... } > catch ( SchemaException e) { ... } > > The exceptions abort the parsing process. > Sure, that makes sense to me. As new events get pushed, you adjust where you are in the schema to do the validation. With the pull way, it's the opposite--you basically walk the schema, deciding what kind of data you expect, and then you pull a bit of data from the YAML document and verify that it really conforms. When you start supporting multiple types, as in my example above, things will get a little tricky under either architecture. Cheers, Steve |