Пример #1
0
 def _evalargs(self, args, lcls, ignore):
     funcname = str(args[0])
     if __debug__:
         assert isinstance(lcls.iv.last.baseobj, uclassobj), "Cannot apply class functions to a non-class object!"
     if not lcls.iv.last.attrsnodata or list(lcls.iv.last.attrsnodata.keys()) == ["$__name"]:
         whichone = lcls.iv.last
     else:
         whichone = uclassobj._classiter(lcls.iv.last)
     for line in whichone:
         if isinstance(line.baseobj, mthdobj) and line[0].datastr == funcname:
             topass = lcls.onlyuobjs()
             # topass = lclsdict(args.control)
             topass.iv.last = line
             topass.iv.this = lcls.iv.last
             delim = args.control.delims["applier"]
             # print(topass,group(data = delim[0], baseobj = delim[1],
             # control = args.control, args = args[1:]))
             topass.iv.last.baseobj.evalobj(
                 group(data=delim[0], baseobj=delim[1], control=args.control, args=args[1:]), topass
             )
             lcls.iv.last = topass.iv.last.deepcopy()
             return lcls.iv.last
     if funcname == "funcs":
         lcls.iv.last = group(
             data=":", baseobj=arrayobj(), control=args.control, args=uclassobj._classiter(lcls.iv.last)
         )
         return lcls.iv.last
     ret = super()._evalargs(args, lcls, ignore)
     if ret != NotImplemented:
         return ret
     raise ValueError("Function '{}' isn't defined for {} '{}'".format(funcname, type(self).__qualname__, args))
Пример #2
0
 def _input(self, args, lcls):
     """ nput:[question,[valid results (regex) [, error messg]]]"""
     from Objects import strobj #this could be moved to the top
     msg, valid, err = group(data = "'> '", control = args.control), None,\
                       group(data = "\"\0'{inv}' is an invalid input! Valid: '{val}'.\"", control = args.control)
     if len(args) > 0:
         args[0].evalgrp(lcls)
         msg = lcls.iv.last
         if len(args) > 1:
             args[1].evalgrp(lcls)
             valid = lcls.iv.last
             if len(args) > 2:
                 args[2].evalgrp(lcls)
                 err = lcls.iv.last
                 if __debug__:
                     assert len(args) <= 3, 'input:[question,[valid results (array) [, error messg]]]'
     lcls.iv.last = group(baseobj = strobj(), control = args.control)
     # if valid != None:
     #     assert 0, 'what is convstr??' + repr(valid)
     #     valid.data = str(valid.data.convstr())
     while True:
         lcls.iv.last = group(data = str(input(msg.scrubstr(args.control))), control = args.control)
         if valid == None:
             break
         if __debug__:
             assert isinstance(valid.baseobj, arrayobj),\
                 'Only accepts array of valid results!, not ' + str(type(valid.baseobj))
         if lcls.iv.last not in valid:
             print(err.scrubstr(args.control, inv = lcls.iv.last.data, val = str(valid)))
         else:
             break;
Пример #3
0
 def comprtkns(linegrp): #this is non-stable
     ret = group(control = self.control, parens = linegrp.parens) #universe
     while len(linegrp) != 0:
         ele = linegrp.pop(0) #pop(0) is inefficient for list. update this in the future
         if isinstance(ele.baseobj, strobj) or\
             str(ele) not in self.control.allparens or\
             not str(ele):
             ret.append(ele)
         else:
             toappend = group(control = self.control)
             parens = {str(ele):1}
             while sum(parens.values()) > 0 and len(linegrp) != 0:
                 toappend.append(linegrp.pop(0))
                 if str(toappend[-1]) in self.control.allparens\
                     and not isinstance(toappend[-1].baseobj, strobj):
                     last = str(toappend[-1])
                     if last in self.control.parens['l']:
                         if last not in parens:
                             parens[last] = 0
                         parens[last] += 1
                     if last in self.control.parens['r']:
                         if __debug__:
                             assert self.control._invertparen(last) in parens, "unmatched paren '{}'!".format(last)
                         parens[self.control._invertparen(last)] -= 1
             if __debug__:
                 assert str(toappend[-1]) in self.control.allparens, toappend #the last element should be in allparens
             toappend.parens = (str(ele), str(toappend.pop()))
             toappend = comprtkns(toappend)
             # if toappend.hasparens():
             #     parens = toappend.parens
             #     toappend.parens = toappend.defaultparens
             #     toappend = group(parens = parens, control = toappend.control, args = toappend)
             ret.append(toappend)
     return ret
Пример #4
0
 def _types(self, args, lcls):
     if __debug__:
         assert len(args) in {1, 2}, "om:types:(TYPE)[:(init args)], not " + str(args)
     base = args[0].datastr
     from Objects import __all__ as allobj
     if __debug__:
         assert base in allobj, "No such type of '{}'!".format(base)
     topassobj = getattr(__import__('Objects'), base)
     lcls.iv.last = group(data = str(topassobj), baseobj = typeobj(\
         baseclass = group(baseobj = topassobj(), control = args.control)), control = args.control)
Пример #5
0
 def _func(self, args, lcls):
     if __debug__:
         assert len(args) == 3, 'func:name:params:body'
     lcls[str(args[0])] = group(data = args.datastr,
                            baseobj = umthdobj(str(args[0])),
                            args = list(args),
                            control = args.control)
Пример #6
0
            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
Пример #7
0
        def tokenize(self, rawt):
            """ goes thru, and splits them up first based upon control.sortedopers and then by control.punctuation. """
            def createtokens(rawt):
                for oper in self.control.sortedopers:
                    if oper in rawt:
                        par = rawt.partition(oper)
                        return createtokens(par[0]) + [par[1]] + createtokens(par[2])
                for punc in self.control.punctuation:
                    if punc in rawt:
                        par = rawt.partition(punc)
                        return createtokens(par[0]) + [par[1]] + createtokens(par[2])
                return [rawt]
            tokens = [token for token in createtokens(rawt) if token]
            ret = []
            currentquote = None
            for token in tokens:
                if token in self.control.allquotes and token:
                    if currentquote == None:
                        ret.append(token)
                        currentquote = token
                    else:
                        if token == currentquote:
                            currentquote = None
                        ret[-1] += token
                elif currentquote:
                    ret[-1] += token
                else:
                    ret.append(token)
            #@define stuff
            linep = 0
            while linep < len(ret): 
                if ret[linep] and ret[linep] in self.control.datadef:
                    self.control.applyrules(ret.args.pop(0))
                linep+=1
            ret2 = []
            for token in ret:
                if token:
                    if token[0] not in self.control.allquotes:
                        if token.strip(self.control.nbwhitespace):
                            if __debug__:
                                assert token[-1] not in self.control.allquotes, token
                            ret2.append(token.strip(self.control.nbwhitespace))
                    else:
                        ret2.append(token)

            ret = []
            for e in (e.strip(self.control.nbwhitespace) for e in ret2):
                if not ret or not e or e not in self.control.delims['endline']\
                    or str(ret[-1].data) not in self.control.delims['endline']:
                    ret.append(group(e, control = self.control))
            # quit(list(str(x) for x in ret))
            return ret
Пример #8
0
    def _class(self, args, lcls):
        if __debug__:
            assert len(args) == 3, 'class:name:[(parent)]:(body)'


        lcls2pass = localsdict(args.control)
        args2pass = []
        if __debug__:
            assert len(args[2]) == 1, 'body should be :{body}, not' + str(args[2])
        for arg in args[2][0]:
            arg.evalgrp(lcls2pass)
            args2pass.append(lcls2pass.iv.last.deepcopy())
        lcls[str(args[0])] = group(data = args.datastr, 
                                baseobj = uclassobj(),
                                args = args2pass, 
                                control = args.control,
                                attrs = {'$__name':str(args[0])})
Пример #9
0
 def _speceval(self, args, lcls):
     ctrl = args.control
     if self.name in ctrl.delims:
         if self.name in ctrl.delims['applier']:
             args[0].evalgrp(lcls)
             lcls.iv.last.baseobj.evalobj(args[1:], lcls)
             return
         if self.name in ctrl.delims['endline']:
             for arg in args:
                 arg.evalgrp(lcls)
                 if lcls.iv.ret:
                     # del lcls.iv.ret
                     break
             return
         if self.name in ctrl.delims['arraysep']:
             grp = group(baseobj = arrayobj(), parens = args.parens, control = args.control)
             for arg in args:
                 arg.evalgrp(lcls)
                 if lcls.iv.ret.data:
                     break
                 grp.append(lcls.iv.last)
             lcls.iv.last = grp
             return
             # assert 0, 'todo: arraysep'
         
     if self.name in ctrl.opers['binary']:
         if __debug__:
             assert self.name not in ctrl.opers['binary']['math'], 'all math should have a func associated!'
             assert self.name not in ctrl.opers['binary']['bitwise'], 'all bitwise should have a func associated!'
         if self.name in ctrl.opers['binary']['assignment']:
             d = self.name in args.control.opers['binary']['assignment']['r']
             args[d - 1].evalgrp(lcls)
             for arg in args[slice(d or None, d - 1 or None, None)]:
                 self._evalassign(arg, lcls)
             return
         if self.name in ctrl.opers['binary']['logic']:
             pass
     raise SyntaxError("Unknown Special Operator '{}' in arguments '{}'! Known operators: {}".\
                       format(self, args, ctrl.allopers.keys()))
Пример #10
0
 def _rand(self, args, lcls):
     lcls.iv.last = group(data = str(random.random()), control = args.control)
Пример #11
0
 def _len(self, args, lcls):
     if __debug__:
         assert len(args) == 0, 'arr:len'
     from Group import group
     lcls.iv.last = group(data = str(len(lcls.iv.last)), baseobj = intobj(), control = args.control)
Пример #12
0
 def __delattr__(self, attr):
     return super().__delattr__(attr) if attr not in self.idict\
         else self.__setitem__(attr, group(control = self.control))
Пример #13
0
 def __init__(self, control):
     self.control = control
     super().__init__(dict())
     for iv in self.idict:
         self[iv] = group(control = self.control)
Пример #14
0
 def _evalargs(self, args, lcls, ignore):
     if __debug__:
         assert len(args) > 0, "No known Obj function '' for Obj '{}'!".format(args)
     # objname = str(lcls.iv.last.data)
     fncname = str(args[0])
     if fncname == '$clone' or fncname == '$copy' and fncname not in ignore:
         lcls.iv.last = lcls.iv.last.deepcopy()
     elif fncname == '$updtype' and fncname not in ignore:
         if __debug__:
             from Objects import arrayobj
             assert isinstance(args[1].baseobj, arrayobj), str(args) + " should be obj:updtype:(type)"
             assert len(args[1]) == 1, str(args) + " should be obj:updtype:(type)"
         last = lcls.iv.last
         args[1][0].evalgrp(lcls)
         if __debug__:
             from Objects import typeobj
             assert isinstance(lcls.iv.last.baseobj, typeobj), "should be obj:updtype:(type)"
         last.baseobj = lcls.iv.last.baseobj.baseclass.baseobj
     elif fncname == '$type' and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import typeobj # to be doing this...
         lcls.iv.last = group(data = type(lcls.iv.last.baseobj).__qualname__, baseobj = typeobj(lcls.iv.last),
                              control = args.control)
     elif fncname == '$str' and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import strobj # to be doing this...
         lcls.iv.last = group(data = lcls.iv.last.data, baseobj = strobj(),
                              control = args.control)
     elif fncname in {'$attrs', '$a'} and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import dictobj # to be doing this...
         lcls.iv.last = group(data = '', baseobj = dictobj(), parens = ('{', '}'),
                              control = args.control,
                              args = lcls.iv.last.attrs)
     elif fncname in {'$setattr', '$sa'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$setattr:(name, value), not '{}'".format(str(args))
             assert len(args[1]) == 2, "obj:$setattr:(name, value), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         args[1][0].evalgrp(lcls)
         name = lcls.iv.last
         args[1][1].evalgrp(lcls)
         print(name.datastr in last.attrs,name.datastr, last.attrs.keys(), sep = '\t|\t')
         last.attrs[name.datastr] = lcls.iv.last
     elif fncname in {'$getattr', '$ga'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$getattr:(name), not '{}'".format(str(args))
             assert len(args[1]) == 1, "obj:$getattr:(name), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         # args[1][0].evalgrp(lcls)
         lcls.iv.last = last.attrs[args[1][0].datastr]
     elif fncname in {'$delattr', '$da'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$delattr:(name), not '{}'".format(str(args))
             assert len(args[1]) == 1, "obj:$delattr:(name), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         # args[1][0].evalgrp(lcls)
         lcls.iv.last = last.attrs[args[1][0].datastr]
         del last.attrs[args[1][0].datastr]
     else:
         if type(self)._evalargs == obj._evalargs:
             raise SyntaxError("No known function '{}' for {} '{}'.".\
                               format(fncname, type(self).__qualname__, lcls.iv.last))
         return NotImplemented
     return lcls.iv.last
Пример #15
0
        def compresstokens(self, linetokens):
            def comprtkns(linegrp): #this is non-stable
                ret = group(control = self.control, parens = linegrp.parens) #universe
                while len(linegrp) != 0:
                    ele = linegrp.pop(0) #pop(0) is inefficient for list. update this in the future
                    if isinstance(ele.baseobj, strobj) or\
                        str(ele) not in self.control.allparens or\
                        not str(ele):
                        ret.append(ele)
                    else:
                        toappend = group(control = self.control)
                        parens = {str(ele):1}
                        while sum(parens.values()) > 0 and len(linegrp) != 0:
                            toappend.append(linegrp.pop(0))
                            if str(toappend[-1]) in self.control.allparens\
                                and not isinstance(toappend[-1].baseobj, strobj):
                                last = str(toappend[-1])
                                if last in self.control.parens['l']:
                                    if last not in parens:
                                        parens[last] = 0
                                    parens[last] += 1
                                if last in self.control.parens['r']:
                                    if __debug__:
                                        assert self.control._invertparen(last) in parens, "unmatched paren '{}'!".format(last)
                                    parens[self.control._invertparen(last)] -= 1
                        if __debug__:
                            assert str(toappend[-1]) in self.control.allparens, toappend #the last element should be in allparens
                        toappend.parens = (str(ele), str(toappend.pop()))
                        toappend = comprtkns(toappend)
                        # if toappend.hasparens():
                        #     parens = toappend.parens
                        #     toappend.parens = toappend.defaultparens
                        #     toappend = group(parens = parens, control = toappend.control, args = toappend)
                        ret.append(toappend)
                return ret
            def findhighest(linegrp):
                if __debug__:
                    assert len(linegrp) or linegrp.data, linegrp
                    #change this in the future when boolean for linegrp changes
                highest = None
                for elep in range(len(linegrp)):
                    ele = str(linegrp[elep])
                    if ele in self.control.allopers and (highest == None or
                            self.control.allopers[ele].priority >=\
                            self.control.allopers[str(linegrp[highest].data)].priority):
                        highest = elep
                if __debug__:
                    if highest == None:
                    #     linegrp.data = self.control.delims['applier'][1]
                    #     return linegrp
                        raise SyntaxError("no operator for string '{}'!".format(repr(linegrp))) # ':' was still required
                return linegrp[highest]
            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
            return fixtkns(comprtkns(group(args = linetokens, control = self.control)))