microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
30 stars 5 forks source link

Implement `switch` expression in expression language, not YAML #90

Open johnstairs opened 11 months ago

johnstairs commented 11 months ago

Computed fields are currently an embedded expression language within a YAML file. switch expressions (to work with unions and optional types) are not expressed in this language, but rather as YAML nodes:

optionalNamedArrayLength: # YAML
  !switch optionalNamedArray: # YAML
    NamedNDArray arr: size(arr) # YAML-type-expression hybrid
    null: 0 # YAML-type-expression hybrid

This does not allow switch expressions to be used as part of larger expressions (type conversions, a function call argument, etc).

Instead, we should consider making switch part of the expression language. The example above might then look like:

optionalNamedArrayLength: |
  switch(optionalNamedArray) {
    NamedNDArray arr: size(arr)
    null: 0
  }

On the other hand, this syntax introduces curly braces within a YAML document, where indentation is usually favoured.