def __new__(cls, *args, **kwargs):
        # this class is an abstract base class for all Parser classes, cannot be built directly

        if cls is Parser :
            # type argument can be the name of a Parser class or an instance of the class
            ptype=kwargs.get('type', None)
            if ptype is None :
                raise TypeError, "must specify a Parser class"
            elif isinstance(ptype, Parser) and not ptype is Parser :
                parsercls = ptype
            elif ptype in Parser.classes :
                parsercls = Parser.classes[ptype]
            else :
                raise TypeError, "invalid Parser type: %s" % ptype
        else :
            # subclasses of Parser
            parsercls = cls

#        if 'tokensDict' in parsercls.__dict__ and 'rulesDict' in parsercls.__dict__:
#            rulesDict = parsercls.rulesDict
#            tokensDict = parsercls.tokensDict
#        else:

        reserved = []
#        #reserved = [ k for k,v in parsercls.tokensDict.items() if not k.startswith( 't_') ]
#        if hasattr( parsercls, '_reserved'):
#            for k, v in parsercls._reserved.items():
#                # reserved should be a map of reserved names (as used in the code to parse) to token names (as used in PLY).
#                # as such, we only care about the PLY names, ie. the values
#                reserved.append(v)

        rulesDict, tokensDict = Parser.getRulesAndTokens( parsercls )

        tokens = tokensDict.keys()
        rules = list(rulesDict.keys())
        # Sort them by line number of declaration as it's how the yacc builder works to order rules
        # TODO : some more explicit rule order handling (when precedence isn't an option) ?
        rules.sort(lambda x,y: cmp(rulesDict[x].func_code.co_firstlineno,rulesDict[y].func_code.co_firstlineno))
        # print "sorted rules:", [(r, parsercls.rulesDict[r].func_code.co_firstlineno) for r in rules]
        rules = tuple(rules)

        parsercls.tokens = tuple( tokens + list(set(reserved)) )
        parsercls.rules = rules

        #print "%s tokens %s" % ( parsercls, parsercls.tokens )
        # class must have a start attribute for __init__, start can be None though
        # must not inherit start as parsed would not parse own class new rules
        if not 'start' in parsercls.__dict__ :
            parsercls.start = None

        # TODO : same for precedence rules
        return super(Parser, cls).__new__(parsercls, *args, **kwargs)
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/pymel-1.0.5/pymel/util/objectParser.py/Parser.__new__/original