]> begriffs open source - sa-parse/blob - README.md
Basics CSV parser and test cases
[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 ├── build.sh            # Build script for easy compilation
11 ├── meson.build         # Meson build configuration
12 ├── README.md           # This file
13 ├── src/                # Source code directory
14 │   ├── csv.l           # Flex lexer specification
15 │   └── csv.y           # Bison parser specification
16 └── tests/              # Test files and documentation
17     ├── README.md       # Test documentation
18     ├── test.csv        # Basic test case
19     ├── complex.csv     # Complex field content test
20     ├── quotes.csv      # Quote handling test
21     ├── empty_fields.csv # Empty field handling test
22     ├── header_only.csv # Header-only file test
23     └── empty.csv       # Empty file test
24 ```
25
26 ## Features
27
28 - **RFC 4180 CSV Parsing**: Handles standard CSV format
29 - **Quoted Field Support**: Properly processes quoted fields with commas and quotes
30 - **Empty Field Handling**: Correctly parses empty fields in any position
31 - **Memory Safe**: Conservative memory management with proper error handling
32 - **Robust Error Reporting**: Line number and context information for parse errors
33
34 ## Building
35
36 ### Quick Build (Recommended)
37 ```bash
38 ./build.sh
39 ```
40
41 ### Manual Build
42 ```bash
43 cd src
44 yacc -d csv.y      # Generate parser
45 flex csv.l         # Generate lexer  
46 gcc -o csv_parser y.tab.c lex.yy.c -ll
47 ```
48
49 ### Meson Build
50 ```bash
51 meson setup builddir
52 meson compile -C builddir
53 ```
54
55 ## Usage
56
57 ```bash
58 # Parse from file
59 ./src/csv_parser < tests/test.csv
60
61 # Parse from stdin
62 echo "name,age,city
63 John,25,Boston" | ./src/csv_parser
64
65 # Test various formats
66 ./src/csv_parser < tests/complex.csv
67 ./src/csv_parser < tests/empty_fields.csv
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 See `tests/README.md` for detailed information about test cases and expected behavior.
83
84 ## Implementation Notes
85
86 - Built with Flex 2.6+ and Bison 3.0+
87 - Uses conservative memory management approach
88 - Handles both CRLF and LF line endings
89 - Supports files with or without headers
90 - Gracefully handles malformed input with informative error messages
91
92 ## Recent Improvements
93
94 - Fixed buffer overflow vulnerabilities in lexer
95 - Added proper memory allocation failure handling
96 - Enhanced error checking in semantic actions
97 - Improved memory leak prevention
98 - Added comprehensive test suite