sexp.h 899 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef __sti__sexp_h__
  2. #define __sti__sexp_h__
  3. // Public Domain.
  4. #include <stdint.h>
  5. #include "vec.h"
  6. // A simple S-Expression parser
  7. // Supports (, [, {, and < as brace characters
  8. typedef struct sexp {
  9. char type; // 0 = list, 1 = literal
  10. char brace;
  11. char* str;
  12. VEC(struct sexp*) args;
  13. } sexp;
  14. sexp* sexp_parse(char* source);
  15. sexp* sexp_parse_file(char* path);
  16. void sexp_free(sexp* x);
  17. void sexp_print(int fd, sexp* x);
  18. // if called on a scalar value, returns the requested conversion and ignores argn
  19. // OOB and NULL input tolerant; returns 0/NULL
  20. sexp* sexp_arg(sexp* x, size_t argn);
  21. int64_t sexp_int(sexp* x, size_t argn);
  22. uint64_t sexp_uint(sexp* x, size_t argn);
  23. float sexp_float(sexp* x, size_t argn);
  24. double sexp_double(sexp* x, size_t argn);
  25. // returns internally managed string, user must dup
  26. char* sexp_str(sexp* x, size_t argn);
  27. #endif // __sti__sexp_h__