dist/axis3d.js
//process chunk of a string by finding out macros and replacing them
process chunk of a string by finding out macros and replacing them
process chunk of a string by finding out macros and replacing them
function process(str) {
		if (!str) return '';
		var arr = [];
		var chunk = str;
		var directive = /#[A-Za-z0-9_$]+/ig.exec(str);
		if (directive) {
			chunk = chunk.slice(0, directive.index);
			str = str.slice(directive.index);
		}
		chunk = escape(chunk, arr);
		chunk = chunk.replace(/\bdefined\s*([A-Za-z0-9_$]+)/g, 'defined($1)');
		for (var name in macros) {
			if (macros[name] instanceof Function) {
				chunk = processFunction(chunk, name, macros[name]);
			}
		}
		chunk = escape(chunk, arr);
		for (var name in macros) {
			if (!(macros[name] instanceof Function)) {
				chunk = processDefinition(chunk, name, macros[name]);
			}
		}
		chunk = unescape(chunk, arr);
		if (directive) {
			if (/^#def/.test(directive[0])) {
				str = define(str);
			} else if (/^#undef/.test(directive[0])) {
				str = undefine(str);
			} else if (/^#if/.test(directive[0])) {
				str = processIf(str);
			} else if (/^#line/.test(directive[0])) {
				var data = /#[A-Za-z0-9_]+\s*([-0-9]+)?[^\n]*/.exec(str);
				macros.__LINE__ = parseInt(data[1]);
				str = str.slice(data.index + data[0].length);
			} else if (/^#version/.test(directive[0])) {
				var data = /#[A-Za-z0-9_]+\s*([-0-9]+)?[^\n]*/.exec(str);
				macros.__VERSION__ = parseInt(data[1]);
				str = str.slice(data.index + data[0].length);
			} else {
				var directiveDecl = /\n/m.exec(str);
				chunk += str.slice(0, directiveDecl.index) + '\n';
				str = str.slice(directiveDecl.index);
			}
			return chunk + process(str);
		}
		return chunk;
	}
function process ( str ) { if ( ! str ) return '' ; var arr = [ ] ; var chunk = str ; var directive = / #[A-Za-z0-9_$]+ / ig . exec ( str ) ; if ( directive ) { chunk = chunk . slice ( 0 , directive . index ) ; str = str . slice ( directive . index ) ; } chunk = escape ( chunk , arr ) ; chunk = chunk . replace ( / \bdefined\s*([A-Za-z0-9_$]+) / g , 'defined($1)' ) ; for ( var name in macros ) { if ( macros [ name ] instanceof Function ) { chunk = processFunction ( chunk , name , macros [ name ] ) ; } } chunk = escape ( chunk , arr ) ; for ( var name in macros ) { if ( ! ( macros [ name ] instanceof Function ) ) { chunk = processDefinition ( chunk , name , macros [ name ] ) ; } } chunk = unescape ( chunk , arr ) ; if ( directive ) { if ( / ^#def / . test ( directive [ 0 ] ) ) { str = define ( str ) ; } else if ( / ^#undef / . test ( directive [ 0 ] ) ) { str = undefine ( str ) ; } else if ( / ^#if / . test ( directive [ 0 ] ) ) { str = processIf ( str ) ; } else if ( / ^#line / . test ( directive [ 0 ] ) ) { var data = / #[A-Za-z0-9_]+\s*([-0-9]+)?[^\n]* / . exec ( str ) ; macros . __LINE__ = parseInt ( data [ 1 ] ) ; str = str . slice ( data . index + data [ 0 ] . length ) ; } else if ( / ^#version / . test ( directive [ 0 ] ) ) { var data = / #[A-Za-z0-9_]+\s*([-0-9]+)?[^\n]* / . exec ( str ) ; macros . __VERSION__ = parseInt ( data [ 1 ] ) ; str = str . slice ( data . index + data [ 0 ] . length ) ; } else { var directiveDecl = / \n / m . exec ( str ) ; chunk += str . slice ( 0 , directiveDecl . index ) + '\n' ; str = str . slice ( directiveDecl . index ) ; } return chunk + process ( str ) ; } return chunk ; }
process chunk of a string by finding out macros and replacing them
process chunk of a string by finding out macros and replacing them
//find next directive, get chunk to process before it //get chunk to process - before next call //escape bad things //replace all defined X to defined (X) //for each registered macro do it’s call //fn macro //for each defined var do replacement //value replacement //process directive //drop directive line