Ejemplo n.º 1
0
def patch(node, permutation):
    """ Replaces all occourences with incoming values """

    modified = False
    
    if node.type == "identifier" or node.type == "dot":

        if node.type == "dot":
            name = assembleDot(node)
        else:
            name = node.value

        replacement = __translateToValue(permutation.get(name))
        if replacement:
            Console.debug("Found permutation query (%s => %s) in line %s", name, replacement, node.line)
            replacementNode = Parser.parseExpression(replacement)
            node.parent.replace(node, replacementNode)
            modified = True
         
    # Process children
    for child in reversed(node):
        if child != None:
            if patch(child, permutation):
                modified = True

    return modified
Ejemplo n.º 2
0
    def __getTree(self, context=None):
        """
        Returns the parsed tree
        """

        field = "tree[%s]" % self.id
        tree = self.project.getCache().read(field, self.mtime)
        if not tree:
            Console.info(
                "Processing stylesheet %s %s...",
                Console.colorize(self.id, "bold"),
                Console.colorize("[%s]" % context, "cyan"),
            )

            Console.indent()
            tree = Parser.parse(self.getText(), self.id)
            Console.outdent()

            self.project.getCache().store(field, tree, self.mtime, True)

        return tree
Ejemplo n.º 3
0
def getTree(text, fileId=None):
    """
    Returns a tree of nodes from the given text
    """

    return Parser.parse(text, fileId)
Ejemplo n.º 4
0
def getTree(text, fileId=None):
    """Returns a tree of nodes from the given text."""

    return Parser.parse(text, fileId)