spec.bend checks
raw source on the hub · import bend-float64@0.1.6.0/spec.bend as Spec
bend-float64's format mini-language: format(x, spec) is Python's format(x, spec) for a float, every field of the spec ([[fill]align][sign][z][#][0][width][grouping][.precision][type]) and every type but 'n' (which depends on the locale). A spec Python refuses gives Fail{} with Python's message. Pure.
6 imports
import Base import ./wide.bend as W import ./big.bend as B import ./float64.bend as F import ./text.bend as T import ./format.bend as FM
Types
type Spec source · line 15 · raw
Data
fill and align (0: none given), sign ('-', '+' or ' '), z, '#', width, grouping (0, ',' or '_'), precision (has: given or not), type (0: none)
Spec@fill:U32 -> @fill_set:Bool -> @align:U32 -> @sign:U32 -> @z:Bool -> @alt:Bool -> @width:U32 -> @group:U32 -> @has_prec:Bool -> @prec:U32 -> @typ:U32 -> Spec
type PR source · line 18 · raw
Data
POk@s:Spec -> PR
PErr@why:String -> PR
type Num source · line 46 · raw
Data
a run of digits: its value (stuck past 2^31: too many digits), how many, and what follows
Num@v:U32 -> @n:U32 -> @rest:List<&2, U32> -> Num
type GS source · line 250 · raw
Data
%g (add0: none-type with a precision, which keeps a ".0" and switches to an exponent one place sooner; alt: '#', which keeps trailing zeros and the point)
GFixGS
GLowGS
GExpGS
type TK source · line 287 · raw
Data
the text of |x| for a type (x finite)
TFTK
TETK
TGTK
TPctTK
TReprTK
TNoneTK
type AL source · line 380 · raw
Data
ALeftAL
ARightAL
ACenterAL
AEqAL
type GK source · line 411 · raw
Data
GNoneGK
GPlainGK
GZerosGK
Definitions
def is_align source · line 22 · raw
@+c:U32 -> Bool
def is_dig source · line 25 · raw
@+c:U32 -> Bool
def head source · line 28 · raw
@xs:List<&2, U32> -> U32
def tail source · line 35 · raw
@xs:List<&2, U32> -> List<&2, U32>
def second source · line 42 · raw
@xs:List<&2, U32> -> U32
def num_go source · line 49 · raw
@xs:List<&2, U32> -> @+v:U32 -> @+n:U32 -> Num
def num source · line 56 · raw
@xs:List<&2, U32> -> Num
def too_many source · line 59 · raw
PR
def chars source · line 62 · raw
@xs:List<&2, U32> -> String
def invalid source · line 69 · raw
@+spec:List<&2, U32> -> PR
def hex_digit source · line 72 · raw
@+d:U32 -> U32
def app source · line 75 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
def hex_go source · line 79 · raw
@n:Nat -> @+x:U32 -> @+started:Bool -> List<&2, U32>
x's hex digits from bit 4 (n - 1) down, leading zeros dropped
def hex_lower source · line 88 · raw
@+x:U32 -> String
def code_text source · line 93 · raw
@+c:U32 -> String
a printable ASCII code as itself, any other as \x and its hex digits a printable ASCII code as itself, any other as a backslash, x and its hex digits (as CPython writes it)
def unknown source · line 96 · raw
@+c:U32 -> PR
def float_type source · line 100 · raw
@+c:U32 -> Bool
'e' 'E' 'f' 'F' 'g' 'G' '%' (and 'n', refused here)
def group_ok source · line 106 · raw
@+g:U32 -> @+c:U32 -> Bool
the types CPython lets a grouping through with (the float's own type check comes after): d and the float types, and with '_' also b, o, x, X
def len_l source · line 110 · raw
@xs:List<&2, U32> -> U32
def group_of source · line 117 · raw
@s:Spec -> U32
def with_type source · line 122 · raw
@s:Spec -> @+t:U32 -> Spec
def p_type source · line 127 · raw
@+rest:List<&2, U32> -> @+spec:List<&2, U32> -> @+s:Spec -> PR
def with_prec source · line 134 · raw
@s:Spec -> @+p:U32 -> Spec
def p_prec_num source · line 139 · raw
@n:Num -> @+spec:List<&2, U32> -> @+s:Spec -> PR
def p_prec source · line 145 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @+s:Spec -> PR
def with_group source · line 148 · raw
@s:Spec -> @+g:U32 -> Spec
def is_group source · line 153 · raw
@+c:U32 -> Bool
def p_group source · line 156 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @+s:Spec -> PR
def with_width source · line 161 · raw
@s:Spec -> @+w:U32 -> Spec
def p_width_num source · line 166 · raw
@n:Num -> @+spec:List<&2, U32> -> @+s:Spec -> PR
def p_zero source · line 172 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @s:Spec -> PR
'0': the fill, unless given, becomes '0'; the alignment, unless given, '='
def p_alt source · line 179 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @s:Spec -> PR
def p_z source · line 185 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @s:Spec -> PR
def p_sign source · line 191 · raw
@+xs:List<&2, U32> -> @+spec:List<&2, U32> -> @s:Spec -> PR
def empty_spec source · line 198 · raw
Spec
def p_fill source · line 202 · raw
@+xs:List<&2, U32> -> PR
fill and align: a fill character is any character followed by an alignment character
def upper source · line 210 · raw
@+c:U32 -> U32
def map_upper source · line 213 · raw
@xs:List<&2, U32> -> List<&2, U32>
def contains source · line 220 · raw
@xs:List<&2, U32> -> @+c:U32 -> Bool
def insert_point source · line 227 · raw
@xs:List<&2, U32> -> List<&2, U32>
def ensure_point source · line 235 · raw
@+xs:List<&2, U32> -> List<&2, U32>
a point inserted before the exponent (or at the end) when there is none: '#' for f, e and none
def dig_list source · line 238 · raw
@ds:List<&2, U32> -> List<&2, U32>
def exp_list source · line 245 · raw
@+x:U32 -> List<&2, U32>
def g_frac source · line 255 · raw
@+alt:Bool -> @+add0:Bool -> @+sci:Bool -> @+fr:List<&2, U32> -> List<&2, U32>
def g_shape source · line 260 · raw
@g:GS -> @+ds:List<&2, U32> -> @+x:U32 -> @+alt:Bool -> @+add0:Bool -> List<&2, U32>
def g_sig source · line 269 · raw
@s:0x71d2c95108c3e65654506f5521343c81/format.Sig -> @+p:U32 -> @+alt:Bool -> @+add0:Bool -> List<&2, U32>
def g_body_p source · line 275 · raw
@c:0x71d2c95108c3e65654506f5521343c81/float64.Cls -> @+p:U32 -> @+alt:Bool -> @+add0:Bool -> List<&2, U32>
def g_body source · line 283 · raw
@c:0x71d2c95108c3e65654506f5521343c81/float64.Cls -> @+p0:U32 -> @+alt:Bool -> @+add0:Bool -> List<&2, U32>
p significant digits (1 for 0)
def tk_of source · line 295 · raw
@+t:U32 -> @+has_prec:Bool -> TK
def body source · line 301 · raw
@k:TK -> @+ax:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> @+p:U32 -> @+alt:Bool -> List<&2, U32>
def zero_text source · line 322 · raw
@xs:List<&2, U32> -> Bool
no digit from 1 to 9 before the exponent: the number rounded to zero ('z' then drops its sign)
def lead_digits source · line 331 · raw
@xs:List<&2, U32> -> List<&2, U32>
def after_digits source · line 338 · raw
@xs:List<&2, U32> -> List<&2, U32>
def group_go source · line 345 · raw
@xs:List<&2, U32> -> @+sep:U32 -> @+i:U32 -> List<&2, U32>
def grouped source · line 352 · raw
@+ds:List<&2, U32> -> @+sep:U32 -> List<&2, U32>
def glen source · line 356 · raw
@+k:U32 -> U32
k digits grouped take k + (k - 1) / 3 characters
def zcount source · line 359 · raw
@n:Nat -> @+k:U32 -> @+minw:U32 -> U32
def fills source · line 366 · raw
@n:Nat -> @+c:U32 -> List<&2, U32>
def zero_grouped source · line 375 · raw
@+ds:List<&2, U32> -> @+sep:U32 -> @+minw:U32 -> List<&2, U32>
'0' fill with '=' alignment and grouping: zeros join the digits, grouped too, until the number fills minw (and it never starts with a separator)
def al_of source · line 386 · raw
@+a:U32 -> AL
def pad_al source · line 389 · raw
@k:AL -> @+fill:U32 -> @+pad:U32 -> @+sg:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>
def pad_out source · line 401 · raw
@+align:U32 -> @+fill:U32 -> @+width:U32 -> @+sg:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>
sign, then the body, padded to width with fill as align says ('>' when none)
def sign_list source · line 405 · raw
@+neg:Bool -> @+sign:U32 -> List<&2, U32>
def is_upper_type source · line 408 · raw
@+t:U32 -> Bool
def group_k source · line 416 · raw
@k:GK -> @+ip:List<&2, U32> -> @+rest:List<&2, U32> -> @+g:U32 -> @+minw:U32 -> List<&2, U32>
def group_num source · line 426 · raw
@+b:List<&2, U32> -> @+f:U32 -> @+a:U32 -> @+w:U32 -> @+g:U32 -> @+slen:U32 -> List<&2, U32>
the digits before the point grouped; under '0' fill with '=' alignment the padding zeros join them
def pct source · line 436 · raw
@+ty:U32 -> @+b:List<&2, U32> -> List<&2, U32>
'%' follows inf and nan too
def render_go source · line 439 · raw
@c:0x71d2c95108c3e65654506f5521343c81/float64.Cls -> @+x:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> @+f:U32 -> @+a:U32 -> @+sg:U32 -> @+z:Bool -> @+alt:Bool -> @+w:U32 -> @+g:U32 -> @+hp:Bool -> @+p:U32 -> @+ty:U32 -> @+up:Bool -> List<&2, U32>
def render_c source · line 451 · raw
@c:0x71d2c95108c3e65654506f5521343c81/float64.Cls -> @+x:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> @s:Spec -> List<&2, U32>
def render source · line 456 · raw
@+x:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> @s:Spec -> List<&2, U32>
def done source · line 459 · raw
@r:PR -> @+x:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> Result<&2, &2, String, String>
def format source · line 468 · raw
@+x:0x71d2c95108c3e65654506f5521343c81/float64.F64 -> @spec:String -> Result<&2, &2, String, String>
Python's format(x, spec) for a float: Done{text}, or Fail{Python's message} for a spec Python refuses (or one with type 'n', which depends on the locale and is not supported)