- Rust 100%
|
|
||
|---|---|---|
| src | pair isnt copy cuz i never derive it | |
| tests | tests folder | |
| vendor | Add vendor/scheme.c | |
| .gitignore | stuff | |
| build.rs | stuffs | |
| Cargo.toml | rename cuz scheme-rs is already took | |
| LICENSE | wtfpl | |
| README.md | readme | |
scheme-rs
FFI bindings to a minimal C s-expression parser. No interpreter, no eval, no macros - just lexing and parsing into a tree you can walk. Built for config/DSL use cases (service definitions, port metadata), not for running Scheme.
Usage
usescheme::{parse,parse_all};letsrc=r#"(service (name "nginx") (deps "network") (backoff 1 2 4 8))"#;letexpr=parse(src).unwrap();println!("{:?}",expr);fortop_levelinparse_all(src){foritemintop_level.items(){// walk pairs
}}Types
pubenum Expr{Sym(String),Str(String),Num(i64),Float(f64),Bool(bool),Pair(Box<Expr>,Box<Expr>),Nil,}Cons-cell pairs, not vectors - .items() walks a proper list into a Vec<&Expr> for convenience. Improper lists ((a b . c)) will silently drop the tail; don't feed it those.
as_sym, as_str, as_num, as_float, as_bool give you Option<_> accessors instead of matching by hand every time.
Supported syntax
- Symbols:
foo,on-failure - Strings:
"daemon off;"(basic escape handling) - Integers:
1,-4 - Floats:
1.5 - Booleans:
#t,#f - Lists:
(a b c), nested freely - Comments:
; line comment
No quoting, no vectors, no chars, no bignums. If you need more than this, you want a real Scheme implementation, not this.
Build
Vendors and compiles a small C parser (vendor/scheme.c) via cc at build time. No system dependency on a Scheme runtime, no dynamic linking.
License
WTFPL.