imatix / gsl

iMatix GSL code generator
http://www.imatix.com
GNU General Public License v3.0
539 stars 107 forks source link

Switching between template/script modes #97

Closed saleyn closed 9 years ago

saleyn commented 9 years ago

It seems to me that it would be very useful to switch between template/script mode automatically depending on the use of function/macro keyword.

Presently the syntax forces you to write:

.template 0
function test1
  echo "test1"
endfunction

template 1
.macro test2
.  echo "test2"
.endmacro
endtemplate
.endtemplate

I propose to make a change so that the use of "macro" keyword in the script mode would automatically switch to template mode in the body of that macro (if not already in the template mode), and vice versa (use of "function" keyword would automatically switch to script mode in the body of the function if not already in the script mode):

.template 0
function test1  # already in script mode - not switching template mode
  echo "test1"
endfunction

macro test2     # in script mode - automatically switching to template mode
.  echo "test2"
endmacro        # returning back to script mode

endtemplate

I would've submitted a pull request as I thought this was a simple change, but frankly after looking at the source code for 20min, couldn't find a place where the template mode is being set when evaluating the function/macro. :(

evoskuil commented 9 years ago

+1

jschultz commented 9 years ago

This is already the case as far as I can tell.

With only one difference - the endmacro keyword has to be written .endmacro - otherwise it looks like a template.

Jonathan

On 11/05/15 06:44, Eric Voskuil wrote:

+1

— Reply to this email directly or view it on GitHub https://github.com/imatix/gsl/issues/97#issuecomment-100697830.

saleyn commented 9 years ago

You are right indeed. It's the '.' before endmacro that was throwing things off. Sorry for noise.