What does filterApplyIdx mean in parse.js?

41 views Asked by At

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?

1

There are 1 answers

0
Paul Armstrong On BEST ANSWER

As I posted to the mailing list

filterApplyIdx is an array of indices on the out (output) array at which filters will be applied. When the parser finds a filter it will apply it to the out array at the index of the last value in filterApplyIdx.

For example: if the out array has the following ['(', 'my_var'], the filterApplyIdx should be [0, 1]. (it will apply first to my_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 the filterApplyIdx last value, which is 1, and look at the out array, and apply the filter to the token at out[1].

If, however, the out array was something more complex, like: ['my_func(', 'foo', 'bar'] (note that the closing parenthesis for my_func has not been found yet), the filterApplyIdx will be: [0, 2]. We've removed 1 now because the chance to apply a filter to foo has passed, since a new variable, bar was found.