Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you expand macros in macro values? #13

Closed
daykin opened this issue Mar 3, 2020 · 1 comment
Closed

Can you expand macros in macro values? #13

daykin opened this issue Mar 3, 2020 · 1 comment

Comments

@daykin
Copy link

daykin commented Mar 3, 2020

Let's say I want to do something like this:

defmacro:
  name: foo
  args: [fooarg1, fooarg2, fooarg3]
  value:
      "{{fooarg1}}_{{fooarg2}}_{{fooarg3}}":
        - something: "cool"
          somethingelse: "neat"
---
defmacro:
  name: bar
  args: [arg1, arg2, newArg]
  value:
      "{{arg1}}_{{arg2}}":
        - thisistoplevel: "OK"
        - {foo: {fooarg1: {{arg1}}, fooarg2: {{arg2}}, fooarg3: nested}}
        
---
- { bar: {arg1: bogus, arg2: example}}
---
#Desired output:
#- bogus_example:
#  - thisistoplevel: OK
#  - bogus_example_nested:
#    - something: cool
#      somethingelse: neat

I get an error attempting this, presumably because it doesn't actually perform macro expansion in the nested invocation:

ERROR: /home/evan/git/alarm_rf/drawer.yaml
<class 'yaml.constructor.ConstructorError'>
while constructing a mapping
  in "/home/evan/git/alarm_rf/drawer.yaml", line 44, column 33
found unacceptable key (unhashable type: 'dict')
  in "/home/evan/git/alarm_rf/drawer.yaml", line 44, column 34

Is this possible? I see a blurb about 'nesting' here but maybe that's a different use case than what I'm imagining.

@birchb1024
Copy link
Owner

This input is not valid YAM!. You need some quotes.

Here's the fixed file below.

defmacro:
  name: foo
  args: [fooarg1, fooarg2, fooarg3]
  value:
      "{{fooarg1}}_{{fooarg2}}_{{fooarg3}}":
        - something: "cool"
          somethingelse: "neat"
---
defmacro:
  name: bar
  args: [arg1, arg2, newArg]
  value:
      "{{arg1}}_{{arg2}}":
        - thisistoplevel: "OK"
        - {foo: {fooarg1: "{{arg1}}", fooarg2: "{{arg2}}", fooarg3: nested}}
        
---
- { bar: {arg1: bogus, arg2: example, newArg: 1}}

Here's output

- bogus_example:
  - thisistoplevel: OK
  - bogus_example_nested:
    - something: cool
      somethingelse: neat

Please try the newest incarnation of this program here: goyamp It's faster and better :-) and runs the yamp code unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants