miller/pkg/mlrval
John Kerl 12c96298b9
Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122)
* Add MT_BYTES mlrval type: foundation and disposition tables

First step toward a first-class bytes type in the DSL (#1231).
Adds MT_BYTES (payload []byte, rendered as lowercase hex in all output
formats, JSON-encoded as a hex string), extends every disposition
matrix/vector with the new row/column -- real cells for comparison,
sorting, and dot-concat of bytes with bytes; type-error stubs
elsewhere -- and adds sweep tests asserting no table has nil cells,
since Go zero-fills short array literals when MT_DIM grows.

Bytes values are not yet constructible from the DSL; b"..." literals
and constructor/codec functions follow in subsequent commits.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add b"..." bytes-literal syntax to the DSL

Adds a bytes_literal token to the grammar (regenerating the PGPG lexer
and parser) and a BytesLiteralNode in the CST which evaluates to an
MT_BYTES mlrval. Escape handling reuses UnbackslashStringLiteral,
which is already byte-oriented: b"\xff" is the single byte 0xff.
Unlike string literals, bytes literals never participate in
regex-capture replacement. A bare identifier b is unaffected.

Part of #1231.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add bytes DSL functions: conversions, codecs, and bytes-aware built-ins

- bytes(x) converts strings to bytes; string(b) reinterprets raw bytes
  as UTF-8 text (the reverse)
- base64_decode now always returns bytes (superseding the interim
  string-or-hex behavior); base64_encode accepts string or bytes
- New hex_encode/hex_decode functions
- is_bytes and asserting_bytes predicates
- md5/sha1/sha256/sha512 accept bytes, hashing the raw payload
- strlen of bytes is the byte count; substr/substr0/substr1 on bytes
  slice by byte position and return bytes

The Cyrillic-LDAP scenario from #1231 now works without exec
workarounds: string(base64_decode($x)) recovers the text, and binary
payloads survive undamaged as bytes.

Closes #1231.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add bytes-type docs and regression cases

Documents the bytes type on the data-types page, regenerates the
function-reference/man-page material, and adds regression coverage:
literal escape forms, operators (concat/compare/slice/sort and
type errors), conversions and codec round-trips, and CSV-to-JSON
output rendering of bytes fields.

Part of #1231.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Reposition MT_BYTES to sort adjacent to MT_STRING in the type enum

MT_BYTES was appended after MT_ABSENT for index stability; move it
right after MT_STRING instead, since that's where it conceptually
belongs and where it already sorts in the cmp disposition matrices.
Mechanically re-derive all ~40 disposition tables in pkg/bifs and
pkg/mlrval accordingly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix windows CI

* fix merge

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 11:58:44 -04:00
..
dispositions_test.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrmap.go Lazy per-record hashing: ~15-30% faster on common workloads (#2081) 2026-06-19 16:37:42 -04:00
mlrmap_accessors.go Lint round 5+6: staticcheck and errcheck to zero (#2130) 2026-07-03 11:42:08 -04:00
mlrmap_accessors_test.go Implement mlr uniq -x (#1457) 2023-12-23 16:20:11 -05:00
mlrmap_flatten_unflatten.go Lint round 5+6: staticcheck and errcheck to zero (#2130) 2026-07-03 11:42:08 -04:00
mlrmap_json.go Fix govet lint findings; fix masked unset-on-array error path (#2129) 2026-07-03 10:31:08 -04:00
mlrmap_new_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrmap_print.go Fix govet lint findings; fix masked unset-on-array error path (#2129) 2026-07-03 10:31:08 -04:00
mlrval_accessors.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_benchmark_test.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
mlrval_bytes_test.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_cmp.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_cmp_test.go Strip dead code from pkg/ (#2121) 2026-07-01 19:32:13 -04:00
mlrval_collections.go Fix govet lint findings; fix masked unset-on-array error path (#2129) 2026-07-03 10:31:08 -04:00
mlrval_collections_test.go Fix govet lint findings; fix masked unset-on-array error path (#2129) 2026-07-03 10:31:08 -04:00
mlrval_constants.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_copy.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_format.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_format_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_get.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_get_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_infer.go Strip dead code from pkg/ (#2121) 2026-07-01 19:32:13 -04:00
mlrval_infer_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_is.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_is_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_json.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_new.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_new_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_output.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_output_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_sort.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_sort_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_type.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_type_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_yaml.go Add a first-class bytes type to the DSL, with b"..." literals and base64/hex codecs (#2122) 2026-07-03 11:58:44 -04:00
mlrval_yaml_test.go fix: preserve key order in YAML output (#2034) 2026-04-12 09:43:09 -04:00
record_arena.go Batch-allocate per-record objects; reuse CSV writer field buffer (#2083) 2026-06-19 17:03:04 -04:00