Exemple #1
0
 def add_property(self, name, value):
     
     prop = AstNode('property')
     prop.addChild(AstNode('name', name))
     prop.addChild(AstNode('value', value))
     
     self.addChild(prop)
def _branch_transform(astNode):
    
    res = AstNode("branch")
    
    for child in astNode.getChildren():
        child.setId("")
        res.addChild(child)
    
    return res
def _group_transform(astNode):
    
    res = AstNode("group")
    
    for child in astNode.getChildrenById('branch'):
        child.setId('')
        res.addChild(child)

    return res
def _comment_transform(astNode):
    
    line = astNode.getChildById('line')
    if line:
        res = AstNode('line-comment')
        begin = AstNode('begin', astNode.getChildById('begin').getText())
        res.addChild(begin)
    else:
        res = AstNode('block-comment')
        begin = AstNode('begin', astNode.getChildById('begin').getText())
        res.addChild(begin)
        end = AstNode('end', astNode.getChildById('end').getText())
        res.addChild(end)
        
    return res
    def get_expanded_ast(self, filepath):

        ast = self._parser.parseFile(filepath)

        new_children = []

        for child in ast.getChildren():
            if child.getName() != 'include':
                child.addChild(AstNode('origin', filepath))
                new_children.append(child)
            else:
                for inclpath in child.getChildren():
                    for new_child in self._resolve_include(inclpath):
                        new_children.append(new_child)

        ast.removeChildren()

        for child in new_children:
            ast.addChild(child)

        self._expanded_asts[filepath] = ast

        return ast
 def transform(self, astNode):
     
     res = AstNode('meta-grammar')
     
     commentNodes = astNode.getChildrenById('comment-style')
     if commentNodes:
         node = AstNode('comment-styles')
         res.addChild(node)
         line = None
         block = None
         for cnode in commentNodes:
             if line and block:
                 break
             if line is None and cnode.getName() == 'line-comment':
                 cnode.setId('')
                 node.addChild(cnode)
                 line = cnode
                 continue
             if block is None and cnode.getName() == 'block-comment':
                 cnode.setId('')
                 node.addChild(cnode)
                 block = cnode
                 
     enableNodes = astNode.getChildrenById('enable')
     if enableNodes:
         node = AstNode('enable')
         for item in enableNodes:
             node.addChild(item)
         res.addChild(node)
                     
     tokensNodes = astNode.getChildrenById('tokens')
     if tokensNodes:
         node = AstNode('tokens')
         res.addChild(node)
         for tn in tokensNodes:
             for t in tn.getChildren():
                 node.addChild(t)
                 
     ruleNodes = astNode.getChildrenById('rule')
     if ruleNodes:
         node = AstNode('rules')
         res.addChild(node)
         for rn in ruleNodes:
             rn.setId('')
             node.addChild(rn)
     
     return res
def _branch_elem_transform(astNode):
    
    res = AstNode('element')
    
    for child in astNode.getChildren():
        id_ = child.getId()
        if id_ == 'token':
            node = AstNode('token-id', child.getText())
            res.addChild(node)
        elif id_ == 'rule': 
            node = AstNode('rule-id', child.getText())
            res.addChild(node)
        elif id_ == 'keyword': 
            node = AstNode('keyword-text', child.getText()[1:-1])
            res.addChild(node)
        elif id_ == 'group':
            child.setId('') 
            res.addChild(child)
        elif id_ == 'id':
            node = AstNode('id', child.getText())
            res.addChild(node)
        elif id_ == 'mult':
            child.setId('') 
            res.addChild(child)
    
    return res
Exemple #8
0
 def __init__(self, name, token_id):
     
     AstNode.__init__(self, name)
     self.addChild(AstNode('token-id', token_id))
Exemple #9
0
 def __init__(self):
     
     AstNode.__init__(self, name = 'properties')
Exemple #10
0
 def __init__(self, rule_id, is_grammar=False):
     
     AstNode.__init__(self, is_grammar and 'grammar' or 'rule')
     self.addChild(AstNode('rule-id', rule_id))