3 A Flex/Bison-based CSV parser that can handle various CSV formats including quoted fields, empty fields, and escaped characters.
9 ├── .gitignore # Ignore build artifacts and temporary files
10 ├── meson.build # Main Meson build configuration
11 ├── meson_options.txt # Meson build options
12 ├── README.md # This file
13 ├── src/ # Source code directory
14 │ ├── csv.l # Flex lexer specification
15 │ ├── csv.y # Bison parser specification
16 │ └── meson.build # Source build configuration
17 └── tests/ # Test files and documentation
18 ├── README.md # Test documentation
19 ├── meson.build # Test configuration
20 ├── test.csv # Basic test case
21 ├── complex.csv # Complex field content test
22 ├── quotes.csv # Quote handling test
23 ├── empty_fields.csv # Empty field handling test
24 ├── header_only.csv # Header-only file test
25 └── empty.csv # Empty file test
30 - **RFC 4180 CSV Parsing**: Handles standard CSV format
31 - **Quoted Field Support**: Properly processes quoted fields with commas and quotes
32 - **Empty Field Handling**: Correctly parses empty fields in any position
33 - **Memory Safe**: Conservative memory management with proper error handling
34 - **Robust Error Reporting**: Line number and context information for parse errors
38 ### Meson Build (Recommended)
41 meson compile -C builddir
47 yacc -d csv.y # Generate parser
48 flex csv.l # Generate lexer
49 gcc -o csv_parser y.tab.c lex.yy.c -ll
56 ./builddir/src/csv_parser < tests/test.csv
60 John,25,Boston" | ./builddir/src/csv_parser
62 # Test various formats
63 ./builddir/src/csv_parser < tests/complex.csv
64 ./builddir/src/csv_parser < tests/empty_fields.csv
67 meson test -C builddir
72 The parser outputs structured information about the CSV content:
75 Header: [field1], [field2], [field3]
76 Record 1: [value1], [value2], [value3]
77 Record 2: [value4], [value5], [value6]
82 The project includes comprehensive tests that can be run with:
85 meson test -C builddir
88 See `tests/README.md` for detailed information about test cases and expected behavior.
90 ## Implementation Notes
92 - Built with Flex 2.6+ and Bison 3.0+
93 - Uses conservative memory management approach
94 - Handles both CRLF and LF line endings
95 - Supports files with or without headers
96 - Gracefully handles malformed input with informative error messages
98 ## Recent Improvements
100 - Switched to Meson build system from shell scripts
101 - Refined CSV grammar for better parsing accuracy
102 - Fixed buffer overflow vulnerabilities in lexer
103 - Added proper memory allocation failure handling
104 - Enhanced error checking in semantic actions
105 - Improved memory leak prevention
106 - Added comprehensive test suite