private Operation parse() {
            boolean parsingLiteral = false;
            int literalStartCharacter = 0;

            while (!parser.eof()) {
                char c = parser.peek();
                parser.skip();

                if (c != expressionStart) {
                    parsingLiteral = true;
                } else if (parser.peek() == expressionStart) {
                    // Don't write escaped expression starts.
                    pushOperation(Operation.stringSlice(template, literalStartCharacter, parser.position()));
                    parser.expect(expressionStart);
                    parsingLiteral = true;
                    literalStartCharacter = parser.position();
                } else {
                    int pendingTextStart = parsingLiteral ? literalStartCharacter : -1;
                    parsingLiteral = false;
                    parseArgument(pendingTextStart);
                    literalStartCharacter = parser.position();
                }
            }

            if (parsingLiteral) {
                pushOperation(Operation.stringSlice(template, literalStartCharacter, parser.position()));
            }

            if (relativeIndex == -1) {
                ensureAllPositionalArgumentsWereUsed();
            } else if (relativeIndex < arguments.length) {
                int unusedCount = arguments.length - relativeIndex;
                throw error(String.format("Found %d unused relative format arguments", unusedCount));
            }

            if (blocks.size() == 1) {
                return blocks.getFirst();
            }

            throw new IllegalArgumentException(
                    "Unclosed parse conditional blocks: ["
                            + blocks.stream()
                                    // Don't include the root block.
                                    .filter(b -> !b.variable().isEmpty())
                                    .map(BlockOperation::variable)
                                    .collect(Collectors.joining(", "))
                            + "]");
        }
A BlockOperation that repeats a template for each value referenced by the block. Each iteration pushes
a state to the writer that includes key, value, key.first, and key.last context properties. The name
of the context property can be customized in the template.
smithy-utils/src/main/java/software/amazon/smithy/utils/CodeFormatter.java