A scheme-like DSL.
| README.md | Update README.md | |
| scheme.c | comment skip, float parsing, list build leak, free recursion | |
| scheme.h | comment skip, float parsing, list build leak, free recursion | |
Scheme
Scheme is the minimal S-expression parser powering StaticLinux's port format and configuration files.
Syntax
Atoms
"hello" ; string
hello ; symbol
42 ; number
3.14 ; float
#t ; true
#f ; false
Lists
(a b c) ; list of symbols
("hello" "world") ; list of strings
(key "value") ; key-value pair
(nested (a b) (c d)) ; nested lists
Comments
; this is a comment
API
#include "scheme.h"
/* parse a single expression */
SExpr *scheme_parse(const char *src);
/* parse all expressions in a string */
SExpr **scheme_parse_all(const char *src, int *count);
Types
| Type | Description |
|---|---|
S_SYM |
symbol |
S_STR |
string |
S_NUM |
number |
S_BOOL |
boolean |
S_PAIR |
cons cell (list node) |
S_NIL |
empty list |
Traversing a list
for (SExpr *c = list; c && c->type == S_PAIR; c = c->cdr) {
SExpr *item = c->car;
// do something with item
}