code wiki / (root) / nx_csv_v1.nx

nx_csv_v1.nx

buildroot/runtime/nx_csv_v1.nx

6701 B201 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic csv
docsdependenciesstructsconstsfunctions

about

csv.nx -- RFC 4180 comma-separated values parser. Companion to tsv.nx. CSV is messier than TSV because fields may be quoted, quotes inside quotes are doubled, and the line separator is CRLF per spec (most real-world files use plain LF -- we accept both). RFC 4180 grammar (simplified): file = header (CRLF record)* CRLF? header/rec = field (, field)* field = non_escaped | escaped non_escaped = TEXTDATA* escaped = DQUOTE (TEXTDATA | , | CR | LF | DQUOTE DQUOTE)* DQUOTE DQUOTE = 0x22 We emit a FIELD CALLBACK at each cell boundary and a ROW CALLBACK at each newline. This avoids allocating a 2D table and lets caller stream megabyte+ files. Invariants: CSV1 Quoted fields handle embedded commas + newlines. CSV2 Doubled quotes inside quoted fields ("") decode to one literal DQUOTE -- caller handles via the callback (we emit the raw quoted range; decoder below does the unescape). CSV3 Trailing CR before LF is stripped. CSV4 Empty file -> 0 rows, 0 cells.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_csv_v1.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap csv_parse csv_decode_quoted

structs

45struct CsvCell

consts

36const CSV_MAGIC_1024: i64 = 1024
38const CSV_ERR_OVERFLOW: i64 = -1
39const CSV_ERR_UNTERM: i64 = -2

functions

55func csv_parse(buf: *u8, n: i64,
called by 1: main
147func csv_decode_quoted(buf: *u8, start: i64, end: i64,
called by 1: main
172func main() -> i64