def get_precedences(self) -> list[PrecedenceSpec]:
    if (self._cache_precedences is not None):
        return self._cache_precedences
    result = []
    for (module, k, v, dirtoks) in self.named_objs:
        if (issubclass(v, Precedence) and (dirtoks[0] in ['%fail', '%nonassoc', '%left', '%right', '%split'])):
            name = k
            relationships = {}
            i = 1
            while (i < len(dirtoks)):
                tok = dirtoks[i]
                m = PrecedenceSpec.assoc_tok_re.match(tok)
                if m:
                    if (m.group(2) in relationships):
                        raise SpecError(('Duplicate precedence relationship: %s' % v.__doc__))
                    relationships[m.group(2)] = m.group(1)
                else:
                    m = NontermSpec.token_re.match(tok)
                    if m:
                        if (i != 1):
                            raise SpecError(('Precedence name must come before relationships: %s' % v.__doc__))
                        name = m.group(1)
                    else:
                        raise SpecError(('Invalid precedence specification: %s' % v.__doc__))
                i += 1
            prec = PrecedenceSpec(name, dirtoks[0][1:], relationships)
            result.append(prec)
    self._cache_precedences = result
    return result
def get_precedences(self) -> list[PrecedenceSpec]:
    if (self._cache_precedences is not None):
        return self._cache_precedences
    result = []
    for (module, k, v, dirtoks) in self.named_objs:
        if (issubclass(v, Precedence) and (dirtoks[0] in ['%fail', '%nonassoc', '%left', '%right', '%split'])):
            name = k
            relationships = {}
            i = 1
            while (i < len(dirtoks)):
                tok = dirtoks[i]
                m = PrecedenceSpec.assoc_tok_re.match(tok)
                if m:
                    if (m.group(2) in relationships):
                        raise SpecError(('Duplicate precedence relationship: %s' % v.__doc__))
                    relationships[m.group(2)] = m.group(1)
                else:
                    m = NontermSpec.token_re.match(tok)
                    if m:
                        if (i != 1):
                            raise SpecError(('Precedence name must come before relationships: %s' % v.__doc__))
                        name = m.group(1)
                    else:
                        raise SpecError(('Invalid precedence specification: %s' % v.__doc__))
                i += 1
            prec = PrecedenceSpec(name, dirtoks[0][1:], relationships)
            result.append(prec)
    self._cache_precedences = result
    return result