- Multi-threaded async parsing
- Fault-tolerance: Error from one thread does not affect the whole process
- Modularity: Parser packed as independent library
- Extensibility: Library users can implement customized callbacks to handle results
Run with specs/ & data/ containing input files under current directory:
swift run homework
How to specify input/output directory (from --help)
USAGE: homework [--specs <specs>] [--data <data>] [--output <output>]
OPTIONS:
-s, --specs <specs> The path of specs CSV files to parse.
-d, --data <data> The path of data files to parse.
-o, --output <output> The output directory.
-h, --help Show help information.
Start server:
python3 Sources/Streaming/stream_server.py --source data/testformat.txt
Start client:
swift run streaming specs/testformat1.csv http://127.0.0.1:5000/ output/stream1.ndjson
swift test
.
├── Sources/
│ ├── Homework/
│ │ └── Main.swift // Basic Function Implementation.
│ ├── MyParser/
│ │ ├── SpecsParser.swift // Function to parse specs.
│ │ ├── DataParser.swift // Struct to parse data strings in specified format,
│ │ | // with default callback to output string.
│ │ ├── Types.swift // Definition of spec and data type, with conversion
│ │ | // methods from certain input.
│ │ └── Error.swift // Error enumeration, all being catched in main func
│ └── Streaming/
│ ├── stream_server.py // Flask server to stream data strings.
│ └── StreamClient.swift // Stream reader parsing data in real-time.
├── Tests/
│ └── MyParserTests/
│ ├── SpecsParserTests.swift // Containing 4 unit tests for SpecsParser.
│ └── DataParserTests.swift // Containing 8 unit tests for DataParser.
└── Package.swift // Swift Package Manager configuration file.
Swift: SwiftCSV, ArgumentParser, Swift Logging, AsyncHTTPClient
Python: Flask
Explore structured concurrency in Swift: https://developer.apple.com/videos/play/wwdc2021/10134/
Swift Style Guide from Google: https://google.github.io/swift/
Linting tool: https://github.com/realm/SwiftLint