def get_tokens(self) -> list[TokenSpec]:
    if (self._cache_tokens is not None):
        return self._cache_tokens
    result = []
    for (module, k, v, dirtoks) in self.named_objs:
        if (issubclass(v, Token) and (dirtoks[0] in ['%token'])):
            name = k
            prec = None
            i = 1
            while (i < len(dirtoks)):
                tok = dirtoks[i]
                m = NontermSpec.precedence_tok_re.match(tok)
                if m:
                    if (i < (len(dirtoks) - 1)):
                        raise SpecError(('Precedence must come last in token specification: %s' % v.__doc__))
                    prec = PrecedenceRef(m.group(1))
                else:
                    m = NontermSpec.token_re.match(tok)
                    if m:
                        name = m.group(1)
                    else:
                        raise SpecError(('Invalid token specification: %s' % v.__doc__))
                i += 1
            if (prec is None):
                prec = PrecedenceRef('none')
            token = TokenSpec(v, name, prec)
            result.append(token)
    self._cache_tokens = result
    return result
def get_tokens(self) -> list[TokenSpec]:
    if (self._cache_tokens is not None):
        return self._cache_tokens
    result = []
    for (module, k, v, dirtoks) in self.named_objs:
        if (issubclass(v, Token) and (dirtoks[0] in ['%token'])):
            name = k
            prec = None
            i = 1
            while (i < len(dirtoks)):
                tok = dirtoks[i]
                m = NontermSpec.precedence_tok_re.match(tok)
                if m:
                    if (i < (len(dirtoks) - 1)):
                        raise SpecError(('Precedence must come last in token specification: %s' % v.__doc__))
                    prec = PrecedenceRef(m.group(1))
                else:
                    m = NontermSpec.token_re.match(tok)
                    if m:
                        name = m.group(1)
                    else:
                        raise SpecError(('Invalid token specification: %s' % v.__doc__))
                i += 1
            if (prec is None):
                prec = PrecedenceRef('none')
            token = TokenSpec(v, name, prec)
            result.append(token)
    self._cache_tokens = result
    return result