]> begriffs open source - sa-parse/blob - README.md
Switch to Meson build system
[sa-parse] / README.md
1 # CSV Parser
2
3 A Flex/Bison-based CSV parser that can handle various CSV formats including quoted fields, empty fields, and escaped characters.
4
5 ## Project Structure
6
7 ```
8 sa-parse/
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
26 ```
27
28 ## Features
29
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
35
36 ## Building
37
38 ### Meson Build (Recommended)
39 ```bash
40 meson setup builddir
41 meson compile -C builddir
42 ```
43
44 ### Manual Build
45 ```bash
46 cd src
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
50 ```
51
52 ## Usage
53
54 ```bash
55 # Parse from file
56 ./builddir/src/csv_parser < tests/test.csv
57
58 # Parse from stdin
59 echo "name,age,city
60 John,25,Boston" | ./builddir/src/csv_parser
61
62 # Test various formats
63 ./builddir/src/csv_parser < tests/complex.csv
64 ./builddir/src/csv_parser < tests/empty_fields.csv
65
66 # Run all tests
67 meson test -C builddir
68 ```
69
70 ## Output Format
71
72 The parser outputs structured information about the CSV content:
73
74 ```
75 Header: [field1], [field2], [field3]
76 Record 1: [value1], [value2], [value3]
77 Record 2: [value4], [value5], [value6]
78 ```
79
80 ## Testing
81
82 The project includes comprehensive tests that can be run with:
83
84 ```bash
85 meson test -C builddir
86 ```
87
88 See `tests/README.md` for detailed information about test cases and expected behavior.
89
90 ## Implementation Notes
91
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
97
98 ## Recent Improvements
99
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