MommaWatasu / OteraEngine.jl

This package is a template engine for Julia Lang.
https://mommawatasu.github.io/OteraEngine.jl/stable
MIT License
20 stars 4 forks source link

Macros within comments are executed #23

Closed frankier closed 10 months ago

frankier commented 10 months ago

Thanks for the update! I think it is very close to working for my purposes, but I still have one more round of nits.

If I write something like the following:

#= {{ my_macro(...) }} =#

Then currently the macros will be expanded first, which will mean my_macro is executed. This could cause problems, e.g. if my_macro isn't defined or my_macro contains an infinite loop or some bad side-effect.

I guess possibly applying comments before macros would help.

P.S. You will probably not be able to implement nested comments without actually parsing into a tree, but these are a bit unusual. I thought I would just note this since Julia itself does support nested comments and I think that might be a point at which the "lex and rewrite" approach might break down.

MommaWatasu commented 10 months ago

Thanks for your report. I’ll fix this bug by removing comments before processing macros. Please wait for a while.

But, as you mentioned, parser which doesn't use syntax tree is not appropriate to make complex template engine. So, I will try implementing own parser which uses syntax tree(and then, I think I should release it as v1.0.0). This change must take a lot of time, but I believe it’s necessary to make OteraEngine.jl practical.

frankier commented 10 months ago

Okay sounds great! I guess the argument against is simplicity. As long as there is a good correspondence between the template language and Julia then lex+rewrite works just fine. On the other hand it could well be useful for some cases beyond nested comments like certain custom tags or something. Good luck either way.

MommaWatasu commented 10 months ago

Now, v0.4.1 is available. But please note that this patch slows down the speed.

frankier commented 10 months ago

Great!