Generator that returns items in ther order needed for the actual python
            1) All forward references
            2) All lexer items
            3) Object / Array definitions in order of increasing dependency depth

            Within each category, items are returned alphabetically

def ordered_elements(self) -> str:
        """ Generator that returns items in ther order needed for the actual python
            1) All forward references
            2) All lexer items
            3) Object / Array definitions in order of increasing dependency depth

            Within each category, items are returned alphabetically
        """
        from pyjsg.parser_impl.jsg_lexerruleblock_parser import JSGLexerRuleBlock
        from pyjsg.parser_impl.jsg_arrayexpr_parser import JSGArrayExpr
        from pyjsg.parser_impl.jsg_objectexpr_parser import JSGObjectExpr
        from pyjsg.parser_impl.jsg_builtinvaluetype_parser import JSGBuiltinValueType
        from pyjsg.parser_impl.jsg_valuetype_parser import JSGValueType

        state = 0
        self.depths = {}
        for k in self.dependency_map.keys():
            self.calc_depths(k)
        # NOTE that depth is not in the closure -- if you create an iterator and then bump depth
        #      the iterator will work against the bumped depth
        depth = -1
        max_depth = max(self.depths.values()) if self.depths else 0
        while state >= 0:
            iter_ = iter([])
            if state == 0:
                depth += 1
                if depth <= max_depth:
                    iter_ = (k for k, v in self.grammarelts.items()
                             if isinstance(v, (JSGLexerRuleBlock, JSGBuiltinValueType)) and self.depths[k] == depth)
                else:
                    depth = -1
                    state += 1
            elif state == 1:
                depth += 1
                if depth <= max_depth:
                    iter_ = (k for k, v in self.grammarelts.items()
                             if isinstance(v, (JSGObjectExpr, JSGArrayExpr, JSGValueType)) and
                             self.depths[k] == depth and k not in self.forward_refs)
                else:
                    depth = -1
                    state += 1
            elif state == 2:          # Forward references
                depth += 1
                if depth <= max_depth:
                    iter_ = (k for k, v in self.grammarelts.items()
                             if isinstance(v, (JSGObjectExpr, JSGArrayExpr, JSGValueType)) and
                             self.depths[k] == depth and k in self.forward_refs)
                else:
                    state = -1
            while state >= 0:
                rval = next(iter_, None)
                if rval is None:
                    break
                yield rval