Strings with interpolations are preceded by a $ token. Regex literals follow the same pattern for interpolations, such as $re/\.x;/.
There are 5 forms of interpolation, all preceded by the \ escape character.
Newlines are allowed within interpolated sections of strings that allow newlines, but never with the dot-semicolon form of interpolation.
opening/closing marks and examples |
---|
. ; opening dot included as part of interpolated value $"\.var;" $"\.x+.y;" |
{ } $"\{.var}" $"\{.x+.y}" |
( ) $"\(.var)" $"\(.x+.y)" |
[ ] $"\[.var]" $"\[.x+.y]" |
< > $"\<.var>" $"\<.x+.y>" |
Interpolations may nest pairs of (), {}, or [] marks (not <>).
Nested marks in an interpolation would look something like $"\[.x[1]]".
Also, a semicolon or colon may be used inside of nesting marks without terminating the interpolation value.
Interpolation modifiers are preceded with a colon within an interpolation, such as $"\(.x +.y:r2)" to round the printed result of .x +.y to 2 places.
Langur allows a single ASCII space on each side of a modifier to improve readability.
Modifiers may include balanced sections enclosed with () [] or {}. These sections may include escape codes if the string interprets escape codes. Also, the code points the string allows are allowed in these sections.
You can use multiple modifiers on a single interpolation (chained), and they will be executed in order.
If you want to convert from a number, you must use that modifier first, because after the first one, the rest of the modifiers will be dealing with a string. The exceptions are rounding and truncate modifiers, which return a number.
# example of modifier chaining $"\.x:r2:L-20(...):20;" # round to 2 decimal places # limit from left, using "..." as indicator, to 20 code points max # right align to 20 code points # if .x is 1180591620717411303424, you get "...20717411303424.00" # if .x is 1234.234, you get " 1234.23"
modifier |
---|
code point alignmentminimumminimum(cp)
$"\.x:7;" $"\.x:7(.);" $"\.x:7(2E);" $"\.x:-7;" $"\.x:-7(.):20(#);" |
code point limitLmaximumLmaximum(...)
Examples: $"\.x:L7;" $"\.x:L7(...);" $"\.x:L7(…);" $"\.x:L-7;" $"\.x:L20(*);" |
hexadecimal+X+Xminimum +x +xminimum
Examples: $"\.x:x2;" $"\.x:X;" $"\.x:x2:7(.);" |
custom base+basex+baseX +basexminimum +baseXminimum
Examples: $"\.x:2x;" $"\.x:+11x10;" |
fixed point+10xinteger.fractional
Examples: $"\.x:10x0.3;" $"\.x:+10x7.3;" |
scientific notation+scaleE+exponentscale+scalee+exponentscale
Examples: $"\.x:e;" $"\.x:7e;" $"\.x:+E7;" $"\.x:E+;" $"\.x:+7e+7;" |
roundrrscale
Examples: $"\.x:r;" $"\.x:r2;" $"\.x:r-3;" |
truncatettscale
Examples: $"\.x:t;" $"\.x:t2;" $"\.x:t-3;" |
custom formatting function.fnExamples: val .F = ucase .s $"\.x:.F;" |
code pointscp
Examples: $"\.x:cp;" |
date-timedt(format)dt.var
Examples: $"\.x:dt(2006);" $"\.x:dt(+07:00);" $"\.x:dt(Jan);" $"\.x:dt.format;" |
escape meta-charactersescExamples: $"\.x:esc;" $re/\.x:esc;/ |
type stringTExamples: $"\.x:T;" |