Project

General

Profile

« Previous | Next » 

Revision 38

data2xml: Added syntax for split paths, which map to multiple leaves

View differences:

xpath.py
43 43
    
44 44
    def _path(self):
45 45
        tree = []
46
        trailing_slash = False
46 47
        while True:
47
            elem = XpathElem(is_attr=self._match_str('@'), name=self._fields())
48
            # Split path
49
            if self._match_str('{'):
50
                paths = []
51
                while True:
52
                    paths.append(tree + self._path())
53
                    if not self._match_str(','): break
54
                self._match_str('}', required=True)
55
                tree = paths[0] # just use first subpath for now
56
                break # nothing allowed after split path
48 57
            
58
            elem = XpathElem(is_attr=self._match_str('@'),
59
                name=self._match_re(r'[\w.*]+', required=True))
60
            
49 61
            # Attrs
50 62
            if self._match_str('['):
51 63
                elem.attrs = []
52 64
                while True:
53 65
                    path = self._path()
54
                    if self._match_str('='): set_value(path, self._value())
66
                    if self._match_str('='):
67
                        set_value(path, self._match_re(r'[\w.|]*'))
55 68
                    elem.attrs.append(path)
56 69
                    if not self._match_str(','): break
57 70
                self._match_str(']', required=True)
......
83 96
            elem_idx += 1
84 97
        
85 98
        return tree
86
    
87
    def _fields(self):
88
        if self._match_str('{'):
89
            tree = []
90
            while True:
91
                tree.append(self._field())
92
                if not self._match_str(','): break
93
            self._match_str('}', required=True)
94
            tree = tuple(tree)
95
            tree = tree[0] # just use first field for now
96
        else: tree = self._field()
97
        return tree
98
    
99
    def _field(self):
100
        return self._name()
101
    
102
    def _name(self): return self._match_re(r'[\w.*]+', required=True)
103
    
104
    def _value(self): return self._match_re(r'[\w.|]+', required=True)
105 99

  
106 100
instance_level = 1
107 101

  

Also available in: Unified diff