hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) {
        //creates the if node
        var node = new Node("if"), block = blocks[index], lastValidIndex = index;
        node.condition = {
            "category": block.condition.category,
            "value": block.condition.value,
            "line": block.condition.line,
            "column": block.condition.column
        };
        node.condition.bound = true; //TODO: what does it mean?
        node.content1 = [];
        out.push(node);

        var endFound = false, out2 = node.content1;

        //process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any
        while (!endFound) {
            //fills node.content1 with the next blocks
            index = this._advance(blocks, index + 1, out2, this._ifEndTypes);
            if (index < 0 || !blocks[index]) {
                this._logError("Missing end if statement", blocks[lastValidIndex]);
                endFound = true;
            } else {
                var type = blocks[index].type;
                if (type === "endif") {
                    endFound = true;
                } else if (type === "else") {
                    //loop will restrat, filling node.content2 with the next blocks
                    node.content2 = [];
                    out2 = node.content2;
                    lastValidIndex = index;
                } else if (type === "elseif") {
                    // consider as a standard else statement
                    node.content2 = [];
                    out2 = node.content2;
                    lastValidIndex = index;
                    endFound = true;

                    // process as if it were an if node
                    index = this.__if(index, blocks, out2);
                }
            }
        }
        return index;
    }
function (index, blocks, out) {
        //creates the if node
        var node = new Node("if"), block = blocks[index], lastValidIndex = index;
        node.condition = {
            "category": block.condition.category,
            "value": block.condition.value,
            "line": block.condition.line,
            "column": block.condition.column
        };
        node.condition.bound = true; //TODO: what does it mean?
        node.content1 = [];
        out.push(node);

        var endFound = false, out2 = node.content1;

        //process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any
        while (!endFound) {
            //fills node.content1 with the next blocks
            index = this._advance(blocks, index + 1, out2, this._ifEndTypes);
            if (index < 0 || !blocks[index]) {
                this._logError("Missing end if statement", blocks[lastValidIndex]);
                endFound = true;
            } else {
                var type = blocks[index].type;
                if (type === "endif") {
                    endFound = true;
                } else if (type === "else") {
                    //loop will restrat, filling node.content2 with the next blocks
                    node.content2 = [];
                    out2 = node.content2;
                    lastValidIndex = index;
                } else if (type === "elseif") {
                    // consider as a standard else statement
                    node.content2 = [];
                    out2 = node.content2;
                    lastValidIndex = index;
                    endFound = true;

                    // process as if it were an if node
                    index = this.__if(index, blocks, out2);
                }
            }
        }
        return index;
    }
function ( index , blocks , out ) { //creates the if node var node = new Node ( "if" ) , block = blocks [ index ] , lastValidIndex = index ; node . condition = { "category" : block . condition . category , "value" : block . condition . value , "line" : block . condition . line , "column" : block . condition . column } ; node . condition . bound = true ; //TODO: what does it mean? node . content1 = [ ] ; out . push ( node ) ; var endFound = false , out2 = node . content1 ; //process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any while ( ! endFound ) { //fills node.content1 with the next blocks index = this . _advance ( blocks , index + 1 , out2 , this . _ifEndTypes ) ; if ( index < 0 || ! blocks [ index ] ) { this . _logError ( "Missing end if statement" , blocks [ lastValidIndex ] ) ; endFound = true ; } else { var type = blocks [ index ] . type ; if ( type === "endif" ) { endFound = true ; } else if ( type === "else" ) { //loop will restrat, filling node.content2 with the next blocks node . content2 = [ ] ; out2 = node . content2 ; lastValidIndex = index ; } else if ( type === "elseif" ) { // consider as a standard else statement node . content2 = [ ] ; out2 = node . content2 ; lastValidIndex = index ; endFound = true ; // process as if it were an if node index = this . __if ( index , blocks , out2 ) ; } } } return index ; }
Manages an if block.
@param {Array} blocks the full list of blocks.
@param {Integer} index the index of the block to manage.
@param {Array} out the output as an array of Node.
@return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
Manages an if block .