// CFML brush by Steven Levithan (based on the XML brush; incomplete)

dp.sh.Brushes.Cfml = function(){
	this.CssClass = 'dp-xml';
}

dp.sh.Brushes.Cfml.prototype	= new dp.sh.Highlighter();
dp.sh.Brushes.Cfml.Aliases		= ['cf', 'cfml'];

dp.sh.Brushes.Cfml.prototype.ProcessRegexList = function(){
	function push(array, value){
		array[array.length] = value;
	}
	
	var index	= 0;
	var match	= null;
	var regex	= null;
	
	// Match comments
	// <!--[\S\s]*?-->
	this.GetMatches(new RegExp('<!--[\\S\\s]*?-->', 'g'), 'comments');
	
	// Match attributes and their values (excluding those within cfset tags, which will get special handling later)
	// Since JavaScript doesn't support lookbehinds, the approach is convoluted
	// The position before "cfset" is escaped so this can run through a CF processor without throwing an error
	// (?:<\bcfset\s+[^>]+>)|([\w.]+)\s*=\s*(".*?"|'.*?'|[^\s>]+)
	regex = new RegExp('(?:<' + 'cfset\\s+[^>]+>)|([\\w.]+)\\s*=\\s*(".*?"|\'.*?\'|[^\\s>]+)', 'g');
	while((match = regex.exec(this.code)) != null){
		// if we matched a cfset tag, ignore it	
		if(match[1] != undefined){
			push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'attribute'));
			push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute-value'));
		}
	}
	
	// Match attributes and values of cfset tags
	// <\bcfset\s+[^=>]+=\s*(".*?"|'.*?')
	// The position before "cfset" is escaped so this can run through a CF processor without throwing an error
	regex = new RegExp('<' + 'cfset\\s+[^=>]+=\\s*(".*?"|\'.*?\')', 'g');
	while((match = regex.exec(this.code)) != null){
		push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'attribute-value'));
	}

	// Match opening and closing tag brackets
	// </*\?*(?!\!)|/*\?*>
	this.GetMatches(new RegExp('</*\\?*(?!\\!)|/*\\?*>', 'gm'), 'tag');

	// Match tag names
	// </*\?*\s*(\w+)
	regex = new RegExp('</*\\?*\\s*([:\\w-\.]+)', 'gm');
	while((match = regex.exec(this.code)) != null){
		push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag-name'));
	}
}

