def find_function_body(text, function):
    position = text.find(function[0])
    if position != -1:

        #get first open bracket
        while text[position] != "{" and text[position] != ";" and position != len(text):
            position += 1
        if text[position] == "{":
            start = position
            end = start + helper.find_adjacent_bracket(text[position:], "{}")
            return text[start:end]

        raise SystemError("Incorrect bracket positions")
Esempio n. 2
0
def find_function_body(text, function):
    position = 0
    while position < len(text):
        position = text.find(function[0], position)
        if position != -1:

            #get first open bracket
            while (not text[position] in ['{', '}', ';']) and position != len(text):
                position += 1
            if text[position] == "{":
                start = position
                end = start + helper.find_adjacent_bracket(text[position:], "{}")
                return text[start:end]
            else:
                continue
    
    raise SyntaxError("Incorrect bracket positions for function {0} in \n----------\n...{1}\n----------\n".format(function, text[position-50:]))
Esempio n. 3
0
def find_function_body(text, function):
    position = 0
    while position < len(text):
        position = text.find(function[0], position)
        if position != -1:

            #get first open bracket
            while (not text[position] in ['{', '}', ';'
                                          ]) and position != len(text):
                position += 1
            if text[position] == "{":
                start = position
                end = start + helper.find_adjacent_bracket(
                    text[position:], "{}")
                return text[start:end]
            else:
                continue

    raise SyntaxError(
        "Incorrect bracket positions for function {0} in \n----------\n...{1}\n----------\n"
        .format(function, text[position - 50:]))
Esempio n. 4
0
    def _build_node(self, text, node):
        """ Creates nodes recursively """

        oldnode = None

        index = 0

        while True:
            (found,
             operator) = find_first(text,
                                    ['if', 'else', 'elseif', 'while', 'for'],
                                    index)
            if found < 0:
                break
            index = found

            if operator == 'if':
                endnode = ExecNode('endif', node.wants_endnode)
                endnode.parents.append(node)
                node.children.append(endnode)
                node.endnode = endnode

                new_node = ExecNode('if', endnode)
                new_node.parents.append(node)
                node.children.append(new_node)

                oldnode = node
                node = endnode

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(
                    text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            elif operator == 'else':
                node.parents.pop(node.parents.index(oldnode))
                oldnode.children.pop(oldnode.children.index(node))

                elsenode = ExecNode('else', node)

                elsenode.parents.append(oldnode)
                oldnode.children.append(elsenode)

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(
                    text[block_start:], '{}')

                self._build_node(text[block_start:block_end], elsenode)

            elif operator == 'elseif':
                new_node = ExecNode('elseif', node)
                new_node.parents.append(oldnode)
                oldnode.children.append(new_node)

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(
                    text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            elif operator == 'while' or operator == 'for':
                endnode = ExecNode('endwhile', node.wants_endnode)
                new_node = ExecNode('while', None)
                new_node.wants_endnode = new_node

                endnode.parents.append(new_node)
                new_node.children.append(endnode)
                node.endnode = endnode

                node.children.append(new_node)
                new_node.parents.append(new_node)

                node = endnode

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(
                    text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            index = block_end

        node.endnode = node.wants_endnode
        node.endnode.parents.append(node)
        node.children.append(node.endnode)
Esempio n. 5
0
    def _build_node(self, text, node):
        """ Creates nodes recursively """

        oldnode = None

        index = 0
        
        while True:
            (found, operator) = find_first(text, ['if', 'else', 'elseif', 'while'], index)
            if found < 0:
                break
            index = found

            if operator == 'if':
                endnode = ExecNode('endif', node.wants_endnode)
                endnode.parents.append(node)
                node.children.append(endnode)
                node.endnode = endnode

                new_node = ExecNode('if', endnode)
                new_node.parents.append(node)
                node.children.append(new_node)
                
                oldnode = node
                node = endnode
                
                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            elif operator == 'else':
                node.parents.pop(node.parents.index(oldnode))
                oldnode.children.pop(oldnode.children.index(node))
                
                elsenode = ExecNode('else', node)

                elsenode.parents.append(oldnode)
                oldnode.children.append(elsenode)

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(text[block_start:], '{}')

                self._build_node(text[block_start:block_end], elsenode)
            
            elif operator == 'elseif':
                new_node = ExecNode('elseif', node)
                new_node.parents.append(node)
                node.children.append(new_node)
                
                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            elif operator == 'while':
                endnode = ExecNode('endwhile', node.wants_endnode)
                new_node = ExecNode('while', None)
                new_node.wants_endnode = new_node

                endnode.parents.append(new_node)
                new_node.children.append(endnode)
                node.endnode = endnode
                
                node.children.append(new_node)
                new_node.parents.append(new_node)

                node = endnode

                block_start = text.find('{', index)
                block_end = block_start + helper.find_adjacent_bracket(text[block_start:], '{}')

                self._build_node(text[block_start:block_end], new_node)

            index = block_end

        node.endnode = node.wants_endnode
        node.endnode.parents.append(node)
        node.children.append(node.endnode)