sudoblockio / tackle

Tackle is a programmable configuration language for building modular utilities, code generators, and CLIs with schema validation baked in.
Apache License 2.0
51 stars 2 forks source link

Typed Macros #250

Open robcxyz opened 8 months ago

robcxyz commented 8 months ago

Typed Macros

Allow creation of macros from within tackle files

Overview


from typing import Callable

from tackle import Context

KEY_MACROS: list[Callable[[Context, str], dict]]

VALUE_MACROS: list[Callable[[Context, str], dict]]

Macro Types

Macros:

Order

Every key:

Key Macros

Compact Hook

key->: value

key:

  ->: value
Special Keys
return

return->: "{{value}}"

return:

  ->: "{{value}}"

return: # Key doesn't matter as value is the only data exported

  ->: return

  value: "{{value}}"

return->:

  "{{value}}": "{{key}}"

return:

  ->:

    "{{value}}": "{{key}}"

return:

  ->: return

  value:

    "{{value}}": "{{key}}"
import

import->: foo/bar

import:

  ->: foo/bar

import->:

  - foo/bar

  - foo/bar2

import:

  ->: import

  providers:

    - foo/bar
assert

assert->: foo==bar

assert:

  ->: foo==bar

assert->:

  - foo==bar

  - foo==bar2

assert:

  ->: assert

  skip_output: true

  providers:

    - foo==bar
merge

merge->:

  foo: bar

merge:

  ->: literal  

  ->: var

  merge: true

  input:

    foo: bar
Expand Keys

key:

  ->: value --a-key foo

key:

  ->: value

  a_key: foo
Block

key:

  ->:

    if: foo == 'bar'

    key: value  

key:

  ->: block

  if: foo == 'bar'

  key: value  

Note: Block hook maps unknown kwargs to items.

Macro could alternatively do this:


key:

  ->: block

  if: foo == 'bar'

  items:

    key: value  

Issues