langur

string/regex literal interpolation

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

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.

modifier chaining

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.

modifier

code point alignment

minimum
minimum(cp)
  • positive will right-align, and negative left-align
  • The default code point to use is the ASCII space. There are 2 ways to specify a different code point.
    1. Use one code point within parentheses.
    2. Specify a code point using a hexadecimal number of 2 digits of more within parentheses.

Examples:
$"\.x:7;"
$"\.x:7(.);"
$"\.x:7(2E);"
$"\.x:-7;"
$"\.x:-7(.):20(#);"


code point limit

Lmaximum
Lmaximum(...)
  • if positive, limits the right side of the string, and negative the left side
  • overflow indicator, if any, is placed on the side that is shortened
  • by default, does not add an overflow indicator; may specify one by enclosing it in parentheses
  • The length of the overflow indicator will be considered when limiting a string. That is, for example, if the limit is 20 and the indicator is 3 code points, and the string is over 20 code points, it will be shortened to 17 code points (20 with the indicator).

Examples:
$"\.x:L7;"
$"\.x:L7(...);"
$"\.x:L7(…);"
$"\.x:L-7;"
$"\.x:L20(*);"


hexadecimal

+X
+Xminimum
+x
+xminimum
  • optional + indicates the interpolated value should always have a sign
  • case of letter x determines capitalization
  • integer indicates a minimum number of digits (will pad with spaces or zeroes)
  • start the minimum with a 0 digit to indicate to pad with zeroes

Examples:
$"\.x:x2;"
$"\.x:X;"
$"\.x:x2:7(.);"


custom base

+basex
+baseX
+basexminimum
+baseXminimum
  • optional + indicates the interpolated value should always have a sign
  • case of letter x determines capitalization
  • use any base from 2 to 36
  • second integer indicates a minimum number of digits (will pad with spaces or zeroes)
  • start the minimum with a 0 digit to indicate to pad with zeroes

Examples:
$"\.x:2x;"
$"\.x:+11x10;"


fixed point

+10xinteger.fractional
  • currently only works with base 10
  • optional + indicates the interpolated value should always have a sign
  • integer portion indicates a minimum number of digits (will pad with spaces or zeroes)
  • start the integer portion with a 0 digit to indicate to pad with zeroes
  • fractional portion indicates rounding

Examples:
$"\.x:10x0.3;"
$"\.x:+10x7.3;"


scientific notation

+scaleE+exponentscale
+scalee+exponentscale
  • optional + indicates the interpolated value should always have a sign
  • case of letter e determines capitalization
  • everything but an e or E optional

Examples:
$"\.x:e;"
$"\.x:7e;"
$"\.x:+E7;"
$"\.x:E+;"
$"\.x:+7e+7;"


round

r
rscale
  • by default, will pad with zeroes; negative number indicates not to add padding zeroes

Examples:
$"\.x:r;"
$"\.x:r2;"
$"\.x:r-3;"


truncate

t
tscale
  • by default, will pad with zeroes; negative number indicates not to add padding zeroes

Examples:
$"\.x:t;"
$"\.x:t2;"
$"\.x:t-3;"


custom formatting function

.fn

Examples:
val .F = ucase .s
$"\.x:.F;"



code points

cp
  • does the same conversions as the cp2s() function

Examples:
$"\.x:cp;"


date-time

dt(format)
  • format string same as may be passed to toString() function (see date & time)

Examples:
$"\.x:dt(2006);"
$"\.x:dt(+07:00);"
$"\.x:dt(Jan);"


escape meta-characters

esc

Examples:
$"\.x:esc;"
$re/\.x:esc;/


type string

T

Examples:
$"\.x:T;"