Skip to content

Add raw string syntax {|...|} and {id|...|id}#4959

Open
toots wants to merge 1 commit intomainfrom
strings-no-interpolation
Open

Add raw string syntax {|...|} and {id|...|id}#4959
toots wants to merge 1 commit intomainfrom
strings-no-interpolation

Conversation

@toots
Copy link
Member

@toots toots commented Mar 5, 2026

Summary

Adds a raw string literal syntax that suppresses both escape processing and #{} interpolation. Content is taken verbatim from source.

The syntax is inspired by OCaml's quoted string literals ({id|...|id}),

This PR implements the changes required to support the feature requested in #4957.

Syntax

  • {|...|} — basic form, terminates at the first |}
  • {id|...|id} — delimited form, where id is any sequence of lowercase letters and underscores; terminates only at |id} with the matching id

This allows embedding |} inside a raw string by choosing a non-empty id:

s = {|hello #{world}|}          # => "hello #{world}"
s = {foo|contains |} here|foo}  # => "contains |} here"
s = {||}                        # => ""

Implementation

The lexer matches {[a-z_]*| as the opening delimiter, extracts the id, and delegates to read_raw_string. That function scans until it finds |[a-z_]*} with a matching id, treating any non-matching |..} sequences as literal content.

A new RAW_STRING token carries the raw content string. The pipeline adds:

  • `Raw_string of (string * string) variant in parsed_ast
  • passthrough in term_preprocessor (no expand_string processing)
  • reduction `Raw_string (_, s) -> `String s in term_reducer
  • JSON serialization in parsed_json with both id separator and string content.

@toots toots requested a review from smimram March 5, 2026 05:34
@toots toots force-pushed the strings-no-interpolation branch from 6409eb9 to c81a357 Compare March 5, 2026 05:36
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Scheduled for backport to v2.4.x-latest when this PR is merged.

@toots toots force-pushed the strings-no-interpolation branch 3 times, most recently from f862b74 to 3b23a0e Compare March 6, 2026 14:50
Raw strings are taken verbatim: no escape processing, no #{} interpolation.
@toots toots force-pushed the strings-no-interpolation branch from 3b23a0e to 9a7d939 Compare March 6, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant