<commit_before>var SubtleSlickParse = (function(){
	function SubtleSlickParse(CSS3_Selectors){
		var selector = ''+CSS3_Selectors;
		if(!SubtleSlickParse.debug && cache[selector]) return cache[selector];
		parsedSelectors = [];
		parsedSelectors.type=[];
		
		while (selector != (selector = selector.replace(parseregexp, parser)));
		
		parsedSelectors.type=parsedSelectors.type.join('');
		return cache[''+CSS3_Selectors] = parsedSelectors;
	};
	var parseregexp = new RegExp("\
		(?x)\
		^(?:\
		\\s+$\
		|(?: \\s* (,)           \\s* ) # Combinator\n\
		|(?: \\s* (\\s|\\>|\\+|\\~) \\s* ) # Combinator\n\
		|(?:      ( \\* | \\w+ \\b   )     ) # Tag Name\n\
		|(?: \\#  ( [a-z][a-z0-9_-]* ) \\b ) # ID\n\
		|(?: \\.  ( [a-z][a-z0-9_-]* ) \\b ) # ClassName\n\
		|(?: \\[  ( ([-_:a-z0-9]+) (?: ([*^$!~|]?=) (?: \"([^\"]*)\" | '([^']*)' | ([^\\]]*) ) )?     ) \\] ) # attribute\n\
		|(?:   :+ ( [a-z][a-z0-9_-]* ) \\b (?: \\([\"]? ([^\\)\\\"]+) [\"]?\\) )?     ) # PseudoClassPseudoClassValue\n\
		)".replace(/\(\?x\)|\s+#.*$|\s+/gim,''),'i');
	var map = {
		// Natural replace function argument position
		rawMatch      : 0,
		offset        : -2,
		string        : -1,
		
		// Replace function argument position
		separator       : 1,
		combinator      : 2,
		combinatorChild : 2,
		
		tagName   : 3,
		id        : 4,
		className : 5,
		
		attribute            : 6,
		attributeKey         : 7,
		attributeOperator    : 8,
		attributeValueDouble : 9,
		attributeValueSingle : 10,
		attributeValue       : 11,
		
		pseudoClass      : 12,
		pseudoClassValue : 13
	};
	var cache = {};
	SubtleSlickParse.cache = cache;
	var parsedSelectors;
	var these_simpleSelectors;
	var this_simpleSelector;
	function parser(){
		var a = arguments;
		SubtleSlickParse.debug && console.log({
			argumentsLength : a.length,
			rawMatch        : a[map.rawMatch],
			offset          : a[arguments.length-2],
			string          : a[arguments.length-1],
			
			separator       : a[map.separator],
			combinator      : a[map.combinator],
			combinatorChild : a[map.combinatorChild],
			
			tagName   : a[map.tagName],
			id        : a[map.id],
			className : a[map.className],
			
			attribute         : a[map.attribute],
			attributeKey      : a[map.attributeKey],
			attributeOperator : a[map.attributeOperator],
			attributeValue    : a[map.attributeValue] || a[map.attributeValueDouble] || a[map.attributeValueSingle],
			
			pseudoClass      : a[map.pseudoClass],
			pseudoClassValue : a[map.pseudoClassValue]
		});
		
		if (!parsedSelectors.length || a[map.separator]) {
			// Make a new selector!
			parsedSelectors.push([]);
			these_simpleSelectors = parsedSelectors[parsedSelectors.length-1];
			if (parsedSelectors.length-1) return '';
		}
		if (!these_simpleSelectors.length || a[map.combinatorChild] || a[map.combinator]) {
			// Make a new simple selector!
			these_simpleSelectors.push({
				bits:0,
				combinator: a[map.combinatorChild] || a[map.combinator],
				tag : null,
				id  : null,
				parsed:{
					pseudos    :[],
					classes    :[],
					attributes :[]
				}
			});
			this_simpleSelector = these_simpleSelectors[these_simpleSelectors.length-1];
			parsedSelectors.type.push(this_simpleSelector.combinator);
			if (these_simpleSelectors.length-1) return '';
		}
		this_simpleSelector.bits ++;
		if (a[map.tagName    ]) return parsedSelectors.type.push('tag')    && (this_simpleSelector.tag = a[map.tagName])&&'';
		if (a[map.id         ]) return parsedSelectors.type.push('id')     && (this_simpleSelector.id  = a[map.id     ])&&'';
		if (a[map.className  ]) return parsedSelectors.type.push('class')  && this_simpleSelector.parsed.classes.push(a[map.className])&&'';
		if (a[map.attribute  ]) return parsedSelectors.type.push('attrib'+a[map.attributeOperator]) && this_simpleSelector.parsed.attributes.push({
			name     : a[map.attributeKey],
			operator : a[map.attributeOperator],
			value    : a[map.attributeValue] || a[map.attributeValueDouble] || a[map.attributeValueSingle]
		})&&'';
		if (a[map.pseudoClass]) return parsedSelectors.type.push('pseudo') && this_simpleSelector.parsed.pseudos.push({
			name     : a[map.pseudoClass],
			argument : a[map.pseudoClassValue]
		})&&'';
		
		return '';
	};
	
	return SubtleSlickParse;
})();


var slick = (function(){
	
	// MAIN Method: searches a context for an expression.
	
	function slick(context, expression){
		var buffer = {}, parsed = slick.parse(expression);
		var all, uid;
		
		// WIP ATTEMPT TO SPEEDUP
		
		// if (parsed.length == 1 && parsed[0].length == 1){
		// 	var bit = parsed[0][0];
		// 	var comBit = combinators[bit.combinator || ' '];
		// 	var selBit = parseBit(bit);
		// 	var founBit = [];
		// 	comBit(founBit, context, selBit, buffer);
		// 	return founBit;
		// }
		
		for (var i = 0; i < parsed.length; i++){
			
			var currentSelector = parsed[i], items;
			
			for (var j = 0; j < currentSelector.length; j++){
				var currentBit = currentSelector[j], combinator = combinators[currentBit.combinator || ' '];
				var selector = parseBit(currentBit), found = {};
				
				if (j == 0){
					combinator(found, context, selector, buffer);
				} else {
					for (uid in items) combinator(found, items[uid], selector, buffer);
				}
				
				items = found;
			}
			
			if (i == 0){
				all = items;
			} else {
				for (uid in items) all[uid] = items[uid];
			}
		}
		
		var nodes = [], idx = 0;
		for (uid in all) nodes[idx++] = all[uid];
		return nodes;
	};
	
	function parseBit(bit){
		return {
			tag: bit.tag || '*',
			id: bit.id,
			classes: bit.parsed.classes,
			attributes: bit.parsed.attributes,
			pseudos: bit.parsed.pseudos
		};
	};
	
	// pseudoselectors accessors
	
	slick.addPseudoSelector = function(name, fn){
		pseudos[name] = fn;
	};
	
	slick.getPseudoSelector = function(name){
		return pseudos[name];
	};
	
	// default getAttribute
	<commit_msg>updated slick4 with the slick5 parser<commit_after>var SubtleSlickParse = (function(){
	function SubtleSlickParse(CSS3_Selectors){
		var selector = ''+CSS3_Selectors;
		if(!SubtleSlickParse.debug && cache[selector]) return cache[selector];
		parsedSelectors = [];
		parsedSelectors.type=[];
		
		while (selector != (selector = selector.replace(parseregexp, parser)));
		
		// parsedSelectors.type=parsedSelectors.type.join('');
		return cache[''+CSS3_Selectors] = parsedSelectors;
	};
	var parseregexp = new RegExp("\
		(?x)\
		^(?:\
		\\s+$\
		|(?: \\s* (,)           \\s* ) # Combinator\n\
		|(?: \\s* (\\s|\\>|\\+|\\~) \\s* ) # Combinator\n\
		|(?:      ( \\* | \\w+ \\b   )     ) # Tag Name\n\
		|(?: \\#  ( [a-z][a-z0-9_-]* ) \\b ) # ID\n\
		|(?: \\.  ( [a-z][a-z0-9_-]* ) \\b ) # ClassName\n\
		|(?: \\[  ( ([-_:a-z0-9]+) (?: ([*^$!~|]?=) (?: \"([^\"]*)\" | '([^']*)' | ([^\\]]*) ) )?     ) \\] ) # attribute\n\
		|(?:   :+ ( [a-z][a-z0-9_-]* ) \\b (?: \\([\"]? ([^\\)\\\"]+) [\"]?\\) )?     ) # PseudoClassPseudoClassValue\n\
		)".replace(/\(\?x\)|\s+#.*$|\s+/gim,''),'i');
	var map = {
		// Natural replace function argument position
		rawMatch      : 0,
		offset        : -2,
		string        : -1,
		
		// Replace function argument position
		separator       : 1,
		combinator      : 2,
		
		tagName   : 3,
		id        : 4,
		className : 5,
		
		attribute            : 6,
		attributeKey         : 7,
		attributeOperator    : 8,
		attributeValueDouble : 9,
		attributeValueSingle : 10,
		attributeValue       : 11,
		
		pseudoClass      : 12,
		pseudoClassValue : 13
	};
	var MAP = (function(){
		var obj = {};
		for (var property in map) {
			var value = map[property];
			if (value<1) continue;
			obj[value] = property;
		}
		return obj;
	})();
	var cache = {};
	SubtleSlickParse.cache = cache;
	var parsedSelectors;
	var these_simpleSelectors;
	var this_simpleSelector;
	function parser(){
		var a = arguments;
		var selectorBitMap;
		var selectorBitName;
		
		for (var aN=1; aN < a.length; aN++) {
			if (a[aN]!==undefined) {
				SubtleSlickParse.debug && console.log(a[aN]);
				selectorBitMap = aN;
				selectorBitName = MAP[selectorBitMap];
				break;
			}
		}
		
		SubtleSlickParse.debug && console.log((function(){
			var o = {};
			o[selectorBitName] = a[selectorBitMap];
			return o;
		})());
		
		if (!parsedSelectors.length || a[map.separator]) {
			// Make a new selector!
			parsedSelectors.push([]);
			these_simpleSelectors = parsedSelectors[parsedSelectors.length-1];
			if (parsedSelectors.length-1) return '';
		}
		
		if (!these_simpleSelectors.length || a[map.combinator]) {
			this_simpleSelector && (this_simpleSelector.reverseCombinator = a[map.combinator]);
			// Make a new simple selector!
			these_simpleSelectors.push({
				// bits:0,
				combinator: a[map.combinator],
				tag : '*'
				// id  : null,
				// pseudos    :[],
				// classes    :[],
				// attributes :[]
			});
			this_simpleSelector = these_simpleSelectors[these_simpleSelectors.length-1];
			parsedSelectors.type.push(this_simpleSelector.combinator);
			if (these_simpleSelectors.length-1) return '';
		}
		
		switch(selectorBitMap){
			
		case map.tagName:
			this_simpleSelector.tag = a[map.tagName];
			break;
			
		case map.id:
			this_simpleSelector.id  = a[map.id];
			break;
			
		case map.className:
			if(!this_simpleSelector.classes)
				this_simpleSelector.classes = []
			;
			this_simpleSelector.classes.push(a[map.className]);
			break;
			
		case map.attribute:
			if(!this_simpleSelector.attributes)
				this_simpleSelector.attributes = []
			;
			this_simpleSelector.attributes.push({
				name     : a[map.attributeKey],
				operator : a[map.attributeOperator],
				value    : a[map.attributeValue] || a[map.attributeValueDouble] || a[map.attributeValueSingle]
			});
			break;
			
		case map.pseudoClass:
			if(!this_simpleSelector.pseudos)
				this_simpleSelector.pseudos = []
			;
			this_simpleSelector.pseudos.push({
				name     : a[map.pseudoClass],
				argument : a[map.pseudoClassValue]
			});
			break;
		}
		
		parsedSelectors.type.push(selectorBitName + (a[map.attributeOperator]||''));
		return '';
	};
	
	return SubtleSlickParse;
})();


var slick = (function(){
	
	// MAIN Method: searches a context for an expression.
	
	function slick(context, expression){
		var buffer = {}, parsed = slick.parse(expression);
		var all, uid;
		
		// WIP ATTEMPT TO SPEEDUP
		
		// if (parsed.length == 1 && parsed[0].length == 1){
		// 	var bit = parsed[0][0];
		// 	var comBit = combinators[bit.combinator || ' '];
		// 	var selBit = parseBit(bit);
		// 	var founBit = [];
		// 	comBit(founBit, context, selBit, buffer);
		// 	return founBit;
		// }
		
		for (var i = 0; i < parsed.length; i++){
			
			var currentSelector = parsed[i], items;
			
			for (var j = 0; j < currentSelector.length; j++){
				var currentBit = currentSelector[j], combinator = combinators[currentBit.combinator || ' '];
				var selector = parseBit(currentBit), found = {};
				
				if (j == 0){
					combinator(found, context, selector, buffer);
				} else {
					for (uid in items) combinator(found, items[uid], selector, buffer);
				}
				
				items = found;
			}
			
			if (i == 0){
				all = items;
			} else {
				for (uid in items) all[uid] = items[uid];
			}
		}
		
		var nodes = [], idx = 0;
		for (uid in all) nodes[idx++] = all[uid];
		return nodes;
	};
	
	function parseBit(bit){
		return {
			tag: bit.tag || '*',
			id: bit.id,
			classes: bit.classes||[],
			attributes: bit.attributes||[],
			pseudos: bit.pseudos||[]
		};
	};
	
	// pseudoselectors accessors
	
	slick.addPseudoSelector = function(name, fn){
		pseudos[name] = fn;
	};
	
	slick.getPseudoSelector = function(name){
		return pseudos[name];
	};
	
	// default getAttribute
	
{'fraction_non_alphanumeric': 0.18029819874170472, 'fraction_numerical': 0.008532276135482204, 'mean_word_length': 2.7909180006533814, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4492300', 'n_tokens_mistral': 4846, 'n_tokens_neox': 4053, 'n_words': 764}