def fixtkns(line): """ combine tokens using order of operations """ if __debug__: assert isinstance(line, group), 'why wouldn\'t it be?' if isinstance(line.baseobj, arrayobj) or line.hasparens():# and len(line) <= 1: if __debug__: assert line.data == None, 'when would this happen??' cpy = line.deepcopy() cpy.parens, cpy.baseobj = cpy.defaultparens, obj() #so it wont go into this again. cpy = fixtkns(cpy) if cpy.data in line.control.delims['arraysep']: if __debug__: assert not cpy.hasparens(), 'not hard and fast, just why would it? (a:b), the a:b is cpy' cpy.parens = line.parens return cpy line = group(control = line.control, parens = line.parens, baseobj = line.baseobj, args = [cpy]) return line if not len(line): return line if len(line) == 1: #if the line is literally a single element, usually: ([blah, blah]) return line[0] if not len(line[0]) else fixtkns(line[0]) fhp = findhighest(line) if __debug__: assert isinstance(fhp, group), 'expected a group for fhp! (not %s)' % fhp assert not len(fhp) and fhp.data, fhp ret = group(data = fhp.data, control = self.control, parens = line.parens) current = group(control = self.control) while len(line): e = line.pop(0) #was formerly .pop(0) if e.data == ret.data: if len(current) and current[-1].hasparens():#isinstance(current[-1].baseobj,arrayobj): for ele in current: ret.append(fixtkns(current)) else: ret.append(fixtkns(current)) current = group(control = self.control) else: current.append(e) if len(current): ret.append(fixtkns(current)) return ret
def getobj(self): if self.data == None and self.hasparens(): return arrayobj() if self.data == None: return nullobj() if __debug__: assert isinstance(self.data, str), "'%s' has to be of type str, not '%s'" %(self.data, type(self.data)) for key in objregexes: m = re.fullmatch(key.format(quote = self.control.allquotes, escape = self.control.escape), self.datastr) if m: self.data = m.groupdict()['keep'] if objregexes[key] == nullobj: return objregexes[key](isuser = True) return objregexes[key]() if self.data in self.control.allkws: return self.control.allkws[self.data] return obj()