aboutsummaryrefslogtreecommitdiff
path: root/elymas/lib/txt.ey
blob: 914f0d777c48ff41ca7e8a832ee638964a119538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<
  <
    # 0 -> string
    # 0 <- leading digits converted to int (0, if none)
    { "^(\\d*)" regex -- ==n
      [ n { 48 sub } each ] reverse 10 math .unbase
    } [ "" ] [ 0 ] '' /u deffd

    # 0 -> string
    # 0 <- leading hexadecimal digits converted to int (0, if none)
    [
      0 1 2 3 4 5 6 7 8 9
      7 { 0 } rep
      10 11 12 13 14 15
      26 { 0 } rep
      10 11 12 13 14 15
    ] =*:hexDigitsReverse

    { "^([0-9A-Fa-f]*)" regex -- ==n
      [ n { 48 sub hexDigitsReverse } each ] reverse 16 math .unbase
    } [ "" ] [ 0 ] '' /hu deffd
  > /consume defvd

  <
    # 0 -> positive integer (or zero)
    # 0 <- decimal representation as string
    {
      _ { [ -01 10 math .base reverse "0123456789" each ] str .fromArray } { -- "0" } ? *
    } [ 0 ] [ "" ] '' /u deffd

    # 0 -> positive integer (or zero)
    # 0 <- hexadecimal representation as string
    {
      _ { [ -01 16 math .base reverse "0123456789ABCDEF" each ] str .fromArray } { -- "0" } ? *
    } [ 0 ] [ "" ] '' /hu deffd
  > /produce defvd
> /txt defvd

# vim: syn=elymas