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

Macro referenced before used issue #45

Open
abastyr opened this issue May 6, 2020 · 2 comments
Open

Macro referenced before used issue #45

abastyr opened this issue May 6, 2020 · 2 comments

Comments

@abastyr
Copy link

abastyr commented May 6, 2020

Airspeed throws an exception if the macro is referenced in the template before it is defined. This works normally in Apache Velocity.

Code example:

import airspeed

t = airspeed.Template("""
#set($value = 'my test')
${instancesuper}
#if(!$!{instancesuper})
missing end
#end
Value is '$value'
#new_macro('A','B')
#macro(new_macro $name $surname)
Your name is $name $surname
#end
Testing macro
#new_macro('A','B')"""
)


print(t.merge(locals()))

This throws a following exception:

raise Exception('no such macro: ' + self.macro_name)
airspeed.TemplateExecutionError: Error in template '<string>' at position 102-121 in expression: #new_macro('A','B')
Exception: no such macro: new_macro
@purcell
Copy link
Owner

purcell commented May 6, 2020

Hmm, I suspect the fix for this could be fiddly. I agree that compatibility would be good here, but I guess it would be fairly trivial to move the macro declaration earlier in the source code in this case.

@abastyr
Copy link
Author

abastyr commented May 7, 2020

Sort of. The problem is that the actual macro is massive and we put it in the back so it doesn't cover what the template really does. But I think I can write a piece of code that will put all the macros in front of the execution.

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