File: format_func.jq

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (16 lines) | stat: -rw-r--r-- 573 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# note this is a "dynamic" include, output string will be used as source

# generates a _format_func function that can be used to implement format overloaded
# functions like torepr, _format_func("msgpack", "torepr") calls _msgpack_torepr

[ "def _format_func($format; $func):"
, "  ( [$format, $func] as $ff"
, "  | if false then error(\"unreachable\")"
, ( _registry.formats[] as $f
  | $f.functions[]?
  | "    elif $ff == \([$f.name, .] | tojson) then _\($f.name)_\(.)"
  )
  , "    else error(\"\\($format) has no \\($func)\")"
  , "    end"
  , "  );"
] | join("\n")