Skip to content

2014 06 25 YAML Logic

7rans edited this page Jun 28, 2014 · 5 revisions

Expressing Logical Relations in YAML

When designing YES, YAML Easy Schema, it became clear that the specification would have to support logical relationships. Now, that seems a rather tricky thing to try to express in YAML. And my first thought was that I'd have to resort to some level of string parsing, which did not sit well with me. I wanted the whole spec to be YAML all the way down.

Eventually I realized that it was in fact possible. The trick was to use special logical types: !and and !or. Then it is easy enough to create logical graphs.

example: !and
  - this
  - that
  - !or
    - these
    - those

In addition we can add a !not type.

example: !and
  - this
  - !not that

And that about wraps it up.

Has anyone else come across a need for this sort of thing? Any ideas for improvements? Any caveats I overlooked?

Clone this wiki locally