langur

string/regex literal interpolation

Interpolations are enclosed by doubled curly braces {{}}. Regex literals follow the same pattern for interpolations, such as re/{{x}}/.

Newlines are allowed within interpolated sections of strings that allow newlines.

opening/closing marks and examples
{{ }}

"{{var}}"
"{{x+y}}"

interpolation modifiers

Interpolation modifiers are preceded with a colon within an interpolation, such as "{{x:r2}}" to round the printed result of x to 2 places.

Langur allows a single ASCII space on each side of a modifier to improve readability.

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.

# example of modifier chaining "{{x:r2:L-20(...):20}}" # r2 rounds to 2 decimal places # L-20(...) limits from left, using "..." as indicator, to 20 code points max # 20 right aligns to 20 code points # so that ... # if x is 1180591620717411303424, you get "...20717411303424.00" # if x is 1234.234, you get " 1234.23"

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(*)}}"


grapheme limit

Lgmaximum
Lgmaximum(...)
  • 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 graphemes, and the string is over 20 graphemes, it will be shortened to 17 graphemes (20 with the indicator).

Examples:
"{{x:Lg7}}"
"{{x:Lg7(...)}}"
"{{x:Lg7(…)}}"
"{{x:Lg-7}}"
"{{x:Lg20(*)}}"


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!
+10xinteger.fractional-
+10xinteger,fractional!
+10xinteger,fractional-
  • currently works with base 10 only
  • 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
  • An optional ! after the fractional portion indicates not to add trailing zeroes.
  • An optional minus after the fractional portion indicates to trim trailing zeroes.
  • Results may vary depending on the rounding mode.

Examples:
"{{x:10x1.3}}"
"{{x:+10x7.3}}"


scientific notation

+1.scale!E+exponentscale
+1.scale!e+exponentscale
+1.scale-E+exponentscale
+1.scale-e+exponentscale
+1,scale!E+exponentscale
+1,scale!e+exponentscale
+1,scale-E+exponentscale
+1,scale-e+exponentscale
  • An optional + indicates the interpolated value should always have a sign.
  • An optional ! after the scale indicates not to add trailing zeroes.
  • An optional minus after the scale indicates to trim trailing zeroes.
  • case of letter e determines capitalization
  • everything but an e or E optional

Examples:
"{{x:e}}"
"{{x:1.7e}}"
"{{x:+E7}}"
"{{x:E+}}"
"{{x:+1,7e+7}}"


round

r
rscale!
rscale-
  • An optional ! after the scale indicates not to add trailing zeroes.
  • An optional minus after the scale indicates to trim trailing zeroes.
  • A negative scale will round on the integer portion.
  • Results may vary depending on the rounding mode.

Examples:
"{{x:r}}"
"{{x:r2}}"
"{{x:r-3}}"
"{{x:r3-}}"


truncate

t
tscale!
tscale-
  • An optional ! after the scale indicates not to add trailing zeroes.
  • An optional minus after the scale indicates to trim trailing zeroes.
  • A negative scale will truncate on the integer portion.

Examples:
"{{x:t}}"
"{{x:t2}}"
"{{x:t-3}}"
"{{x:t3!}}"


custom formatting function

fn fn

Examples:
val F = fn s:tcase(s[1]) ~ lcase(less(s, of=1))
"{{x:fn F}}"



code points

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

Examples:
"{{x:cp}}"


date-time

dt(format)
dt var
  • format string same as may be passed to string() conversion (see date & time)
  • may use a variable as a format string with the dt var syntax

Examples:
"{{x:dt(2006)}}"
"{{x:dt(+07:00)}}"
"{{x:dt(Jan)}}"
val format = "Jan 2"; "{{x:dt format}}"


escape meta-characters

esc

Examples:
"{{x:esc}}"
re/{{x:esc}}/


type string

T

Examples:
"{{x:T}}"