| 23981 | // * "filter" which will help filter out values |
| 23982 | |
| 23983 | var arrayComprehension = function() { |
| 23984 | var CompArray = function() { |
| 23985 | this.mode = "use"; |
| 23986 | this.variables = []; |
| 23987 | }; |
| 23988 | var _carrays = []; |
| 23989 | var _current; |
| 23990 | function declare(v) { |
| 23991 | var l = _current.variables.filter(function(elt) { |
| 23992 | // if it has, change its undef state |
| 23993 | if (elt.value === v) { |
| 23994 | elt.undef = false; |
| 23995 | return v; |
| 23996 | } |
| 23997 | }).length; |
| 23998 | return l !== 0; |
| 23999 | } |
| 24000 | function use(v) { |
| 24001 | var l = _current.variables.filter(function(elt) { |
| 24002 | // and if it has been defined |
| 24003 | if (elt.value === v && !elt.undef) { |
| 24004 | if (elt.unused === true) { |
| 24005 | elt.unused = false; |
| 24006 | } |
| 24007 | return v; |
| 24008 | } |
| 24009 | }).length; |
| 24010 | // otherwise we warn about it |
| 24011 | return (l === 0); |
| 24012 | } |
| 24013 | return { stack: function() { |
| 24014 | _current = new CompArray(); |
| 24015 | _carrays.push(_current); |
| 24016 | }, |
| 24017 | unstack: function() { |
| 24018 | _current.variables.filter(function(v) { |
| 24019 | if (v.unused) |
| 24020 | warning("W098", v.token, v.raw_text || v.value); |
| 24021 | if (v.undef) |
| 24022 | state.funct["(scope)"].block.use(v.value, v.token); |
| 24023 | }); |
| 24024 | _carrays.splice(-1, 1); |
| 24025 | _current = _carrays[_carrays.length - 1]; |
| 24026 | }, |
| 24027 | setState: function(s) { |
| 24028 | if (_.contains(["use", "define", "generate", "filter"], s)) |
| 24029 | _current.mode = s; |
| 24030 | }, |
| 24031 | check: function(v) { |
| 24032 | if (!_current) { |
| 24033 | return; |
| 24034 | } |
| 24035 | // When we are in "use" state of the list comp, we enqueue that var |
| 24036 | if (_current && _current.mode === "use") { |
| 24037 | if (use(v)) { |
| 24038 | _current.variables.push({ |
| 24039 | funct: state.funct, |
| 24040 | token: state.tokens.curr, |