Build input itemset closure
481909
def _build_item_closure(itemset, productionset):
    
    #For every item inside current itemset, if we have the following rule:
    #  xxx <cursor><nonterminalSymbol> xxx  append every rule from self._productionruleset that begins with that NonTerminalSymbol
    if not isinstance(itemset, LR0ItemSet):
        raise TypeError
    import copy
    resultset = copy.copy(itemset)
    changed = True
    while changed:
        changed = False
        for currentitem in resultset.itemlist:
            nextsymbol = currentitem.next_symbol()
            if nextsymbol is None:
                break
            for rule in productionset.productions:
                newitem = LR0Item(rule)
                if rule.leftside[0] == nextsymbol and newitem not in resultset.itemlist:
                    resultset.append_item(newitem)
                    changed = True
    return resultset
360196
function (collection, elements, settings, index, oldIndex, newIndex) {
            var toReplace = new RegExp(pregQuote(settings.name_prefix + '[' + oldIndex + ']'), 'g');
            var replaceWith = settings.name_prefix + '[' + newIndex + ']';

            if (settings.children) {
                $.each(settings.children, function (key, child) {
                    var childCollection = collection.find(child.selector).eq(index);
                    var childSettings = childCollection.data('collection-settings');
                    if (childSettings) {
                        childSettings.name_prefix = childSettings.name_prefix.replace(toReplace, replaceWith);
                        childCollection.data('collection-settings', childSettings);
                    }
                });
            }

            replaceAttrData(elements, index, toReplace, replaceWith);

            toReplace = new RegExp(pregQuote(collection.attr('id') + '_' + oldIndex), 'g');
            replaceWith = collection.attr('id') + '_' + newIndex;

            if (settings.children) {
                $.each(settings.children, function (key, child) {
                    var childCollection = collection.find(child.selector).eq(index);
                    var childSettings = childCollection.data('collection-settings');
                    if (childSettings) {
                        childSettings.elements_parent_selector = childSettings.elements_parent_selector.replace(toReplace, replaceWith);
                        childSettings.elements_selector = childSettings.elements_selector.replace(toReplace, replaceWith);
                        childSettings.prefix = childSettings.prefix.replace(toReplace, replaceWith);
                        childCollection.data('collection-settings', childSettings);
                    }
                });
            }

            replaceAttrData(elements, index, toReplace, replaceWith);
        }
594299
function(){
            var self = this,
                item0 = new DataTypes.Item(self.productions[0], 0, [self.EOF]),  //S' -> S #dotPos=0
                itemSet0 = new DataTypes.ItemSet();

            itemSet0.push(item0);

            var firstItemSet = self._closureItemSet(itemSet0),
                itemSets = this.itemSets = [],
                itemSetsHash = {},      //这个hash是为了判断项集是否已存在(在closure扩展项集之前生成key来判断)
                itemSet,
                formState,
                curIdx,
                dotSymbolHash;         //这个hash是为了基于当前项集 和 各子项的dotSymbol进行goto运算时，避免已经goto运算过的dotSymbol再次运算

            //为什么是itemSet0.key() 不是firstItemSet.key()
            //因为要用仅包含内核项的项集做KEY，下次GOTO运算的结果项集在未CLOSURE运算前，
            //就能判断是否已经存在于项集族中，如果已存在，就直接拿到ID，否则进行CLOSURE运算增加到项集族中
            //避免没必要的CLOSURE计算
            itemSetsHash[itemSet0.key()] = 0;       

            itemSets.push(firstItemSet);

            curIdx=0;

            while(curIdx !== itemSets.length){   //C0 

                itemSet = itemSets[curIdx];
                curIdx++;

                dotSymbolHash = {};

                _.each(itemSet.subItems, function(item){

                    if(item.dotSymbol && !dotSymbolHash[item.dotSymbol]){

                        dotSymbolHash[item.dotSymbol] = true;
                        var gotoItemSet = self._gotoItemSet(itemSet, item.dotSymbol);

                        if(itemSetsHash[gotoItemSet.key()]){
                            itemSet.gotos[item.dotSymbol] = itemSetsHash[gotoItemSet.key()];
                            self.gotoItemSetRepeatCount = self.gotoItemSetRepeatCount || 0;
                            self.gotoItemSetRepeatCount += 1;
                        }else{
                            itemSetsHash[gotoItemSet.key()] = itemSets.length;
                            if (gotoItemSet.subItems.length){
                                gotoItemSet = self._closureItemSet(gotoItemSet);
                            }
                            //原itemSet通过该dotSymbol，转换到的新itemSet的序号
                            itemSet.gotos[item.dotSymbol] = itemSets.length;
                            itemSets.push(gotoItemSet);
                            console.log('generate lr state:' + itemSets.length);
                        }
                    }
                });

            }

            return itemSets;
        }
1230366
function forEachElement(elements, callback = () => {}) {
  const elementsType = Object.prototype.toString.call(elements);
  const isCollectionTyped = (elementsType === '[object Array]' ||
          (elementsType === '[object NodeList]') ||
          (elementsType === '[object HTMLCollection]') ||
          (typeof jQuery !== 'undefined' && elements instanceof jQuery) || // jquery
          (typeof Elements !== 'undefined' && elements instanceof Elements) // mootools
      );
  let i = 0;
  const j = elements.length;
  if (isCollectionTyped) {
    for (; i < j; i += 1) {
      callback(elements[i]);
    }
  } else {
    callback(elements);
  }
}
934798
def set_append(input_set, item):
    # type: (set, Any) -> set
    
    if item:
        if isinstance(item, (list, tuple)):
            input_set.update(item)
        else:
            input_set.add(item)
    return input_set
729894
function (collection, settings, isInitialization, event) {
            var elementsParent = $(settings.elements_parent_selector);
            var init = elementsParent.find('.' + settings.prefix + '-tmp').length === 0;
            var elements = collection.find(settings.elements_selector);

            // add a rescue button that will appear only if collection is emptied
            if (settings.allow_add) {
                if (init) {
                    elementsParent.append('<span class="' + settings.prefix + '-tmp"></span>');
                    if (settings.add) {
                        elementsParent.append(
                            $(settings.add)
                                .addClass(settings.prefix + '-action ' + settings.prefix + '-rescue-add')
                                .data('collection', collection.attr('id'))
                        );
                    }
                }
            }

            // initializes the collection with a minimal number of elements
            if (isInitialization) {
                collection.data('collection-offset', elements.length);

                var container = $(settings.container);
                var button = collection.find('.' + settings.prefix + '-add, .' + settings.prefix + '-rescue-add, .' + settings.prefix + '-duplicate').first();
                var secure = 0;
                while (elements.length < settings.init_with_n_elements) {
                    secure++;
                    var element = elements.length > 0 ? elements.last() : undefined;
                    var index = elements.length - 1;
                    elements = doAdd(container, button, collection, settings, elements, element, index, false);
                    if (secure > settings.init_with_n_elements) {
                        console.error('Infinite loop, element selector (' + settings.elements_selector + ') not found !');
                        break;
                    }
                }

                collection.data('collection-offset', elements.length);
            }

            // make buttons appear/disappear in each elements of the collection according to options
            // (enabled, min/max...) and logic (for example, do not put a move up button on the first
            // element of the collection)
            elements.each(function (index) {
                var element = $(this);

                if (isInitialization) {
                    element.data('index', index);
                }

                var actions = element.find('.' + settings.prefix + '-actions').addBack().filter('.' + settings.prefix + '-actions');
                if (actions.length === 0) {
                    actions = $('<' + settings.action_container_tag + ' class="' + settings.prefix + '-actions"></' + settings.action_container_tag + '>');

                    element.append(actions);
                }

                var delta = 0;
                if (event === 'remove' && settings.fade_out) {
                    delta = 1;
                }

                var buttons = [
                    {
                        'enabled': settings.allow_remove,
                        'selector': settings.prefix + '-remove',
                        'html': settings.remove,
                        'condition': elements.length - delta > settings.min
                    }, {
                        'enabled': settings.allow_up,
                        'selector': settings.prefix + '-up',
                        'html': settings.up,
                        'condition': elements.length - delta > 1 && elements.index(element) - delta > 0
                    }, {
                        'enabled': settings.allow_down,
                        'selector': settings.prefix + '-down',
                        'html': settings.down,
                        'condition': elements.length - delta > 1 && elements.index(element) !== elements.length - 1
                    }, {
                        'enabled': settings.allow_add && !settings.add_at_the_end && !settings.custom_add_location,
                        'selector': settings.prefix + '-add',
                        'html': settings.add,
                        'condition': elements.length - delta < settings.max
                    }, {
                        'enabled': settings.allow_duplicate,
                        'selector': settings.prefix + '-duplicate',
                        'html': settings.duplicate,
                        'condition': elements.length - delta < settings.max
                    }
                ];

                $.each(buttons, function (i, button) {
                    if (button.enabled) {
                        var action = element.find('.' + button.selector);
                        if (action.length === 0 && button.html) {
                            action = $(button.html)
                                .appendTo(actions)
                                .addClass(button.selector);
                        }
                        if (button.condition) {
                            action.removeClass(settings.prefix + '-action-disabled');
                            if (settings.hide_useless_buttons) {
                                action.css('display', '');
                            }
                        } else {
                            action.addClass(settings.prefix + '-action-disabled');
                            if (settings.hide_useless_buttons) {
                                action.css('display', 'none');
                            }
                        }
                        action
                            .addClass(settings.prefix + '-action')
                            .data('collection', collection.attr('id'))
                            .data('element', getOrCreateId(collection.attr('id') + '_' + index, element));
                    } else {
                        element.find('.' + button.selector).css('display', 'none');
                    }
                });

            }); // elements.each

            // make the rescue button appear / disappear according to options (add_at_the_end) and
            // logic (no more elements on the collection)
            if (settings.allow_add) {

                var delta = 0;
                if (event === 'remove' && settings.fade_out) {
                    delta = 1;
                }

                var rescueAdd = collection.find('.' + settings.prefix + '-rescue-add').css('display', '').removeClass(settings.prefix + '-action-disabled');
                var adds = collection.find('.' + settings.prefix + '-add');
                if (!settings.add_at_the_end && adds.length > delta || settings.custom_add_location) {
                    rescueAdd.css('display', 'none');
                } else if (event === 'remove' && settings.fade_out) {
                    rescueAdd.css('display', 'none');
                    rescueAdd.fadeIn('fast');
                }
                if (elements.length - delta >= settings.max) {
                    rescueAdd.addClass(settings.prefix + '-action-disabled');
                    if (settings.hide_useless_buttons) {
                        collection.find('.' + settings.prefix + '-add, .' + settings.prefix + '-rescue-add, .' + settings.prefix + '-duplicate').css('display', 'none');
                    }
                }
            }

        }
768248
function(callback)
    {
        var self = this, items = [];
        
        var append = function(err, item) {
            if (err)
            {
                return callback(err);
            }
            if (item)
            {
                items.push(item);
                self.next(append);
            }
            else
            {
                callback(null, items);
            }
        };
        
        this.next(append);
    }
619373
function(inst) {
		var onClose = this._get(inst, 'onClose');
		if (onClose)
			onClose.apply((inst.input ? inst.input[0] : null),
						  [(inst.input ? inst.input.val() : ''), inst]);
	}
1336537
function (items, options) {


            options = options || {};
            _.defaults(options, {silent: false, index: this.$items.length});

            var index = options.index;

            if (!_.isArray(items)) {
                items = [items];
            }
            var item, itemIndex;
            for (var i = 0; i < items.length; i++) {
                item = items[i];
                if (item instanceof Bindable) {
                    item.bind('change', this._onItemChange, this);
                    item.bind('*', this._onItemEvent, this);
                }
                itemIndex = index + i;
                if (_.isUndefined(this.$items[itemIndex]) || itemIndex >= this.$items.length) {
                    this.$items[itemIndex] = item;
                } else {
                    this.$items.splice(itemIndex, 0, item);
                }
                if (options.silent !== true) {
                    this.trigger('add', {item: item, index: itemIndex});
                }
            }
        }
1056302
function wrapSet(set){
    return function(context, value){
      set.call( context, value, context.data );
      return value;
    }
  }
433387
function makeSetter(setters, selector, view) {
  setters = parseSetters(setters, view);

  return setters.length < 1 ? undefined : function (model, value, data) {
    if (data && data.internal) return;

    const $el = this.$(selector);

    if ($el.length < 1) return;

    setters.forEach((fnc) => {
      fnc($el, value);
    });
  };
}
1364008
function(el,prop,val,ret,args,stopChange)
            {
              var e = new _changeEvent(el,prop,val,ret,args,undefined,'set',stopChange);

              if(el.__kb !== undefined)
              {
                var localAttrListeners = el.__kb._attrListeners,
                    localStyleListeners = el.__kb._styleListeners,
                    localParentAttrListeners = el.__kb._parentAttrListeners,
                    localParentStyleListeners = el.__kb._parentStyleListeners;

                if(localAttrListeners[prop] !== undefined)
                {
                  loopListener(localAttrListeners[prop],e);
                }

                if(e._stopPropogation === undefined && localStyleListeners[prop] !== undefined)
                {
                  loopListener(localStyleListeners[prop],e);
                }
                
                if(e._stopPropogation === undefined && localAttrListeners[_all] !== undefined)
                {
                  loopListener(localAttrListeners[_all],e);
                  if(e._stopPropogation === undefined)
                  {
                    loopListener(localStyleListeners[_all],e);
                  }
                }

                if(e._stopPropogation === undefined && localParentAttrListeners[prop] !== undefined)
                {
                  loopParentListener(localParentAttrListeners[prop],e);
                }

                if(e._stopPropogation === undefined && localParentStyleListeners[prop] !== undefined)
                {
                  loopParentListener(localParentStyleListeners[prop],e);
                }
                
                if(e._stopPropogation === undefined && localParentAttrListeners[_all] !== undefined)
                {
                  loopParentListener(localParentAttrListeners[_all],e);

                  if(e._stopPropogation === undefined)
                  {
                    loopParentListener(localParentStyleListeners[_all],e);
                  }
                }
              }

              if(e._stopPropogation === undefined && _attrListeners[prop] !== undefined)
              {
                loopListener(_attrListeners[prop],e);
              }

              if(e._stopPropogation === undefined && _styleListeners[prop] !== undefined)
              {
                loopListener(_styleListeners[prop],e);
              }
              
              if(e._stopPropogation === undefined && _attrListeners[_all] !== undefined)
              {
                loopListener(_attrListeners[_all],e);
                if(e._stopPropogation === undefined)
                {
                  loopListener(_styleListeners[_all],e);
                }
              }

              if(e._preventDefault !== undefined) return false;

              return true;
            }
1186522
function set(i, item, array)
{
	if (i < 0 || length(array) <= i)
	{
		return array;
	}
	return unsafeSet(i, item, array);
}
576764
function (container) {
        var matches = [], i, l, selectors = this._selectors;

        function collect(items, selector, index) {
          var i, l, fi, fl, item, filters = selector[index];

          for (i = 0, l = items.length; i < l; i++) {
            item = items[i];

            // Run each filter against the item
            for (fi = 0, fl = filters.length; fi < fl; fi++) {
              if (!filters[fi](item, i, l)) {
                fi = fl + 1;
                break;
              }
            }

            // All filters matched the item
            if (fi === fl) {
              // Matched item is on the last expression like: panel toolbar [button]
              if (index == selector.length - 1) {
                matches.push(item);
              } else {
                // Collect next expression type
                if (item.items) {
                  collect(item.items(), selector, index + 1);
                }
              }
            } else if (filters.direct) {
              return;
            }

            // Collect child items
            if (item.items) {
              collect(item.items(), selector, index);
            }
          }
        }

        if (container.items) {
          for (i = 0, l = selectors.length; i < l; i++) {
            collect(container.items(), selectors[i], 0);
          }

          // Unique the matches if needed
          if (l > 1) {
            matches = unique(matches);
          }
        }

        // Fix for circular reference
        if (!Collection) {
          // TODO: Fix me!
          Collection = Selector.Collection;
        }

        return new Collection(matches);
      }
1217965
function (item) {
            if($.isEmptyObject(item)){
              var tempObj={ id: $('input:first', el).val(), name: $('input:first', el).val()};
              return [tempObj];
            }else{
              return item;
            }
          }
68309
public static void appendInput(
      Appendable out,
      DependencyInfo info,
      String contents) throws IOException {
    new ClosureBundler().appendTo(out, info, contents);
  }
24615
function each(collection, fn, scope) {
  var i = 0,
    cont;

  for (i; i < collection.length; i++) {
    cont = fn.call(scope, collection[i], i);
    if (cont === false) {
      break; //allow early exit
    }
  }
}