def graph(self, argstr, i):
        """
        Parse trig graph, i.e.

           <urn:graphname> = { .. triples .. }

        return -1 if it doesn't look like a graph-decl
        raise Exception if it looks like a graph, but isn't.
        """

        #import pdb; pdb.set_trace()
        j = self.sparqlTok('GRAPH', argstr, i) # optional GRAPH keyword
        if j >= 0: i = j

        r = []
        j = self.labelOrSubject(argstr, i, r)
        if j >= 0:
            graph = r[0]
            i = j
        else:
            graph = self._store.graph.identifier # hack


        j = self.skipSpace(argstr, i)
        if j < 0:
            self.BadSyntax(argstr, i,
                           "EOF found when expected graph")

        if argstr[j:j + 1] == "=": # optional = for legacy support

            i = self.skipSpace(argstr, j + 1)
            if i < 0:
                self.BadSyntax(argstr, i, "EOF found when expecting '{'")
        else:
            i = j

        if argstr[i:i+1] != "{":
            return -1 # the node wasn't part of a graph


        j = i+1

        oldParentContext = self._parentContext
        self._parentContext = self._context
        reason2 = self._reason2
        self._reason2 = becauseSubGraph
        self._context = self._store.newGraph(graph)

        while 1:
            i = self.skipSpace(argstr, j)
            if i < 0:
                self.BadSyntax(
                    argstr, i, "needed '}', found end.")

            if argstr[i:i + 1] == "}":
                j = i + 1
                break

            j = self.directiveOrStatement(argstr, i)
            if j < 0:
                self.BadSyntax(
                    argstr, i, "expected statement or '}'")

        self._context = self._parentContext
        self._reason2 = reason2
        self._parentContext = oldParentContext
        #res.append(subj.close())    # No use until closed
        return j
dataset/ETHPy150Open RDFLib/rdflib/rdflib/plugins/parsers/trig.py/TrigSinkParser.graph/original