3d1c458e0c10c73f9f03cbbf06ec2ec0302b2a68
spp
Description
SPP (Single Pass Parser) is a minimal, zero-allocation parsing utility for C that operates directly on a character stream. It provides a small set of composable primitives for building fast, simple parsers without backtracking.
The library is designed around the idea of consuming input in a single forward pass, making it ideal for tokenization, lightweight parsing, and embedded systems.
Table of Contents
Features
- Single-pass, forward-only parsing
- Zero allocations
- Tiny API surface
- Composable primitives
- Works directly on const char* streams
Todos
- Add new feature X
- Improve documentation
- Write tests
Usage
// Returns true if the current character is in the provided character set.
bool spp_is(struct Stream s, const char *list);
// Returns true if the stream has reached the end '\0'
bool spp_eof(struct Stream s);
// Consumes and returns the current stream character if in a list.
char spp_take(struct Stream s, const char *list);
// Consumes characters while they belong to the set. I.E. skip white-space.
uintptr_t spp_skip(struct Stream s, const char *list);
// Consumes characters until a character from the set is encountered.
uintptr_t spp_until(struct Stream s, const char *list);
// Returns current cursor position of the stream.
const char *spp_cursor(struct Stream s);
// Pass a custom callback to parse a stream.
typedef bool (*parse)(struct Stream s, const char **start, ptrdiff_t *len);
uintptr_t spp_parse(struct Stream s, parse fn, const char *buf[], ptrdiff_t cnt[], uintptr_t cap );
Acknowledgments
Tom Preston-Werner README Driven Development
Make a README
Choose a LICENSE
License
This project is licensed under the MIT License - see the [LICENSE] file for details.
Languages
C
62.7%
Makefile
37.3%