-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
SyntaxSyntactic and semantic improvements and sugarsSyntactic and semantic improvements and sugars
Description
Summary
Introduce triple-quoted strings '''...''' (and """...""") for multiline text with automatic indentation trimming (trim margin).
Dialect setting
enum MultilineString
{
Deny, // '''...''' not recognized
Allow, // '''...''' with trim margin + $-prefix escape levels
}Default: Deny (current behavior). Allow enables the full feature set including $'''...''' escape levels (#99).
Syntax
sql = '''
SELECT *
FROM users
WHERE age > 18
'''
# → "SELECT *\nFROM users\nWHERE age > 18"
Trim margin algorithm (Swift/Java/C# style)
- First newline after opening
'''is stripped - Last newline before closing
'''is stripped - Find the minimum common whitespace prefix across all non-empty content lines and the closing
'''line - Strip that prefix from every line
- Tabs and spaces are compared character-by-character (mixed = error or no trim)
Rules
- Opening
'''must be followed by a newline (nothing else on that line) - Closing
'''determines the baseline indentation - A content line with less indentation than closing
'''→ compile error - Both
'''and"""are supported (equivalent) - Interpolation uses
{expr}— same as single-quoted strings - Escape sequences (
\n,\t,\{, etc.) work as usual - To include literal
'''inside: use\'''or switch to"""
Escape level prefix ($-prefix)
When MultilineString.Allow is set, $-prefix is also available (for both '...' and '''...'''):
| Syntax | Interpolation | { literal |
$ literal |
|---|---|---|---|
'''...''' |
{expr} |
\{ |
literal |
$'''...''' |
${expr} |
literal | \$ |
$$'''...''' |
$${expr} |
literal | literal |
# JSON — braces literal, interpolation via ${expr}
json = $'''
{"name": "${name}", "age": ${age}}
'''
# Template with $ signs — interpolation via $${expr}
report = $$'''
Price: $100
Customer: $${customer}
'''
Edge cases
- Empty triple-quote:
'''\n'''→"" - Single line:
'''hello'''→ error? Or treat as regular string? (to decide) - Tabs vs spaces mixed indentation → compile error
Related
- Depends on: Dialect setting: disallow newlines in single-quoted strings #97 (dialect setting for single-line strings)
- Subsumes: Escape level prefix for string interpolation: $'...' $$'...' #99 (escape levels — included in this feature when
Allow)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
SyntaxSyntactic and semantic improvements and sugarsSyntactic and semantic improvements and sugars