Skip to content

Support implicit concatenation of adjacent string literals - #28

Open
florianvoss-commit wants to merge 1 commit into
ochafik:mainfrom
sima-neat:fix/adjacent-string-literals
Open

florianvoss-commit wants to merge 1 commit into
ochafik:mainfrom
sima-neat:fix/adjacent-string-literals

Conversation

@florianvoss-commit

@florianvoss-commit florianvoss-commit commented Jul 27, 2026 •

Copy link
Copy Markdown

Summary

Add support for implicit concatenation of adjacent string literals in Minja expressions.

This allows valid Jinja expressions such as:

{{ raise_exception(
    "first part "
    "second part "
    "third part"
) }}

The implementation extends Minja's existing constant parser to consume adjacent quoted literals separated by whitespace and combine them into a single string value.

Fixes #27

Motivation

Google's canonical Gemma 4 chat template uses adjacent string literals inside a raise_exception() call:

https://huggingface.co/google/gemma-4-E2B-it/blob/main/chat_template.jinja#L257-L260

The template was published by the Google Gemma Engineering Team and is used by the public google/gemma-4-E2B-it model.

Minja currently parses the first literal and then expects a comma or closing parenthesis. It therefore fails on the second literal with:

Expected closing parenthesis in call args

This prevents runtimes using Minja from loading the canonical Gemma 4 template.

Implementation

  • Continue consuming string literals after parsing the first literal when they are separated only by whitespace.
  • Combine their contents into the existing Minja Value.
  • Keep the behavior within the native Minja parser; no template preprocessing or model-specific workaround is introduced.
  • Support mixed single and double quotes as well as multiline adjacency.

Tests

Added native C++ syntax coverage for:

  • General adjacent literal concatenation with mixed quote styles.
  • The exact multiline raise_exception() structure used by Gemma 4.
  • Verification that the exception receives the fully concatenated message, proving parsing completed successfully.

Validation performed:

  • Native test-syntax suite passes.
  • Sources compile cleanly with -Wall -Wextra -pedantic -Werror.
  • Sources also compile successfully with a AArch64 cross-compiler.

Scope

This adds syntax that is actively used by a publicly available LLM chat
template, consistent with Minja's restricted contribution scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser rejects adjacent string literals in function-call arguments

1 participant