nl_tokens: ( Toy CSS parser . The goals here are : 1 ) expansive test coverage without the weight of a full CSS parser . 2 ) Avoiding regex wherever convenient . Quick tests : http : // jsfiddle . net / gtntL4gr / 3 / Returns an array of arrays . )
pl_tokens: function parseComponentValues ( str ) { var chrctr ; var component = "" ; var componentArray = [ ] ; var listArray = [ ] ; var parenDepth = 0 ; var pos = 0 ; var inComment = false ; function pushComponent ( ) { if ( component ) { componentArray . push ( component ) ; component = "" ; } } function pushComponentArray ( ) { if ( componentArray [ 0 ] ) { listArray . push ( componentArray ) ; componentArray = [ ] ; } } // (Loop forwards from the beginning of the string.) while ( true ) { chrctr = str . charAt ( pos ) ; if ( chrctr === "" ) { // ( End of string reached.) pushComponent ( ) ; pushComponentArray ( ) ; return listArray ; } else if ( inComment ) { if ( ( chrctr === "*" ) && ( str [ pos + 1 ] === "/" ) ) { // (At end of a comment.) inComment = false ; <mask> += 2 ; pushComponent ( ) ; continue ; } else { pos += 1 ; // (Skip all characters inside comments.) continue ; } } else if ( isSpace ( chrctr ) ) { // (If previous character in loop was also a space, or if // at the beginning of the string, do not add space char to // component.) if ( ( str . charAt ( pos - 1 ) && isSpace ( str . charAt ( pos - 1 ) ) ) || ! component ) { pos += 1 ; continue ; } else if ( parenDepth === 0 ) { pushComponent ( ) ; pos += 1 ; continue ; } else { // (Replace any space character with a plain space for legibility.) chrctr = " " ; } } else if ( chrctr === "(" ) { parenDepth += 1 ; } else if ( chrctr === ")" ) { parenDepth -= 1 ; } else if ( chrctr === "," ) { pushComponent ( ) ; pushComponentArray ( ) ; pos += 1 ; continue ; } else if ( ( chrctr === "/" ) && ( str . charAt ( pos + 1 ) === "*" ) ) { inComment = true ; pos += 2 ; continue ; } component = component + chrctr ; pos += 1 ; } }