Skip to content

Add CSV syntax highlighting

Mike Boyer requested to merge csv-syntax-highlighting into main

tokenize() for lint_csv.py: _detect_delim() factored out of lint() so tokenize() reuses the exact same sniffed/overridden delimiter instead of guessing independently. Header-row fields get "type" kind regardless of quoting (a header names the column, same judgment call JSON's tokenize() made for object keys); quoted data-row fields are "string"; unquoted numeric-looking fields are "number"; anything else stays plain.

The one real subtlety: a quoted CSV field may legally contain a literal embedded newline (RFC 4180), so row number is tracked by counting newlines between field matches rather than with a naive per-line split -- a fresh reason to need the same "whole-file, not per-line" approach every other tokenizer here already follows.

test_tokenize.py covers header/data/quoted/numeric fields, the embedded-newline row-tracking case specifically (a numeric field right after a multi-line quoted field must not be misread as still being the header), and .tsv. All seven test files pass.

Branch: csv-syntax-highlighting.

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

Merge request reports