I'm working on swig.js to make it work with Django more friendly,I can understand most of the codes but the parse.js,I wonder what the 'filterApplyIdx' exactly means.Is there anybody else working on this too?
I'm working on swig.js to make it work with Django more friendly,I can understand most of the codes but the parse.js,I wonder what the 'filterApplyIdx' exactly means.Is there anybody else working on this too?
As I posted to the mailing list
filterApplyIdx
is an array of indices on theout
(output) array at which filters will be applied. When the parser finds a filter it will apply it to theout
array at the index of the last value infilterApplyIdx
.For example: if the
out
array has the following['(', 'my_var']
, thefilterApplyIdx
should be[0, 1]
. (it will apply first tomy_var
, and second to everything that is encompassed by the opening parenthesis, once the closing parenthesis is found). So, if the next item parsed is a filter, it will pop thefilterApplyIdx
last value, which is1
, and look at theout
array, and apply the filter to the token atout[1]
.If, however, the
out
array was something more complex, like:['my_func(', 'foo', 'bar']
(note that the closing parenthesis formy_func
has not been found yet), thefilterApplyIdx
will be:[0, 2]
. We've removed1
now because the chance to apply a filter tofoo
has passed, since a new variable,bar
was found.