src/aria/templates/CSSParser.js
function (dictionary, throwErrors) {
            // Everyting starts on the first {
            var text = this.template, utilString = ariaUtilsString, currentPosition = 0, nextOpening = -1, nextClosing = -1, wholeText = [], nameExtractor = /^\{[\s\/]*?([\w]+)\b/, lastCopiedPosition = 0, textLength = text.length, statementLevel = -1, currentLevel = 0, lastOpenedLevel0 = -1;

            while (lastCopiedPosition < textLength) {
                // Update the pointers
                if (nextOpening < currentPosition) {
                    nextOpening = utilString.indexOfNotEscaped(text, "{", currentPosition);
                }
                if (nextClosing < currentPosition) {
                    nextClosing = utilString.indexOfNotEscaped(text, "}", currentPosition);
                }

                if (nextOpening > -1 && (nextClosing > nextOpening || nextClosing == -1)) {
                    // found a '{'
                    if (currentLevel === 0) {
                        lastOpenedLevel0 = nextOpening;
                    }
                    currentLevel++;
                    if (statementLevel == -1) {
                        // we are not inside a statement
                        if (text.charAt(nextOpening - 1) == "$") {
                            // we do not prefix in case we have ${...}
                            statementLevel = currentLevel;
                        } else {
                            var tag = text.substring(nextOpening, nextClosing);
                            var currentTagName = nameExtractor.exec(tag);
                            if (currentTagName && dictionary[currentTagName[1]]) {
                                // It's a statement, it shouldn't be escaped
                                // and we should skip everything inside this statement
                                statementLevel = currentLevel;
                            } else {
                                // add a prefix
                                wholeText.push(text.substring(lastCopiedPosition, nextOpening));
                                wholeText.push('\\{');
                                lastCopiedPosition = nextOpening + 1;
                            }
                        }
                    }
                    currentPosition = nextOpening + 1;
                } else if (nextClosing > -1) {
                    // found '}'
                    if (currentLevel === 0) {
                        // missing opening '{' corresponding to '}'
                        this._computeLineNumbers();
                        this.logOrThrowError(this.MISSING_OPENINGBRACES, [this.positionToLineNumber(nextClosing)], this.context, throwErrors);
                        return false;
                    }
                    if (statementLevel == currentLevel) {
                        statementLevel = -1; // no longer inside a statement
                    } else if (statementLevel == -1) {
                        // add the prefix for the closing }
                        wholeText.push(text.substring(lastCopiedPosition, nextClosing));
                        wholeText.push('\\}');
                        lastCopiedPosition = nextClosing + 1;
                    }
                    currentLevel--;
                    currentPosition = nextClosing + 1;
                } else {
                    this.$assert(94, nextOpening == -1 && nextClosing == -1);
                    // no more '{' or '}'
                    currentPosition = textLength;
                    wholeText.push(text.substring(lastCopiedPosition, textLength));
                    lastCopiedPosition = textLength;
                }
            }
            if (currentLevel > 0) {
                // missing opening '{' corresponding to '}'
                this._computeLineNumbers();
                this.logOrThrowError(this.MISSING_CLOSINGBRACES, [this.positionToLineNumber(lastOpenedLevel0)], this.context, throwErrors);
                return false;
            }
            this.template = wholeText.join("");
            return true;
        }
function (dictionary, throwErrors) {
            // Everyting starts on the first {
            var text = this.template, utilString = ariaUtilsString, currentPosition = 0, nextOpening = -1, nextClosing = -1, wholeText = [], nameExtractor = /^\{[\s\/]*?([\w]+)\b/, lastCopiedPosition = 0, textLength = text.length, statementLevel = -1, currentLevel = 0, lastOpenedLevel0 = -1;

            while (lastCopiedPosition < textLength) {
                // Update the pointers
                if (nextOpening < currentPosition) {
                    nextOpening = utilString.indexOfNotEscaped(text, "{", currentPosition);
                }
                if (nextClosing < currentPosition) {
                    nextClosing = utilString.indexOfNotEscaped(text, "}", currentPosition);
                }

                if (nextOpening > -1 && (nextClosing > nextOpening || nextClosing == -1)) {
                    // found a '{'
                    if (currentLevel === 0) {
                        lastOpenedLevel0 = nextOpening;
                    }
                    currentLevel++;
                    if (statementLevel == -1) {
                        // we are not inside a statement
                        if (text.charAt(nextOpening - 1) == "$") {
                            // we do not prefix in case we have ${...}
                            statementLevel = currentLevel;
                        } else {
                            var tag = text.substring(nextOpening, nextClosing);
                            var currentTagName = nameExtractor.exec(tag);
                            if (currentTagName && dictionary[currentTagName[1]]) {
                                // It's a statement, it shouldn't be escaped
                                // and we should skip everything inside this statement
                                statementLevel = currentLevel;
                            } else {
                                // add a prefix
                                wholeText.push(text.substring(lastCopiedPosition, nextOpening));
                                wholeText.push('\\{');
                                lastCopiedPosition = nextOpening + 1;
                            }
                        }
                    }
                    currentPosition = nextOpening + 1;
                } else if (nextClosing > -1) {
                    // found '}'
                    if (currentLevel === 0) {
                        // missing opening '{' corresponding to '}'
                        this._computeLineNumbers();
                        this.logOrThrowError(this.MISSING_OPENINGBRACES, [this.positionToLineNumber(nextClosing)], this.context, throwErrors);
                        return false;
                    }
                    if (statementLevel == currentLevel) {
                        statementLevel = -1; // no longer inside a statement
                    } else if (statementLevel == -1) {
                        // add the prefix for the closing }
                        wholeText.push(text.substring(lastCopiedPosition, nextClosing));
                        wholeText.push('\\}');
                        lastCopiedPosition = nextClosing + 1;
                    }
                    currentLevel--;
                    currentPosition = nextClosing + 1;
                } else {
                    this.$assert(94, nextOpening == -1 && nextClosing == -1);
                    // no more '{' or '}'
                    currentPosition = textLength;
                    wholeText.push(text.substring(lastCopiedPosition, textLength));
                    lastCopiedPosition = textLength;
                }
            }
            if (currentLevel > 0) {
                // missing opening '{' corresponding to '}'
                this._computeLineNumbers();
                this.logOrThrowError(this.MISSING_CLOSINGBRACES, [this.positionToLineNumber(lastOpenedLevel0)], this.context, throwErrors);
                return false;
            }
            this.template = wholeText.join("");
            return true;
        }
function ( dictionary , throwErrors ) { // Everyting starts on the first { var text = this . template , utilString = ariaUtilsString , currentPosition = 0 , nextOpening = - 1 , nextClosing = - 1 , wholeText = [ ] , nameExtractor = / ^\{[\s\/]*?([\w]+)\b / , lastCopiedPosition = 0 , textLength = text . length , statementLevel = - 1 , currentLevel = 0 , lastOpenedLevel0 = - 1 ; while ( lastCopiedPosition < textLength ) { // Update the pointers if ( nextOpening < currentPosition ) { nextOpening = utilString . indexOfNotEscaped ( text , "{" , currentPosition ) ; } if ( nextClosing < currentPosition ) { nextClosing = utilString . indexOfNotEscaped ( text , "}" , currentPosition ) ; } if ( nextOpening > - 1 && ( nextClosing > nextOpening || nextClosing == - 1 ) ) { // found a '{' if ( currentLevel === 0 ) { lastOpenedLevel0 = nextOpening ; } currentLevel ++ ; if ( statementLevel == - 1 ) { // we are not inside a statement if ( text . charAt ( nextOpening - 1 ) == "$" ) { // we do not prefix in case we have ${...} statementLevel = currentLevel ; } else { var tag = text . substring ( nextOpening , nextClosing ) ; var currentTagName = nameExtractor . exec ( tag ) ; if ( currentTagName && dictionary [ currentTagName [ 1 ] ] ) { // It's a statement, it shouldn't be escaped // and we should skip everything inside this statement statementLevel = currentLevel ; } else { // add a prefix wholeText . push ( text . substring ( lastCopiedPosition , nextOpening ) ) ; wholeText . push ( '\\{' ) ; lastCopiedPosition = nextOpening + 1 ; } } } currentPosition = nextOpening + 1 ; } else if ( nextClosing > - 1 ) { // found '}' if ( currentLevel === 0 ) { // missing opening '{' corresponding to '}' this . _computeLineNumbers ( ) ; this . logOrThrowError ( this . MISSING_OPENINGBRACES , [ this . positionToLineNumber ( nextClosing ) ] , this . context , throwErrors ) ; return false ; } if ( statementLevel == currentLevel ) { statementLevel = - 1 ; // no longer inside a statement } else if ( statementLevel == - 1 ) { // add the prefix for the closing } wholeText . push ( text . substring ( lastCopiedPosition , nextClosing ) ) ; wholeText . push ( '\\}' ) ; lastCopiedPosition = nextClosing + 1 ; } currentLevel -- ; currentPosition = nextClosing + 1 ; } else { this . $assert ( 94 , nextOpening == - 1 && nextClosing == - 1 ) ; // no more '{' or '}' currentPosition = textLength ; wholeText . push ( text . substring ( lastCopiedPosition , textLength ) ) ; lastCopiedPosition = textLength ; } } if ( currentLevel > 0 ) { // missing opening '{' corresponding to '}' this . _computeLineNumbers ( ) ; this . logOrThrowError ( this . MISSING_CLOSINGBRACES , [ this . positionToLineNumber ( lastOpenedLevel0 ) ] , this . context , throwErrors ) ; return false ; } this . template = wholeText . join ( "" ) ; return true ; }
Preprocess the CSS template to escape any curly brackets that will break the tree build
@param {Object} dictionary list of statementes allowed by the class generator
@return {Boolean} true if preprocessing was done successfully or false if there was a mismatch between '{'
and '}'
@private
Preprocess the CSS template to escape any curly brackets that will break the tree build