birchb1024 / yamp

Yet Another Macro Processor - for YAML - Superseded by Goyamp
GNU General Public License v3.0
13 stars 3 forks source link

range: over keys of a map? #10

Closed birchb1024 closed 5 years ago

birchb1024 commented 5 years ago

Like in goyamp, range would convert a map to a sequence of keys and return them, typically used in iterations. Here's an example, range: all produces a sequence from the map held in the all variable. (perf and prod). The macro then uses the loop variable item to select one of the map entries using dot notation all.item.

- defmacro:
    name: loopy
    args: all
    value:
       repeat:
         for: item
         in: { range: all }
         body:
           env: item
           host: all.item.host
---
loopy:
  perf:
    host: lp123123
    size: 190
  prod:
    host: lpp23423
    size: 324

This yields

- env: perf
  host: lp123123
- env: prod
  host: lpp23423