public static int collect(
        final Signal signal, final List<Token> tokens, final int index, final List<Token> collected)
    {
        int i = index;
        while (i < tokens.size())
        {
            final Token token = tokens.get(i);
            if (signal != token.signal())
            {
                break;
            }

            final int tokenCount = token.componentTokenCount();
            for (final int limit = i + tokenCount; i < limit; i++)
            {
                collected.add(tokens.get(i));
            }
        }

        return i;
    }
Collect a run of tokens matching a signal.

@param signal    to match against.
@param tokens    for the message.
@param index     index at which to begin.
@param collected to collect the tokens into.
@return resulting index.
sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/GenerationUtil.java