code wiki / (root) / csv.nx

csv.nx

buildroot/runtime/csv.nx

6598 B194 linesdepth 3pulls 3 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

syscalls.nx csv.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

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

main csv_parse csv_decode_quoted

structs

38struct CsvCell {

consts

31const CSV_ERR_OVERFLOW: i64 = -1
32const CSV_ERR_UNTERM: i64 = -2

functions

48func csv_parse(buf: *u8, n: i64,
called by 1: main
140func csv_decode_quoted(buf: *u8, start: i64, end: i64,
called by 1: main
165func main() -> i64 {